Fixing pointer array-indexing *((word*) main::SCREEN + (byte) main::idx)
Fixing pointer array-indexing *((const word*) arr16 + (number~) getValue::$0)
Identified constant variable (word*) main::SCREEN
Culled Empty Block (label) main::@2
Culled Empty Block (label) @1
Culled Empty Block (label) getValue::@1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@2

(void()) main()
main: scope:[main]  from @2
  (byte) main::idx#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@3
  (byte) main::idx#2 ← phi( main/(byte) main::idx#0 main::@3/(byte) main::idx#1 )
  (word) getValue::index#0 ← (byte) main::idx#2
  call getValue 
  (word) getValue::return#0 ← (word) getValue::return#2
  to:main::@3
main::@3: scope:[main]  from main::@1
  (byte) main::idx#3 ← phi( main::@1/(byte) main::idx#2 )
  (word) getValue::return#3 ← phi( main::@1/(word) getValue::return#0 )
  (word~) main::$0 ← (word) getValue::return#3
  (byte~) main::$2 ← (byte) main::idx#3 * (const byte) SIZEOF_WORD
  *((const word*) main::SCREEN + (byte~) main::$2) ← (word~) main::$0
  (byte) main::idx#1 ← (byte) main::idx#3 + rangenext(0,$80)
  (bool~) main::$1 ← (byte) main::idx#1 != rangelast(0,$80)
  if((bool~) main::$1) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return

(word()) getValue((word) getValue::index)
getValue: scope:[getValue]  from main::@1
  (word) getValue::index#1 ← phi( main::@1/(word) getValue::index#0 )
  (number~) getValue::$0 ← (word) getValue::index#1 & (number) $7f
  (number~) getValue::$4 ← (number~) getValue::$0 * (const byte) SIZEOF_WORD
  (number~) getValue::$1 ← *((const word*) arr16 + (number~) getValue::$4) & (number) $ff
  (number~) getValue::$2 ← (number~) getValue::$1 >> (number) 1
  (word~) getValue::$3 ← ((word)) (number~) getValue::$2
  (word) getValue::return#1 ← (word~) getValue::$3
  to:getValue::@return
getValue::@return: scope:[getValue]  from getValue
  (word) getValue::return#4 ← phi( getValue/(word) getValue::return#1 )
  (word) getValue::return#2 ← (word) getValue::return#4
  return 
  to:@return
@2: scope:[]  from @begin
  call main 
  to:@3
@3: scope:[]  from @2
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(const byte) SIZEOF_WORD = (byte) 2
(const word*) arr16[(number) $80]  = { fill( $80, 0) }
(word()) getValue((word) getValue::index)
(number~) getValue::$0
(number~) getValue::$1
(number~) getValue::$2
(word~) getValue::$3
(number~) getValue::$4
(label) getValue::@return
(word) getValue::index
(word) getValue::index#0
(word) getValue::index#1
(word) getValue::return
(word) getValue::return#0
(word) getValue::return#1
(word) getValue::return#2
(word) getValue::return#3
(word) getValue::return#4
(void()) main()
(word~) main::$0
(bool~) main::$1
(byte~) main::$2
(label) main::@1
(label) main::@3
(label) main::@return
(const word*) main::SCREEN = (word*)(number) $400
(byte) main::idx
(byte) main::idx#0
(byte) main::idx#1
(byte) main::idx#2
(byte) main::idx#3

Adding number conversion cast (unumber) $7f in (number~) getValue::$0 ← (word) getValue::index#1 & (number) $7f
Adding number conversion cast (unumber) getValue::$0 in (number~) getValue::$0 ← (word) getValue::index#1 & (unumber)(number) $7f
Adding number conversion cast (unumber) getValue::$4 in (number~) getValue::$4 ← (unumber~) getValue::$0 * (const byte) SIZEOF_WORD
Adding number conversion cast (unumber) $ff in (number~) getValue::$1 ← *((const word*) arr16 + (unumber~) getValue::$4) & (number) $ff
Adding number conversion cast (unumber) getValue::$1 in (number~) getValue::$1 ← *((const word*) arr16 + (unumber~) getValue::$4) & (unumber)(number) $ff
Adding number conversion cast (unumber) 1 in (number~) getValue::$2 ← (unumber~) getValue::$1 >> (number) 1
Adding number conversion cast (unumber) getValue::$2 in (number~) getValue::$2 ← (unumber~) getValue::$1 >> (unumber)(number) 1
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (word~) getValue::$3 ← (word)(unumber~) getValue::$2
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (word*) 1024
Simplifying constant integer cast $7f
Simplifying constant integer cast $ff
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $7f
Finalized unsigned number type (byte) $ff
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) getValue::$0 ← (word) getValue::index#1 & (byte) $7f
Inferred type updated to byte in (unumber~) getValue::$4 ← (byte~) getValue::$0 * (const byte) SIZEOF_WORD
Inferred type updated to byte in (unumber~) getValue::$1 ← *((const word*) arr16 + (byte~) getValue::$4) & (byte) $ff
Inferred type updated to byte in (unumber~) getValue::$2 ← (byte~) getValue::$1 >> (byte) 1
Alias (word) getValue::return#0 = (word) getValue::return#3 
Alias (byte) main::idx#2 = (byte) main::idx#3 
Alias (word) getValue::return#1 = (word~) getValue::$3 (word) getValue::return#4 (word) getValue::return#2 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (word) getValue::index#1 (word) getValue::index#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$1 [11] if((byte) main::idx#1!=rangelast(0,$80)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) main::idx#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [9] main::idx#1 ← ++ main::idx#2 to ++
Resolved ranged comparison value [11] if(main::idx#1!=rangelast(0,$80)) goto main::@1 to (number) $81
Adding number conversion cast (unumber) $81 in if((byte) main::idx#1!=(number) $81) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $81
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $81
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting multiplication to use shift [5] (byte~) main::$2 ← (byte) main::idx#2 * (const byte) SIZEOF_WORD
Rewriting multiplication to use shift [11] (byte~) getValue::$4 ← (byte~) getValue::$0 * (const byte) SIZEOF_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const byte) main::idx#0
Constant inlined main::idx#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant (const byte) SIZEOF_WORD
Successful SSA optimization PassNEliminateUnusedVars
Added new block during phi lifting main::@4(between main::@3 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to getValue:8 

Created 1 initial phi equivalence classes
Coalesced [16] main::idx#4 ← main::idx#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) main::@4
Renumbering block @2 to @1
Renumbering block main::@3 to main::@2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [5] (byte) main::idx#2 ← phi( main/(byte) 0 main::@2/(byte) main::idx#1 )
  [6] (word) getValue::index#0 ← (byte) main::idx#2
  [7] call getValue 
  [8] (word) getValue::return#0 ← (word) getValue::return#1
  to:main::@2
main::@2: scope:[main]  from main::@1
  [9] (word~) main::$0 ← (word) getValue::return#0
  [10] (byte~) main::$2 ← (byte) main::idx#2 << (byte) 1
  [11] *((const word*) main::SCREEN + (byte~) main::$2) ← (word~) main::$0
  [12] (byte) main::idx#1 ← ++ (byte) main::idx#2
  [13] if((byte) main::idx#1!=(byte) $81) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@2
  [14] return 
  to:@return

(word()) getValue((word) getValue::index)
getValue: scope:[getValue]  from main::@1
  [15] (byte~) getValue::$0 ← (word) getValue::index#0 & (byte) $7f
  [16] (byte~) getValue::$4 ← (byte~) getValue::$0 << (byte) 1
  [17] (byte~) getValue::$1 ← *((const word*) arr16 + (byte~) getValue::$4) & (byte) $ff
  [18] (byte~) getValue::$2 ← (byte~) getValue::$1 >> (byte) 1
  [19] (word) getValue::return#1 ← (word)(byte~) getValue::$2
  to:getValue::@return
getValue::@return: scope:[getValue]  from getValue
  [20] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(word()) getValue((word) getValue::index)
(byte~) getValue::$0 4.0
(byte~) getValue::$1 4.0
(byte~) getValue::$2 2.0
(byte~) getValue::$4 4.0
(word) getValue::index
(word) getValue::index#0 13.0
(word) getValue::return
(word) getValue::return#0 22.0
(word) getValue::return#1 4.333333333333333
(void()) main()
(word~) main::$0 11.0
(byte~) main::$2 22.0
(byte) main::idx
(byte) main::idx#1 16.5
(byte) main::idx#2 6.285714285714286

Initial phi equivalence classes
[ main::idx#2 main::idx#1 ]
Added variable getValue::index#0 to live range equivalence class [ getValue::index#0 ]
Added variable getValue::return#0 to live range equivalence class [ getValue::return#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Added variable getValue::$0 to live range equivalence class [ getValue::$0 ]
Added variable getValue::$4 to live range equivalence class [ getValue::$4 ]
Added variable getValue::$1 to live range equivalence class [ getValue::$1 ]
Added variable getValue::$2 to live range equivalence class [ getValue::$2 ]
Added variable getValue::return#1 to live range equivalence class [ getValue::return#1 ]
Complete equivalence classes
[ main::idx#2 main::idx#1 ]
[ getValue::index#0 ]
[ getValue::return#0 ]
[ main::$0 ]
[ main::$2 ]
[ getValue::$0 ]
[ getValue::$4 ]
[ getValue::$1 ]
[ getValue::$2 ]
[ getValue::return#1 ]
Allocated zp[1]:2 [ main::idx#2 main::idx#1 ]
Allocated zp[2]:3 [ getValue::index#0 ]
Allocated zp[2]:5 [ getValue::return#0 ]
Allocated zp[2]:7 [ main::$0 ]
Allocated zp[1]:9 [ main::$2 ]
Allocated zp[1]:10 [ getValue::$0 ]
Allocated zp[1]:11 [ getValue::$4 ]
Allocated zp[1]:12 [ getValue::$1 ]
Allocated zp[1]:13 [ getValue::$2 ]
Allocated zp[2]:14 [ getValue::return#1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test KickC performance for 16-bit array lookup function from article "Optimizing C array lookups for the 6502"
// http://8bitworkshop.com/blog/compilers/2019/03/17/cc65-optimization.html
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label SCREEN = $400
    .label __0 = 7
    .label __2 = 9
    .label idx = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::idx#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z idx
    jmp __b1
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (byte) main::idx#2 = (byte) main::idx#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (word) getValue::index#0 ← (byte) main::idx#2 -- vwuz1=vbuz2 
    lda.z idx
    sta.z getValue.index
    lda #0
    sta.z getValue.index+1
    // [7] call getValue 
    jsr getValue
    // [8] (word) getValue::return#0 ← (word) getValue::return#1 -- vwuz1=vwuz2 
    lda.z getValue.return_1
    sta.z getValue.return
    lda.z getValue.return_1+1
    sta.z getValue.return+1
    jmp __b2
    // main::@2
  __b2:
    // [9] (word~) main::$0 ← (word) getValue::return#0 -- vwuz1=vwuz2 
    lda.z getValue.return
    sta.z __0
    lda.z getValue.return+1
    sta.z __0+1
    // [10] (byte~) main::$2 ← (byte) main::idx#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z idx
    asl
    sta.z __2
    // [11] *((const word*) main::SCREEN + (byte~) main::$2) ← (word~) main::$0 -- pwuc1_derefidx_vbuz1=vwuz2 
    ldy.z __2
    lda.z __0
    sta SCREEN,y
    lda.z __0+1
    sta SCREEN+1,y
    // [12] (byte) main::idx#1 ← ++ (byte) main::idx#2 -- vbuz1=_inc_vbuz1 
    inc.z idx
    // [13] if((byte) main::idx#1!=(byte) $81) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$81
    cmp.z idx
    bne __b1_from___b2
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // getValue
// getValue(word zp(3) index)
getValue: {
    .label __0 = $a
    .label __1 = $c
    .label __2 = $d
    .label __4 = $b
    .label index = 3
    .label return = 5
    .label return_1 = $e
    // [15] (byte~) getValue::$0 ← (word) getValue::index#0 & (byte) $7f -- vbuz1=vwuz2_band_vbuc1 
    lda #$7f
    and.z index
    sta.z __0
    // [16] (byte~) getValue::$4 ← (byte~) getValue::$0 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z __0
    asl
    sta.z __4
    // [17] (byte~) getValue::$1 ← *((const word*) arr16 + (byte~) getValue::$4) & (byte) $ff -- vbuz1=pwuc1_derefidx_vbuz2_band_vbuc2 
    lda #$ff
    ldy.z __4
    and arr16,y
    sta.z __1
    // [18] (byte~) getValue::$2 ← (byte~) getValue::$1 >> (byte) 1 -- vbuz1=vbuz2_ror_1 
    lda.z __1
    lsr
    sta.z __2
    // [19] (word) getValue::return#1 ← (word)(byte~) getValue::$2 -- vwuz1=_word_vbuz2 
    lda.z __2
    sta.z return_1
    lda #0
    sta.z return_1+1
    jmp __breturn
    // getValue::@return
  __breturn:
    // [20] return 
    rts
}
  // File Data
  arr16: .fill 2*$80, 0

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (word) getValue::index#0 ← (byte) main::idx#2 [ main::idx#2 getValue::index#0 ] ( main:2 [ main::idx#2 getValue::index#0 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::idx#2 main::idx#1 ]
Statement [8] (word) getValue::return#0 ← (word) getValue::return#1 [ main::idx#2 getValue::return#0 ] ( main:2 [ main::idx#2 getValue::return#0 ] ) always clobbers reg byte a 
Statement [9] (word~) main::$0 ← (word) getValue::return#0 [ main::idx#2 main::$0 ] ( main:2 [ main::idx#2 main::$0 ] ) always clobbers reg byte a 
Statement [10] (byte~) main::$2 ← (byte) main::idx#2 << (byte) 1 [ main::idx#2 main::$0 main::$2 ] ( main:2 [ main::idx#2 main::$0 main::$2 ] ) always clobbers reg byte a 
Statement [11] *((const word*) main::SCREEN + (byte~) main::$2) ← (word~) main::$0 [ main::idx#2 ] ( main:2 [ main::idx#2 ] ) always clobbers reg byte a 
Statement [15] (byte~) getValue::$0 ← (word) getValue::index#0 & (byte) $7f [ getValue::$0 ] ( main:2::getValue:7 [ main::idx#2 getValue::$0 ] ) always clobbers reg byte a 
Statement [16] (byte~) getValue::$4 ← (byte~) getValue::$0 << (byte) 1 [ getValue::$4 ] ( main:2::getValue:7 [ main::idx#2 getValue::$4 ] ) always clobbers reg byte a 
Statement [17] (byte~) getValue::$1 ← *((const word*) arr16 + (byte~) getValue::$4) & (byte) $ff [ getValue::$1 ] ( main:2::getValue:7 [ main::idx#2 getValue::$1 ] ) always clobbers reg byte a 
Statement [18] (byte~) getValue::$2 ← (byte~) getValue::$1 >> (byte) 1 [ getValue::$2 ] ( main:2::getValue:7 [ main::idx#2 getValue::$2 ] ) always clobbers reg byte a 
Statement [19] (word) getValue::return#1 ← (word)(byte~) getValue::$2 [ getValue::return#1 ] ( main:2::getValue:7 [ main::idx#2 getValue::return#1 ] ) always clobbers reg byte a 
Statement [6] (word) getValue::index#0 ← (byte) main::idx#2 [ main::idx#2 getValue::index#0 ] ( main:2 [ main::idx#2 getValue::index#0 ] ) always clobbers reg byte a 
Statement [8] (word) getValue::return#0 ← (word) getValue::return#1 [ main::idx#2 getValue::return#0 ] ( main:2 [ main::idx#2 getValue::return#0 ] ) always clobbers reg byte a 
Statement [9] (word~) main::$0 ← (word) getValue::return#0 [ main::idx#2 main::$0 ] ( main:2 [ main::idx#2 main::$0 ] ) always clobbers reg byte a 
Statement [10] (byte~) main::$2 ← (byte) main::idx#2 << (byte) 1 [ main::idx#2 main::$0 main::$2 ] ( main:2 [ main::idx#2 main::$0 main::$2 ] ) always clobbers reg byte a 
Statement [11] *((const word*) main::SCREEN + (byte~) main::$2) ← (word~) main::$0 [ main::idx#2 ] ( main:2 [ main::idx#2 ] ) always clobbers reg byte a 
Statement [15] (byte~) getValue::$0 ← (word) getValue::index#0 & (byte) $7f [ getValue::$0 ] ( main:2::getValue:7 [ main::idx#2 getValue::$0 ] ) always clobbers reg byte a 
Statement [16] (byte~) getValue::$4 ← (byte~) getValue::$0 << (byte) 1 [ getValue::$4 ] ( main:2::getValue:7 [ main::idx#2 getValue::$4 ] ) always clobbers reg byte a 
Statement [17] (byte~) getValue::$1 ← *((const word*) arr16 + (byte~) getValue::$4) & (byte) $ff [ getValue::$1 ] ( main:2::getValue:7 [ main::idx#2 getValue::$1 ] ) always clobbers reg byte a 
Statement [18] (byte~) getValue::$2 ← (byte~) getValue::$1 >> (byte) 1 [ getValue::$2 ] ( main:2::getValue:7 [ main::idx#2 getValue::$2 ] ) always clobbers reg byte a 
Statement [19] (word) getValue::return#1 ← (word)(byte~) getValue::$2 [ getValue::return#1 ] ( main:2::getValue:7 [ main::idx#2 getValue::return#1 ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::idx#2 main::idx#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[2]:3 [ getValue::index#0 ] : zp[2]:3 , 
Potential registers zp[2]:5 [ getValue::return#0 ] : zp[2]:5 , 
Potential registers zp[2]:7 [ main::$0 ] : zp[2]:7 , 
Potential registers zp[1]:9 [ main::$2 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:10 [ getValue::$0 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:11 [ getValue::$4 ] : zp[1]:11 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:12 [ getValue::$1 ] : zp[1]:12 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:13 [ getValue::$2 ] : zp[1]:13 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:14 [ getValue::return#1 ] : zp[2]:14 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 22.79: zp[1]:2 [ main::idx#2 main::idx#1 ] 22: zp[1]:9 [ main::$2 ] 11: zp[2]:7 [ main::$0 ] 
Uplift Scope [getValue] 22: zp[2]:5 [ getValue::return#0 ] 13: zp[2]:3 [ getValue::index#0 ] 4.33: zp[2]:14 [ getValue::return#1 ] 4: zp[1]:10 [ getValue::$0 ] 4: zp[1]:11 [ getValue::$4 ] 4: zp[1]:12 [ getValue::$1 ] 2: zp[1]:13 [ getValue::$2 ] 
Uplift Scope [] 

Uplifting [main] best 899 combination reg byte x [ main::idx#2 main::idx#1 ] reg byte a [ main::$2 ] zp[2]:7 [ main::$0 ] 
Uplifting [getValue] best 877 combination zp[2]:5 [ getValue::return#0 ] zp[2]:3 [ getValue::index#0 ] zp[2]:14 [ getValue::return#1 ] reg byte a [ getValue::$0 ] reg byte a [ getValue::$4 ] reg byte a [ getValue::$1 ] reg byte a [ getValue::$2 ] 
Limited combination testing to 100 combinations of 256 possible.
Uplifting [] best 877 combination 
Coalescing zero page register [ zp[2]:5 [ getValue::return#0 ] ] with [ zp[2]:7 [ main::$0 ] ] - score: 1
Coalescing zero page register [ zp[2]:5 [ getValue::return#0 main::$0 ] ] with [ zp[2]:14 [ getValue::return#1 ] ] - score: 1
Allocated (was zp[2]:3) zp[2]:2 [ getValue::index#0 ]
Allocated (was zp[2]:5) zp[2]:4 [ getValue::return#0 main::$0 getValue::return#1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test KickC performance for 16-bit array lookup function from article "Optimizing C array lookups for the 6502"
// http://8bitworkshop.com/blog/compilers/2019/03/17/cc65-optimization.html
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label SCREEN = $400
    .label __0 = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::idx#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (byte) main::idx#2 = (byte) main::idx#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (word) getValue::index#0 ← (byte) main::idx#2 -- vwuz1=vbuxx 
    txa
    sta.z getValue.index
    lda #0
    sta.z getValue.index+1
    // [7] call getValue 
    jsr getValue
    // [8] (word) getValue::return#0 ← (word) getValue::return#1
    jmp __b2
    // main::@2
  __b2:
    // [9] (word~) main::$0 ← (word) getValue::return#0
    // [10] (byte~) main::$2 ← (byte) main::idx#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [11] *((const word*) main::SCREEN + (byte~) main::$2) ← (word~) main::$0 -- pwuc1_derefidx_vbuaa=vwuz1 
    tay
    lda.z __0
    sta SCREEN,y
    lda.z __0+1
    sta SCREEN+1,y
    // [12] (byte) main::idx#1 ← ++ (byte) main::idx#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if((byte) main::idx#1!=(byte) $81) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$81
    bne __b1_from___b2
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // getValue
// getValue(word zp(2) index)
getValue: {
    .label index = 2
    .label return = 4
    // [15] (byte~) getValue::$0 ← (word) getValue::index#0 & (byte) $7f -- vbuaa=vwuz1_band_vbuc1 
    lda #$7f
    and.z index
    // [16] (byte~) getValue::$4 ← (byte~) getValue::$0 << (byte) 1 -- vbuaa=vbuaa_rol_1 
    asl
    // [17] (byte~) getValue::$1 ← *((const word*) arr16 + (byte~) getValue::$4) & (byte) $ff -- vbuaa=pwuc1_derefidx_vbuaa_band_vbuc2 
    tay
    lda #$ff
    and arr16,y
    // [18] (byte~) getValue::$2 ← (byte~) getValue::$1 >> (byte) 1 -- vbuaa=vbuaa_ror_1 
    lsr
    // [19] (word) getValue::return#1 ← (word)(byte~) getValue::$2 -- vwuz1=_word_vbuaa 
    sta.z return
    lda #0
    sta.z return+1
    jmp __breturn
    // getValue::@return
  __breturn:
    // [20] return 
    rts
}
  // File Data
  arr16: .fill 2*$80, 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b2 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b2:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const word*) arr16[(number) $80]  = { fill( $80, 0) }
(word()) getValue((word) getValue::index)
(byte~) getValue::$0 reg byte a 4.0
(byte~) getValue::$1 reg byte a 4.0
(byte~) getValue::$2 reg byte a 2.0
(byte~) getValue::$4 reg byte a 4.0
(label) getValue::@return
(word) getValue::index
(word) getValue::index#0 index zp[2]:2 13.0
(word) getValue::return
(word) getValue::return#0 return zp[2]:4 22.0
(word) getValue::return#1 return zp[2]:4 4.333333333333333
(void()) main()
(word~) main::$0 zp[2]:4 11.0
(byte~) main::$2 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@return
(const word*) main::SCREEN = (word*) 1024
(byte) main::idx
(byte) main::idx#1 reg byte x 16.5
(byte) main::idx#2 reg byte x 6.285714285714286

reg byte x [ main::idx#2 main::idx#1 ]
zp[2]:2 [ getValue::index#0 ]
zp[2]:4 [ getValue::return#0 main::$0 getValue::return#1 ]
reg byte a [ main::$2 ]
reg byte a [ getValue::$0 ]
reg byte a [ getValue::$4 ]
reg byte a [ getValue::$1 ]
reg byte a [ getValue::$2 ]


FINAL ASSEMBLER
Score: 502

  // File Comments
// Test KickC performance for 16-bit array lookup function from article "Optimizing C array lookups for the 6502"
// http://8bitworkshop.com/blog/compilers/2019/03/17/cc65-optimization.html
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label SCREEN = $400
    .label __0 = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::idx#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [5] phi (byte) main::idx#2 = (byte) main::idx#1 [phi:main::@2->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // getValue(idx)
    // [6] (word) getValue::index#0 ← (byte) main::idx#2 -- vwuz1=vbuxx 
    txa
    sta.z getValue.index
    lda #0
    sta.z getValue.index+1
    // [7] call getValue 
    jsr getValue
    // [8] (word) getValue::return#0 ← (word) getValue::return#1
    // main::@2
    // [9] (word~) main::$0 ← (word) getValue::return#0
    // SCREEN[idx] = getValue(idx)
    // [10] (byte~) main::$2 ← (byte) main::idx#2 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [11] *((const word*) main::SCREEN + (byte~) main::$2) ← (word~) main::$0 -- pwuc1_derefidx_vbuaa=vwuz1 
    tay
    lda.z __0
    sta SCREEN,y
    lda.z __0+1
    sta SCREEN+1,y
    // for(unsigned char idx : 0..128)
    // [12] (byte) main::idx#1 ← ++ (byte) main::idx#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if((byte) main::idx#1!=(byte) $81) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$81
    bne __b1
    // main::@return
    // }
    // [14] return 
    rts
}
  // getValue
// getValue(word zp(2) index)
getValue: {
    .label index = 2
    .label return = 4
    // index & 0x7f
    // [15] (byte~) getValue::$0 ← (word) getValue::index#0 & (byte) $7f -- vbuaa=vwuz1_band_vbuc1 
    lda #$7f
    and.z index
    // arr16[index & 0x7f] & 0xff
    // [16] (byte~) getValue::$4 ← (byte~) getValue::$0 << (byte) 1 -- vbuaa=vbuaa_rol_1 
    asl
    // [17] (byte~) getValue::$1 ← *((const word*) arr16 + (byte~) getValue::$4) & (byte) $ff -- vbuaa=pwuc1_derefidx_vbuaa_band_vbuc2 
    tay
    lda #$ff
    and arr16,y
    // (arr16[index & 0x7f] & 0xff) >> 1
    // [18] (byte~) getValue::$2 ← (byte~) getValue::$1 >> (byte) 1 -- vbuaa=vbuaa_ror_1 
    lsr
    // (unsigned int)((arr16[index & 0x7f] & 0xff) >> 1)
    // [19] (word) getValue::return#1 ← (word)(byte~) getValue::$2 -- vwuz1=_word_vbuaa 
    sta.z return
    lda #0
    sta.z return+1
    // getValue::@return
    // }
    // [20] return 
    rts
}
  // File Data
  arr16: .fill 2*$80, 0

