Fixing constant pointer addition (const signed word*) VALS+(number) 1
Fixing pointer array-indexing *((const signed word*) VALS + (byte) main::i)
Fixing pointer array-indexing *((const signed word*) SCREEN + (byte) idx)
Culled Empty Block (label) main::@2

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

(void()) main()
main: scope:[main]  from @2
  (byte) idx#15 ← phi( @2/(byte) idx#17 )
  (signed word*) print::p#0 ← (const signed word*) VALS
  call print 
  to:main::@3
main::@3: scope:[main]  from main
  (byte) idx#8 ← phi( main/(byte) idx#6 )
  (byte) idx#0 ← (byte) idx#8
  (signed word*) print::p#1 ← (const signed word*) VALS+(number) 1*(const byte) SIZEOF_SIGNED_WORD
  call print 
  to:main::@4
main::@4: scope:[main]  from main::@3
  (byte) idx#9 ← phi( main::@3/(byte) idx#6 )
  (byte) idx#1 ← (byte) idx#9
  (byte) main::i#0 ← (byte) 2
  to:main::@1
main::@1: scope:[main]  from main::@4 main::@5
  (byte) idx#16 ← phi( main::@4/(byte) idx#1 main::@5/(byte) idx#2 )
  (byte) main::i#2 ← phi( main::@4/(byte) main::i#0 main::@5/(byte) main::i#1 )
  (byte~) main::$5 ← (byte) main::i#2 * (const byte) SIZEOF_SIGNED_WORD
  (signed word*~) main::$2 ← & *((const signed word*) VALS + (byte~) main::$5)
  (signed word*) print::p#2 ← (signed word*~) main::$2
  call print 
  to:main::@5
main::@5: scope:[main]  from main::@1
  (byte) main::i#3 ← phi( main::@1/(byte) main::i#2 )
  (byte) idx#10 ← phi( main::@1/(byte) idx#6 )
  (byte) idx#2 ← (byte) idx#10
  (byte) main::i#1 ← (byte) main::i#3 + rangenext(2,3)
  (bool~) main::$4 ← (byte) main::i#1 != rangelast(2,3)
  if((bool~) main::$4) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@5
  (byte) idx#11 ← phi( main::@5/(byte) idx#2 )
  (byte) idx#3 ← (byte) idx#11
  return 
  to:@return
@1: scope:[]  from @begin
  (byte) idx#4 ← (byte) 0
  to:@2

(void()) print((signed word*) print::p)
print: scope:[print]  from main main::@1 main::@3
  (signed word*) print::p#3 ← phi( main/(signed word*) print::p#0 main::@1/(signed word*) print::p#2 main::@3/(signed word*) print::p#1 )
  (byte) idx#12 ← phi( main/(byte) idx#15 main::@1/(byte) idx#16 main::@3/(byte) idx#0 )
  (byte~) print::$0 ← (byte) idx#12 * (const byte) SIZEOF_SIGNED_WORD
  *((const signed word*) SCREEN + (byte~) print::$0) ← *((signed word*) print::p#3)
  (byte) idx#5 ← ++ (byte) idx#12
  to:print::@return
print::@return: scope:[print]  from print
  (byte) idx#13 ← phi( print/(byte) idx#5 )
  (byte) idx#6 ← (byte) idx#13
  return 
  to:@return
@2: scope:[]  from @1
  (byte) idx#17 ← phi( @1/(byte) idx#4 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) idx#14 ← phi( @2/(byte) idx#3 )
  (byte) idx#7 ← (byte) idx#14
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @3
(label) @begin
(label) @end
(const signed word*) SCREEN = (signed word*)(number) $400
(const byte) SIZEOF_SIGNED_WORD = (byte) 2
(const signed word*) VALS[]  = { (signed word) 1, (signed word) 2, (signed word) 3, (signed word) 4 }
(byte) idx
(byte) idx#0
(byte) idx#1
(byte) idx#10
(byte) idx#11
(byte) idx#12
(byte) idx#13
(byte) idx#14
(byte) idx#15
(byte) idx#16
(byte) idx#17
(byte) idx#2
(byte) idx#3
(byte) idx#4
(byte) idx#5
(byte) idx#6
(byte) idx#7
(byte) idx#8
(byte) idx#9
(void()) main()
(signed word*~) main::$2
(bool~) main::$4
(byte~) main::$5
(label) main::@1
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::i#3
(void()) print((signed word*) print::p)
(byte~) print::$0
(label) print::@return
(signed word*) print::p
(signed word*) print::p#0
(signed word*) print::p#1
(signed word*) print::p#2
(signed word*) print::p#3

Adding number conversion cast (unumber) 1*SIZEOF_SIGNED_WORD in (signed word*) print::p#1 ← (const signed word*) VALS+(number) 1*(const byte) SIZEOF_SIGNED_WORD
Adding number conversion cast (unumber) 1 in (signed word*) print::p#1 ← (const signed word*) VALS+(unumber)(number) 1*(const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (signed word*) 1024
Simplifying constant integer cast (unumber)(number) 1*(const byte) SIZEOF_SIGNED_WORD
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) idx#0 = (byte) idx#8 
Alias (byte) idx#1 = (byte) idx#9 
Alias (signed word*) print::p#2 = (signed word*~) main::$2 
Alias (byte) main::i#2 = (byte) main::i#3 
Alias (byte) idx#10 = (byte) idx#2 (byte) idx#11 (byte) idx#3 
Alias (byte) idx#13 = (byte) idx#5 (byte) idx#6 
Alias (byte) idx#17 = (byte) idx#4 
Alias (byte) idx#14 = (byte) idx#7 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) idx#15 (byte) idx#17
Identical Phi Values (byte) idx#0 (byte) idx#13
Identical Phi Values (byte) idx#1 (byte) idx#13
Identical Phi Values (byte) idx#10 (byte) idx#13
Identical Phi Values (byte) idx#14 (byte) idx#10
Successful SSA optimization Pass2IdenticalPhiElimination
Identical Phi Values (byte) idx#16 (byte) idx#13
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$4 [19] if((byte) main::i#1!=rangelast(2,3)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Rewriting array member address-of to pointer addition [12] (signed word*) print::p#2 ← (const signed word*) VALS + (byte~) main::$5
Successful SSA optimization PassNArrayElementAddressOfRewriting
Constant (const signed word*) print::p#0 = VALS
Constant (const signed word*) print::p#1 = VALS+1*SIZEOF_SIGNED_WORD
Constant (const byte) main::i#0 = 2
Constant (const byte) idx#17 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [17] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [19] if(main::i#1!=rangelast(2,3)) goto main::@1 to (number) 4
Adding number conversion cast (unumber) 4 in if((byte) main::i#1!=(number) 4) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 4
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting multiplication to use shift [3] (byte~) main::$5 ← (byte) main::i#2 * (const byte) SIZEOF_SIGNED_WORD
Rewriting multiplication to use shift [10] (byte~) print::$0 ← (byte) idx#12 * (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const byte) main::i#0
Inlining constant with var siblings (const signed word*) print::p#0
Inlining constant with var siblings (const signed word*) print::p#1
Inlining constant with var siblings (const byte) idx#17
Constant inlined main::i#0 = (byte) 2
Constant inlined idx#17 = (byte) 0
Constant inlined print::p#1 = (const signed word*) VALS+(byte) 1*(const byte) SIZEOF_SIGNED_WORD
Constant inlined print::p#0 = (const signed word*) VALS
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@6(between main::@5 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
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
Adding NOP phi() at start of main::@4
CALL GRAPH
Calls in [] to main:3 
Calls in [main] to print:7 print:9 print:16 

Created 3 initial phi equivalence classes
Coalesced [8] idx#19 ← idx#13
Coalesced (already) [14] idx#18 ← idx#13
Coalesced [15] print::p#4 ← print::p#2
Coalesced [20] main::i#4 ← main::i#1
Coalesced down to 3 phi equivalence classes
Culled Empty Block (label) @1
Culled Empty Block (label) @3
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@6
Renumbering block @2 to @1
Renumbering block main::@3 to main::@2
Renumbering block main::@5 to main::@3
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
Adding NOP phi() at start of main::@2

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()
  [5] call print 
  to:main::@2
main::@2: scope:[main]  from main
  [6] phi()
  [7] call print 
  to:main::@1
main::@1: scope:[main]  from main::@2 main::@3
  [8] (byte) main::i#2 ← phi( main::@2/(byte) 2 main::@3/(byte) main::i#1 )
  [9] (byte~) main::$5 ← (byte) main::i#2 << (byte) 1
  [10] (signed word*) print::p#2 ← (const signed word*) VALS + (byte~) main::$5
  [11] call print 
  to:main::@3
main::@3: scope:[main]  from main::@1
  [12] (byte) main::i#1 ← ++ (byte) main::i#2
  [13] if((byte) main::i#1!=(byte) 4) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  [14] return 
  to:@return

(void()) print((signed word*) print::p)
print: scope:[print]  from main main::@1 main::@2
  [15] (signed word*) print::p#3 ← phi( main/(const signed word*) VALS main::@1/(signed word*) print::p#2 main::@2/(const signed word*) VALS+(byte) 1*(const byte) SIZEOF_SIGNED_WORD )
  [15] (byte) idx#12 ← phi( main/(byte) 0 main::@1/(byte) idx#13 main::@2/(byte) idx#13 )
  [16] (byte~) print::$0 ← (byte) idx#12 << (byte) 1
  [17] *((const signed word*) SCREEN + (byte~) print::$0) ← *((signed word*) print::p#3)
  [18] (byte) idx#13 ← ++ (byte) idx#12
  to:print::@return
print::@return: scope:[print]  from print
  [19] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) idx
(byte) idx#12 5.666666666666667
(byte) idx#13 1.3636363636363638
(void()) main()
(byte~) main::$5 22.0
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 8.25
(void()) print((signed word*) print::p)
(byte~) print::$0 4.0
(signed word*) print::p
(signed word*) print::p#2 22.0
(signed word*) print::p#3 6.5

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ idx#12 idx#13 ]
[ print::p#3 print::p#2 ]
Added variable main::$5 to live range equivalence class [ main::$5 ]
Added variable print::$0 to live range equivalence class [ print::$0 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ idx#12 idx#13 ]
[ print::p#3 print::p#2 ]
[ main::$5 ]
[ print::$0 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ idx#12 idx#13 ]
Allocated zp[2]:4 [ print::p#3 print::p#2 ]
Allocated zp[1]:6 [ main::$5 ]
Allocated zp[1]:7 [ print::$0 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test address-of an array element
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const SIZEOF_SIGNED_WORD = 2
  .label idx = 3
  // @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 __5 = 6
    .label i = 2
    // [5] call print 
    // [15] phi from main to print [phi:main->print]
  print_from_main:
    // [15] phi (signed word*) print::p#3 = (const signed word*) VALS [phi:main->print#0] -- pwsz1=pwsc1 
    lda #<VALS
    sta.z print.p
    lda #>VALS
    sta.z print.p+1
    // [15] phi (byte) idx#12 = (byte) 0 [phi:main->print#1] -- vbuz1=vbuc1 
    lda #0
    sta.z idx
    jsr print
    // [6] phi from main to main::@2 [phi:main->main::@2]
  __b2_from_main:
    jmp __b2
    // main::@2
  __b2:
    // [7] call print 
    // [15] phi from main::@2 to print [phi:main::@2->print]
  print_from___b2:
    // [15] phi (signed word*) print::p#3 = (const signed word*) VALS+(byte) 1*(const byte) SIZEOF_SIGNED_WORD [phi:main::@2->print#0] -- pwsz1=pwsc1 
    lda #<VALS+1*SIZEOF_SIGNED_WORD
    sta.z print.p
    lda #>VALS+1*SIZEOF_SIGNED_WORD
    sta.z print.p+1
    // [15] phi (byte) idx#12 = (byte) idx#13 [phi:main::@2->print#1] -- register_copy 
    jsr print
    // [8] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [8] phi (byte) main::i#2 = (byte) 2 [phi:main::@2->main::@1#0] -- vbuz1=vbuc1 
    lda #2
    sta.z i
    jmp __b1
    // [8] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [8] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [9] (byte~) main::$5 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z i
    asl
    sta.z __5
    // [10] (signed word*) print::p#2 ← (const signed word*) VALS + (byte~) main::$5 -- pwsz1=pwsc1_plus_vbuz2 
    lda.z __5
    clc
    adc #<VALS
    sta.z print.p
    lda #>VALS
    adc #0
    sta.z print.p+1
    // [11] call print 
    // [15] phi from main::@1 to print [phi:main::@1->print]
  print_from___b1:
    // [15] phi (signed word*) print::p#3 = (signed word*) print::p#2 [phi:main::@1->print#0] -- register_copy 
    // [15] phi (byte) idx#12 = (byte) idx#13 [phi:main::@1->print#1] -- register_copy 
    jsr print
    jmp __b3
    // main::@3
  __b3:
    // [12] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [13] if((byte) main::i#1!=(byte) 4) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #4
    cmp.z i
    bne __b1_from___b3
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // print
// print(signed word* zp(4) p)
print: {
    .label __0 = 7
    .label p = 4
    // [16] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z idx
    asl
    sta.z __0
    // [17] *((const signed word*) SCREEN + (byte~) print::$0) ← *((signed word*) print::p#3) -- pwsc1_derefidx_vbuz1=_deref_pwsz2 
    ldx.z __0
    ldy #0
    lda (p),y
    sta SCREEN,x
    iny
    lda (p),y
    sta SCREEN+1,x
    // [18] (byte) idx#13 ← ++ (byte) idx#12 -- vbuz1=_inc_vbuz1 
    inc.z idx
    jmp __breturn
    // print::@return
  __breturn:
    // [19] return 
    rts
}
  // File Data
  VALS: .word 1, 2, 3, 4

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [9] (byte~) main::$5 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::$5 idx#13 ] ( main:2 [ main::i#2 main::$5 idx#13 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:3 [ idx#12 idx#13 ]
Statement [10] (signed word*) print::p#2 ← (const signed word*) VALS + (byte~) main::$5 [ main::i#2 print::p#2 idx#13 ] ( main:2 [ main::i#2 print::p#2 idx#13 ] ) always clobbers reg byte a 
Statement [16] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 [ idx#12 print::p#3 print::$0 ] ( main:2::print:5 [ idx#12 print::p#3 print::$0 ] main:2::print:7 [ idx#12 print::p#3 print::$0 ] main:2::print:11 [ main::i#2 idx#12 print::p#3 print::$0 ] ) always clobbers reg byte a 
Statement [17] *((const signed word*) SCREEN + (byte~) print::$0) ← *((signed word*) print::p#3) [ idx#12 ] ( main:2::print:5 [ idx#12 ] main:2::print:7 [ idx#12 ] main:2::print:11 [ main::i#2 idx#12 ] ) always clobbers reg byte a reg byte y 
Removing always clobbered register reg byte y as potential for zp[1]:3 [ idx#12 idx#13 ]
Removing always clobbered register reg byte y as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [9] (byte~) main::$5 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::$5 idx#13 ] ( main:2 [ main::i#2 main::$5 idx#13 ] ) always clobbers reg byte a 
Statement [10] (signed word*) print::p#2 ← (const signed word*) VALS + (byte~) main::$5 [ main::i#2 print::p#2 idx#13 ] ( main:2 [ main::i#2 print::p#2 idx#13 ] ) always clobbers reg byte a 
Statement [16] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 [ idx#12 print::p#3 print::$0 ] ( main:2::print:5 [ idx#12 print::p#3 print::$0 ] main:2::print:7 [ idx#12 print::p#3 print::$0 ] main:2::print:11 [ main::i#2 idx#12 print::p#3 print::$0 ] ) always clobbers reg byte a 
Statement [17] *((const signed word*) SCREEN + (byte~) print::$0) ← *((signed word*) print::p#3) [ idx#12 ] ( main:2::print:5 [ idx#12 ] main:2::print:7 [ idx#12 ] main:2::print:11 [ main::i#2 idx#12 ] ) always clobbers reg byte a reg byte y 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , 
Potential registers zp[1]:3 [ idx#12 idx#13 ] : zp[1]:3 , reg byte x , 
Potential registers zp[2]:4 [ print::p#3 print::p#2 ] : zp[2]:4 , 
Potential registers zp[1]:6 [ main::$5 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:7 [ print::$0 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 24.75: zp[1]:2 [ main::i#2 main::i#1 ] 22: zp[1]:6 [ main::$5 ] 
Uplift Scope [print] 28.5: zp[2]:4 [ print::p#3 print::p#2 ] 4: zp[1]:7 [ print::$0 ] 
Uplift Scope [] 7.03: zp[1]:3 [ idx#12 idx#13 ] 

Uplifting [main] best 572 combination zp[1]:2 [ main::i#2 main::i#1 ] reg byte a [ main::$5 ] 
Uplifting [print] best 568 combination zp[2]:4 [ print::p#3 print::p#2 ] reg byte a [ print::$0 ] 
Uplifting [] best 568 combination zp[1]:3 [ idx#12 idx#13 ] 
Attempting to uplift remaining variables inzp[1]:2 [ main::i#2 main::i#1 ]
Uplifting [main] best 568 combination zp[1]:2 [ main::i#2 main::i#1 ] 
Attempting to uplift remaining variables inzp[1]:3 [ idx#12 idx#13 ]
Uplifting [] best 568 combination zp[1]:3 [ idx#12 idx#13 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test address-of an array element
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const SIZEOF_SIGNED_WORD = 2
  .label idx = 3
  // @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 i = 2
    // [5] call print 
    // [15] phi from main to print [phi:main->print]
  print_from_main:
    // [15] phi (signed word*) print::p#3 = (const signed word*) VALS [phi:main->print#0] -- pwsz1=pwsc1 
    lda #<VALS
    sta.z print.p
    lda #>VALS
    sta.z print.p+1
    // [15] phi (byte) idx#12 = (byte) 0 [phi:main->print#1] -- vbuz1=vbuc1 
    lda #0
    sta.z idx
    jsr print
    // [6] phi from main to main::@2 [phi:main->main::@2]
  __b2_from_main:
    jmp __b2
    // main::@2
  __b2:
    // [7] call print 
    // [15] phi from main::@2 to print [phi:main::@2->print]
  print_from___b2:
    // [15] phi (signed word*) print::p#3 = (const signed word*) VALS+(byte) 1*(const byte) SIZEOF_SIGNED_WORD [phi:main::@2->print#0] -- pwsz1=pwsc1 
    lda #<VALS+1*SIZEOF_SIGNED_WORD
    sta.z print.p
    lda #>VALS+1*SIZEOF_SIGNED_WORD
    sta.z print.p+1
    // [15] phi (byte) idx#12 = (byte) idx#13 [phi:main::@2->print#1] -- register_copy 
    jsr print
    // [8] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [8] phi (byte) main::i#2 = (byte) 2 [phi:main::@2->main::@1#0] -- vbuz1=vbuc1 
    lda #2
    sta.z i
    jmp __b1
    // [8] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [8] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [9] (byte~) main::$5 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuz1_rol_1 
    lda.z i
    asl
    // [10] (signed word*) print::p#2 ← (const signed word*) VALS + (byte~) main::$5 -- pwsz1=pwsc1_plus_vbuaa 
    clc
    adc #<VALS
    sta.z print.p
    lda #>VALS
    adc #0
    sta.z print.p+1
    // [11] call print 
    // [15] phi from main::@1 to print [phi:main::@1->print]
  print_from___b1:
    // [15] phi (signed word*) print::p#3 = (signed word*) print::p#2 [phi:main::@1->print#0] -- register_copy 
    // [15] phi (byte) idx#12 = (byte) idx#13 [phi:main::@1->print#1] -- register_copy 
    jsr print
    jmp __b3
    // main::@3
  __b3:
    // [12] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [13] if((byte) main::i#1!=(byte) 4) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #4
    cmp.z i
    bne __b1_from___b3
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // print
// print(signed word* zp(4) p)
print: {
    .label p = 4
    // [16] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 -- vbuaa=vbuz1_rol_1 
    lda.z idx
    asl
    // [17] *((const signed word*) SCREEN + (byte~) print::$0) ← *((signed word*) print::p#3) -- pwsc1_derefidx_vbuaa=_deref_pwsz1 
    tax
    ldy #0
    lda (p),y
    sta SCREEN,x
    iny
    lda (p),y
    sta SCREEN+1,x
    // [18] (byte) idx#13 ← ++ (byte) idx#12 -- vbuz1=_inc_vbuz1 
    inc.z idx
    jmp __breturn
    // print::@return
  __breturn:
    // [19] return 
    rts
}
  // File Data
  VALS: .word 1, 2, 3, 4

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b2
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b3 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b2_from_main:
Removing instruction print_from___b2:
Removing instruction __b1_from___b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction print_from_main:
Removing instruction __b2:
Removing instruction __b1_from___b2:
Removing instruction print_from___b1:
Removing instruction __b3:
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 signed word*) SCREEN = (signed word*) 1024
(const byte) SIZEOF_SIGNED_WORD = (byte) 2
(const signed word*) VALS[]  = { (signed word) 1, (signed word) 2, (signed word) 3, (signed word) 4 }
(byte) idx
(byte) idx#12 idx zp[1]:3 5.666666666666667
(byte) idx#13 idx zp[1]:3 1.3636363636363638
(void()) main()
(byte~) main::$5 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) main::i
(byte) main::i#1 i zp[1]:2 16.5
(byte) main::i#2 i zp[1]:2 8.25
(void()) print((signed word*) print::p)
(byte~) print::$0 reg byte a 4.0
(label) print::@return
(signed word*) print::p
(signed word*) print::p#2 p zp[2]:4 22.0
(signed word*) print::p#3 p zp[2]:4 6.5

zp[1]:2 [ main::i#2 main::i#1 ]
zp[1]:3 [ idx#12 idx#13 ]
zp[2]:4 [ print::p#3 print::p#2 ]
reg byte a [ main::$5 ]
reg byte a [ print::$0 ]


FINAL ASSEMBLER
Score: 457

  // File Comments
// Test address-of an array element
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const SIZEOF_SIGNED_WORD = 2
  .label idx = 3
  // @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 i = 2
    // print(VALS)
    // [5] call print 
    // [15] phi from main to print [phi:main->print]
    // [15] phi (signed word*) print::p#3 = (const signed word*) VALS [phi:main->print#0] -- pwsz1=pwsc1 
    lda #<VALS
    sta.z print.p
    lda #>VALS
    sta.z print.p+1
    // [15] phi (byte) idx#12 = (byte) 0 [phi:main->print#1] -- vbuz1=vbuc1 
    lda #0
    sta.z idx
    jsr print
    // [6] phi from main to main::@2 [phi:main->main::@2]
    // main::@2
    // print(&VALS[1])
    // [7] call print 
    // [15] phi from main::@2 to print [phi:main::@2->print]
    // [15] phi (signed word*) print::p#3 = (const signed word*) VALS+(byte) 1*(const byte) SIZEOF_SIGNED_WORD [phi:main::@2->print#0] -- pwsz1=pwsc1 
    lda #<VALS+1*SIZEOF_SIGNED_WORD
    sta.z print.p
    lda #>VALS+1*SIZEOF_SIGNED_WORD
    sta.z print.p+1
    // [15] phi (byte) idx#12 = (byte) idx#13 [phi:main::@2->print#1] -- register_copy 
    jsr print
    // [8] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [8] phi (byte) main::i#2 = (byte) 2 [phi:main::@2->main::@1#0] -- vbuz1=vbuc1 
    lda #2
    sta.z i
    // [8] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
    // [8] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@3->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // &VALS[i]
    // [9] (byte~) main::$5 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuz1_rol_1 
    lda.z i
    asl
    // print(&VALS[i])
    // [10] (signed word*) print::p#2 ← (const signed word*) VALS + (byte~) main::$5 -- pwsz1=pwsc1_plus_vbuaa 
    clc
    adc #<VALS
    sta.z print.p
    lda #>VALS
    adc #0
    sta.z print.p+1
    // [11] call print 
    // [15] phi from main::@1 to print [phi:main::@1->print]
    // [15] phi (signed word*) print::p#3 = (signed word*) print::p#2 [phi:main::@1->print#0] -- register_copy 
    // [15] phi (byte) idx#12 = (byte) idx#13 [phi:main::@1->print#1] -- register_copy 
    jsr print
    // main::@3
    // for(char i:2..3)
    // [12] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [13] if((byte) main::i#1!=(byte) 4) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #4
    cmp.z i
    bne __b1
    // main::@return
    // }
    // [14] return 
    rts
}
  // print
// print(signed word* zp(4) p)
print: {
    .label p = 4
    // SCREEN[idx++] = *p
    // [16] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 -- vbuaa=vbuz1_rol_1 
    lda.z idx
    asl
    // [17] *((const signed word*) SCREEN + (byte~) print::$0) ← *((signed word*) print::p#3) -- pwsc1_derefidx_vbuaa=_deref_pwsz1 
    tax
    ldy #0
    lda (p),y
    sta SCREEN,x
    iny
    lda (p),y
    sta SCREEN+1,x
    // SCREEN[idx++] = *p;
    // [18] (byte) idx#13 ← ++ (byte) idx#12 -- vbuz1=_inc_vbuz1 
    inc.z idx
    // print::@return
    // }
    // [19] return 
    rts
}
  // File Data
  VALS: .word 1, 2, 3, 4

