Warning! Adding boolean cast to non-boolean condition (number~) main::$0
Warning! Adding boolean cast to non-boolean condition (number~) main::$6
Culled Empty Block (label) main::@8
Culled Empty Block (label) main::@9
Culled Empty Block (label) main::@10
Culled Empty Block (label) main::@11
Culled Empty Block (label) main::@12

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

(void()) main()
main: scope:[main]  from @1
  (byte*) main::screen#0 ← (byte*)(number) $400
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@7
  (byte*) main::screen#9 ← phi( main/(byte*) main::screen#0 main::@7/(byte*) main::screen#2 )
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@7/(byte) main::i#1 )
  (number~) main::$0 ← (byte) main::i#2 & (number) 1
  (bool~) main::$13 ← (number) 0 != (number~) main::$0
  if((bool~) main::$13) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  (byte*) main::screen#5 ← phi( main::@1/(byte*) main::screen#9 )
  (byte) main::i#3 ← phi( main::@1/(byte) main::i#2 )
  (number~) main::$3 ← (byte) main::i#3 + (number) 3
  (number~) main::$4 ← (number~) main::$3
  to:main::@4
main::@3: scope:[main]  from main::@1
  (byte*) main::screen#6 ← phi( main::@1/(byte*) main::screen#9 )
  (byte) main::i#4 ← phi( main::@1/(byte) main::i#2 )
  (number~) main::$1 ← (byte) main::i#4 * (number) 4
  (number~) main::$2 ← (number~) main::$1
  to:main::@4
main::@4: scope:[main]  from main::@2 main::@3
  (byte) main::i#5 ← phi( main::@2/(byte) main::i#3 main::@3/(byte) main::i#4 )
  (byte*) main::screen#3 ← phi( main::@2/(byte*) main::screen#5 main::@3/(byte*) main::screen#6 )
  (number~) main::$5 ← phi( main::@2/(number~) main::$4 main::@3/(number~) main::$2 )
  *((byte*) main::screen#3) ← (number~) main::$5
  (byte*) main::screen#1 ← ++ (byte*) main::screen#3
  (number~) main::$6 ← (byte) main::i#5 & (number) 1
  (bool~) main::$14 ← (number) 0 != (number~) main::$6
  if((bool~) main::$14) goto main::@5
  to:main::@6
main::@5: scope:[main]  from main::@4
  (byte*) main::screen#7 ← phi( main::@4/(byte*) main::screen#1 )
  (byte) main::i#6 ← phi( main::@4/(byte) main::i#5 )
  (number~) main::$9 ← (byte) main::i#6 + (number) 3
  (number~) main::$10 ← (number~) main::$9
  to:main::@7
main::@6: scope:[main]  from main::@4
  (byte*) main::screen#8 ← phi( main::@4/(byte*) main::screen#1 )
  (byte) main::i#7 ← phi( main::@4/(byte) main::i#5 )
  (number~) main::$7 ← (byte) main::i#7 * (number) 4
  (number~) main::$8 ← (number~) main::$7
  to:main::@7
main::@7: scope:[main]  from main::@5 main::@6
  (byte) main::i#8 ← phi( main::@5/(byte) main::i#6 main::@6/(byte) main::i#7 )
  (byte*) main::screen#4 ← phi( main::@5/(byte*) main::screen#7 main::@6/(byte*) main::screen#8 )
  (number~) main::$11 ← phi( main::@5/(number~) main::$10 main::@6/(number~) main::$8 )
  *((byte*) main::screen#4) ← (number~) main::$11
  (byte*) main::screen#2 ← ++ (byte*) main::screen#4
  (byte) main::i#1 ← (byte) main::i#8 + rangenext(0,2)
  (bool~) main::$12 ← (byte) main::i#1 != rangelast(0,2)
  if((bool~) main::$12) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@7
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(void()) main()
(number~) main::$0
(number~) main::$1
(number~) main::$10
(number~) main::$11
(bool~) main::$12
(bool~) main::$13
(bool~) main::$14
(number~) main::$2
(number~) main::$3
(number~) main::$4
(number~) main::$5
(number~) main::$6
(number~) main::$7
(number~) main::$8
(number~) main::$9
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@7
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte) main::i#3
(byte) main::i#4
(byte) main::i#5
(byte) main::i#6
(byte) main::i#7
(byte) main::i#8
(byte*) main::screen
(byte*) main::screen#0
(byte*) main::screen#1
(byte*) main::screen#2
(byte*) main::screen#3
(byte*) main::screen#4
(byte*) main::screen#5
(byte*) main::screen#6
(byte*) main::screen#7
(byte*) main::screen#8
(byte*) main::screen#9

Adding number conversion cast (unumber) 1 in (number~) main::$0 ← (byte) main::i#2 & (number) 1
Adding number conversion cast (unumber) main::$0 in (number~) main::$0 ← (byte) main::i#2 & (unumber)(number) 1
Adding number conversion cast (unumber) 0 in (bool~) main::$13 ← (number) 0 != (unumber~) main::$0
Adding number conversion cast (unumber) 3 in (number~) main::$3 ← (byte) main::i#3 + (number) 3
Adding number conversion cast (unumber) main::$3 in (number~) main::$3 ← (byte) main::i#3 + (unumber)(number) 3
Adding number conversion cast (unumber) main::$4 in (number~) main::$4 ← (unumber~) main::$3
Adding number conversion cast (unumber) 4 in (number~) main::$1 ← (byte) main::i#4 * (number) 4
Adding number conversion cast (unumber) main::$1 in (number~) main::$1 ← (byte) main::i#4 * (unumber)(number) 4
Adding number conversion cast (unumber) main::$2 in (number~) main::$2 ← (unumber~) main::$1
Adding number conversion cast (unumber) main::$5 in (byte) main::i#5 ← phi( main::@2/(byte) main::i#3 main::@3/(byte) main::i#4 )
  (byte*) main::screen#3 ← phi( main::@2/(byte*) main::screen#5 main::@3/(byte*) main::screen#6 )
  (number~) main::$5 ← phi( main::@2/(unumber~) main::$4 main::@3/(unumber~) main::$2 )
Adding number conversion cast (unumber) 1 in (number~) main::$6 ← (byte) main::i#5 & (number) 1
Adding number conversion cast (unumber) main::$6 in (number~) main::$6 ← (byte) main::i#5 & (unumber)(number) 1
Adding number conversion cast (unumber) 0 in (bool~) main::$14 ← (number) 0 != (unumber~) main::$6
Adding number conversion cast (unumber) 3 in (number~) main::$9 ← (byte) main::i#6 + (number) 3
Adding number conversion cast (unumber) main::$9 in (number~) main::$9 ← (byte) main::i#6 + (unumber)(number) 3
Adding number conversion cast (unumber) main::$10 in (number~) main::$10 ← (unumber~) main::$9
Adding number conversion cast (unumber) 4 in (number~) main::$7 ← (byte) main::i#7 * (number) 4
Adding number conversion cast (unumber) main::$7 in (number~) main::$7 ← (byte) main::i#7 * (unumber)(number) 4
Adding number conversion cast (unumber) main::$8 in (number~) main::$8 ← (unumber~) main::$7
Adding number conversion cast (unumber) main::$11 in (byte) main::i#8 ← phi( main::@5/(byte) main::i#6 main::@6/(byte) main::i#7 )
  (byte*) main::screen#4 ← phi( main::@5/(byte*) main::screen#7 main::@6/(byte*) main::screen#8 )
  (number~) main::$11 ← phi( main::@5/(unumber~) main::$10 main::@6/(unumber~) main::$8 )
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 3
Simplifying constant integer cast 4
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 3
Simplifying constant integer cast 4
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 3
Finalized unsigned number type (byte) 4
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 3
Finalized unsigned number type (byte) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$0 ← (byte) main::i#2 & (byte) 1
Inferred type updated to byte in (unumber~) main::$3 ← (byte) main::i#3 + (byte) 3
Inferred type updated to byte in (unumber~) main::$4 ← (byte~) main::$3
Inferred type updated to byte in (unumber~) main::$1 ← (byte) main::i#4 * (byte) 4
Inferred type updated to byte in (unumber~) main::$2 ← (byte~) main::$1
Inferred type updated to byte for (unumber~) main::$5
Inferred type updated to byte in (unumber~) main::$6 ← (byte) main::i#5 & (byte) 1
Inferred type updated to byte in (unumber~) main::$9 ← (byte) main::i#6 + (byte) 3
Inferred type updated to byte in (unumber~) main::$10 ← (byte~) main::$9
Inferred type updated to byte in (unumber~) main::$7 ← (byte) main::i#7 * (byte) 4
Inferred type updated to byte in (unumber~) main::$8 ← (byte~) main::$7
Inferred type updated to byte for (unumber~) main::$11
Alias (byte) main::i#2 = (byte) main::i#3 (byte) main::i#4 
Alias (byte*) main::screen#5 = (byte*) main::screen#9 (byte*) main::screen#6 
Alias (byte~) main::$4 = (byte~) main::$3 
Alias (byte~) main::$2 = (byte~) main::$1 
Alias (byte) main::i#5 = (byte) main::i#6 (byte) main::i#7 
Alias (byte*) main::screen#1 = (byte*) main::screen#7 (byte*) main::screen#8 
Alias (byte~) main::$10 = (byte~) main::$9 
Alias (byte~) main::$8 = (byte~) main::$7 
Successful SSA optimization Pass2AliasElimination
Alias (byte*) main::screen#3 = (byte*) main::screen#5 
Alias (byte) main::i#2 = (byte) main::i#5 (byte) main::i#8 
Alias (byte*) main::screen#1 = (byte*) main::screen#4 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$13 [5] if((byte) 0!=(byte~) main::$0) goto main::@2
Simple Condition (bool~) main::$14 [17] if((byte) 0!=(byte~) main::$6) goto main::@5
Simple Condition (bool~) main::$12 [29] if((byte) main::i#1!=rangelast(0,2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) main::screen#0 = (byte*) 1024
Constant (const byte) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [27] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [29] if(main::i#1!=rangelast(0,2)) goto main::@1 to (number) 3
Adding number conversion cast (unumber) 3 in if((byte) main::i#1!=(number) 3) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting multiplication to use shift [4] (byte~) main::$2 ← (byte) main::i#2 * (byte) 4
Rewriting multiplication to use shift [11] (byte~) main::$8 ← (byte) main::i#2 * (byte) 4
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const byte*) main::screen#0
Inlining constant with var siblings (const byte) main::i#0
Constant inlined main::screen#0 = (byte*) 1024
Constant inlined main::i#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@13(between main::@7 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 @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 

Created 4 initial phi equivalence classes
Coalesced [10] main::$16 ← main::$2
Coalesced [17] main::$18 ← main::$8
Coalesced [24] main::i#9 ← main::i#1
Coalesced [25] main::screen#10 ← main::screen#2
Coalesced [27] main::$17 ← main::$10
Coalesced [29] main::$15 ← main::$4
Coalesced down to 4 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@13
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::@7
  [5] (byte*) main::screen#3 ← phi( main/(byte*) 1024 main::@7/(byte*) main::screen#2 )
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@7/(byte) main::i#1 )
  [6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1
  [7] if((byte) 0!=(byte~) main::$0) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [8] (byte~) main::$2 ← (byte) main::i#2 << (byte) 2
  to:main::@4
main::@4: scope:[main]  from main::@2 main::@3
  [9] (byte~) main::$5 ← phi( main::@2/(byte~) main::$4 main::@3/(byte~) main::$2 )
  [10] *((byte*) main::screen#3) ← (byte~) main::$5
  [11] (byte*) main::screen#1 ← ++ (byte*) main::screen#3
  [12] (byte~) main::$6 ← (byte) main::i#2 & (byte) 1
  [13] if((byte) 0!=(byte~) main::$6) goto main::@5
  to:main::@6
main::@6: scope:[main]  from main::@4
  [14] (byte~) main::$8 ← (byte) main::i#2 << (byte) 2
  to:main::@7
main::@7: scope:[main]  from main::@5 main::@6
  [15] (byte~) main::$11 ← phi( main::@5/(byte~) main::$10 main::@6/(byte~) main::$8 )
  [16] *((byte*) main::screen#1) ← (byte~) main::$11
  [17] (byte*) main::screen#2 ← ++ (byte*) main::screen#1
  [18] (byte) main::i#1 ← ++ (byte) main::i#2
  [19] if((byte) main::i#1!=(byte) 3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@7
  [20] return 
  to:@return
main::@5: scope:[main]  from main::@4
  [21] (byte~) main::$10 ← (byte) main::i#2 + (byte) 3
  to:main::@7
main::@2: scope:[main]  from main::@1
  [22] (byte~) main::$4 ← (byte) main::i#2 + (byte) 3
  to:main::@4


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$0 22.0
(byte~) main::$10 22.0
(byte~) main::$11 33.0
(byte~) main::$2 22.0
(byte~) main::$4 22.0
(byte~) main::$5 33.0
(byte~) main::$6 22.0
(byte~) main::$8 22.0
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 5.866666666666666
(byte*) main::screen
(byte*) main::screen#1 4.714285714285714
(byte*) main::screen#2 7.333333333333333
(byte*) main::screen#3 4.714285714285714

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::screen#3 main::screen#2 ]
[ main::$5 main::$4 main::$2 ]
[ main::$11 main::$10 main::$8 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::screen#1 to live range equivalence class [ main::screen#1 ]
Added variable main::$6 to live range equivalence class [ main::$6 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::screen#3 main::screen#2 ]
[ main::$5 main::$4 main::$2 ]
[ main::$11 main::$10 main::$8 ]
[ main::$0 ]
[ main::screen#1 ]
[ main::$6 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[2]:3 [ main::screen#3 main::screen#2 ]
Allocated zp[1]:5 [ main::$5 main::$4 main::$2 ]
Allocated zp[1]:6 [ main::$11 main::$10 main::$8 ]
Allocated zp[1]:7 [ main::$0 ]
Allocated zp[2]:8 [ main::screen#1 ]
Allocated zp[1]:10 [ main::$6 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Tests optimization of identical sub-expressions
  // 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 __0 = 7
    .label __2 = 5
    .label __4 = 5
    .label __5 = 5
    .label __6 = $a
    .label __8 = 6
    .label __10 = 6
    .label __11 = 6
    .label screen = 8
    .label screen_1 = 3
    .label i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte*) main::screen#3 = (byte*) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen_1
    lda #>$400
    sta.z screen_1+1
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // [5] phi from main::@7 to main::@1 [phi:main::@7->main::@1]
  __b1_from___b7:
    // [5] phi (byte*) main::screen#3 = (byte*) main::screen#2 [phi:main::@7->main::@1#0] -- register_copy 
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@7->main::@1#1] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1 -- vbuz1=vbuz2_band_vbuc1 
    lda #1
    and.z i
    sta.z __0
    // [7] if((byte) 0!=(byte~) main::$0) goto main::@2 -- vbuc1_neq_vbuz1_then_la1 
    lda #0
    cmp.z __0
    bne __b2
    jmp __b3
    // main::@3
  __b3:
    // [8] (byte~) main::$2 ← (byte) main::i#2 << (byte) 2 -- vbuz1=vbuz2_rol_2 
    lda.z i
    asl
    asl
    sta.z __2
    // [9] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
  __b4_from___b2:
  __b4_from___b3:
    // [9] phi (byte~) main::$5 = (byte~) main::$4 [phi:main::@2/main::@3->main::@4#0] -- register_copy 
    jmp __b4
    // main::@4
  __b4:
    // [10] *((byte*) main::screen#3) ← (byte~) main::$5 -- _deref_pbuz1=vbuz2 
    lda.z __5
    ldy #0
    sta (screen_1),y
    // [11] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 -- pbuz1=_inc_pbuz2 
    lda.z screen_1
    clc
    adc #1
    sta.z screen
    lda.z screen_1+1
    adc #0
    sta.z screen+1
    // [12] (byte~) main::$6 ← (byte) main::i#2 & (byte) 1 -- vbuz1=vbuz2_band_vbuc1 
    lda #1
    and.z i
    sta.z __6
    // [13] if((byte) 0!=(byte~) main::$6) goto main::@5 -- vbuc1_neq_vbuz1_then_la1 
    lda #0
    cmp.z __6
    bne __b5
    jmp __b6
    // main::@6
  __b6:
    // [14] (byte~) main::$8 ← (byte) main::i#2 << (byte) 2 -- vbuz1=vbuz2_rol_2 
    lda.z i
    asl
    asl
    sta.z __8
    // [15] phi from main::@5 main::@6 to main::@7 [phi:main::@5/main::@6->main::@7]
  __b7_from___b5:
  __b7_from___b6:
    // [15] phi (byte~) main::$11 = (byte~) main::$10 [phi:main::@5/main::@6->main::@7#0] -- register_copy 
    jmp __b7
    // main::@7
  __b7:
    // [16] *((byte*) main::screen#1) ← (byte~) main::$11 -- _deref_pbuz1=vbuz2 
    lda.z __11
    ldy #0
    sta (screen),y
    // [17] (byte*) main::screen#2 ← ++ (byte*) main::screen#1 -- pbuz1=_inc_pbuz2 
    lda.z screen
    clc
    adc #1
    sta.z screen_1
    lda.z screen+1
    adc #0
    sta.z screen_1+1
    // [18] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [19] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp.z i
    bne __b1_from___b7
    jmp __breturn
    // main::@return
  __breturn:
    // [20] return 
    rts
    // main::@5
  __b5:
    // [21] (byte~) main::$10 ← (byte) main::i#2 + (byte) 3 -- vbuz1=vbuz2_plus_vbuc1 
    lax.z i
    axs #-[3]
    stx.z __10
    jmp __b7_from___b5
    // main::@2
  __b2:
    // [22] (byte~) main::$4 ← (byte) main::i#2 + (byte) 3 -- vbuz1=vbuz2_plus_vbuc1 
    lax.z i
    axs #-[3]
    stx.z __4
    jmp __b4_from___b2
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [8] (byte~) main::$2 ← (byte) main::i#2 << (byte) 2 [ main::i#2 main::screen#3 main::$2 ] ( main:2 [ main::i#2 main::screen#3 main::$2 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [10] *((byte*) main::screen#3) ← (byte~) main::$5 [ main::i#2 main::screen#3 ] ( main:2 [ main::i#2 main::screen#3 ] ) always clobbers reg byte y 
Removing always clobbered register reg byte y as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [11] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 [ main::i#2 main::screen#1 ] ( main:2 [ main::i#2 main::screen#1 ] ) always clobbers reg byte a 
Statement [12] (byte~) main::$6 ← (byte) main::i#2 & (byte) 1 [ main::i#2 main::screen#1 main::$6 ] ( main:2 [ main::i#2 main::screen#1 main::$6 ] ) always clobbers reg byte a 
Statement [14] (byte~) main::$8 ← (byte) main::i#2 << (byte) 2 [ main::i#2 main::screen#1 main::$8 ] ( main:2 [ main::i#2 main::screen#1 main::$8 ] ) always clobbers reg byte a 
Statement [16] *((byte*) main::screen#1) ← (byte~) main::$11 [ main::i#2 main::screen#1 ] ( main:2 [ main::i#2 main::screen#1 ] ) always clobbers reg byte y 
Statement [17] (byte*) main::screen#2 ← ++ (byte*) main::screen#1 [ main::i#2 main::screen#2 ] ( main:2 [ main::i#2 main::screen#2 ] ) always clobbers reg byte a 
Statement [21] (byte~) main::$10 ← (byte) main::i#2 + (byte) 3 [ main::i#2 main::screen#1 main::$10 ] ( main:2 [ main::i#2 main::screen#1 main::$10 ] ) always clobbers reg byte a 
Statement [22] (byte~) main::$4 ← (byte) main::i#2 + (byte) 3 [ main::i#2 main::screen#3 main::$4 ] ( main:2 [ main::i#2 main::screen#3 main::$4 ] ) always clobbers reg byte a 
Statement [6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1 [ main::i#2 main::screen#3 main::$0 ] ( main:2 [ main::i#2 main::screen#3 main::$0 ] ) always clobbers reg byte a 
Statement [8] (byte~) main::$2 ← (byte) main::i#2 << (byte) 2 [ main::i#2 main::screen#3 main::$2 ] ( main:2 [ main::i#2 main::screen#3 main::$2 ] ) always clobbers reg byte a 
Statement [10] *((byte*) main::screen#3) ← (byte~) main::$5 [ main::i#2 main::screen#3 ] ( main:2 [ main::i#2 main::screen#3 ] ) always clobbers reg byte y 
Statement [11] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 [ main::i#2 main::screen#1 ] ( main:2 [ main::i#2 main::screen#1 ] ) always clobbers reg byte a 
Statement [12] (byte~) main::$6 ← (byte) main::i#2 & (byte) 1 [ main::i#2 main::screen#1 main::$6 ] ( main:2 [ main::i#2 main::screen#1 main::$6 ] ) always clobbers reg byte a 
Statement [14] (byte~) main::$8 ← (byte) main::i#2 << (byte) 2 [ main::i#2 main::screen#1 main::$8 ] ( main:2 [ main::i#2 main::screen#1 main::$8 ] ) always clobbers reg byte a 
Statement [16] *((byte*) main::screen#1) ← (byte~) main::$11 [ main::i#2 main::screen#1 ] ( main:2 [ main::i#2 main::screen#1 ] ) always clobbers reg byte y 
Statement [17] (byte*) main::screen#2 ← ++ (byte*) main::screen#1 [ main::i#2 main::screen#2 ] ( main:2 [ main::i#2 main::screen#2 ] ) always clobbers reg byte a 
Statement [21] (byte~) main::$10 ← (byte) main::i#2 + (byte) 3 [ main::i#2 main::screen#1 main::$10 ] ( main:2 [ main::i#2 main::screen#1 main::$10 ] ) always clobbers reg byte a 
Statement [22] (byte~) main::$4 ← (byte) main::i#2 + (byte) 3 [ main::i#2 main::screen#3 main::$4 ] ( main:2 [ main::i#2 main::screen#3 main::$4 ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , 
Potential registers zp[2]:3 [ main::screen#3 main::screen#2 ] : zp[2]:3 , 
Potential registers zp[1]:5 [ main::$5 main::$4 main::$2 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:6 [ main::$11 main::$10 main::$8 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:7 [ main::$0 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:8 [ main::screen#1 ] : zp[2]:8 , 
Potential registers zp[1]:10 [ main::$6 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 77: zp[1]:5 [ main::$5 main::$4 main::$2 ] 77: zp[1]:6 [ main::$11 main::$10 main::$8 ] 22.37: zp[1]:2 [ main::i#2 main::i#1 ] 22: zp[1]:7 [ main::$0 ] 22: zp[1]:10 [ main::$6 ] 12.05: zp[2]:3 [ main::screen#3 main::screen#2 ] 4.71: zp[2]:8 [ main::screen#1 ] 
Uplift Scope [] 

Uplifting [main] best 1443 combination reg byte a [ main::$5 main::$4 main::$2 ] reg byte a [ main::$11 main::$10 main::$8 ] reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$0 ] zp[1]:10 [ main::$6 ] zp[2]:3 [ main::screen#3 main::screen#2 ] zp[2]:8 [ main::screen#1 ] 
Limited combination testing to 100 combinations of 512 possible.
Uplifting [] best 1443 combination 
Attempting to uplift remaining variables inzp[1]:10 [ main::$6 ]
Uplifting [main] best 1403 combination reg byte a [ main::$6 ] 
Coalescing zero page register [ zp[2]:3 [ main::screen#3 main::screen#2 ] ] with [ zp[2]:8 [ main::screen#1 ] ] - score: 2
Allocated (was zp[2]:3) zp[2]:2 [ main::screen#3 main::screen#2 main::screen#1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests optimization of identical sub-expressions
  // 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 = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte*) main::screen#3 = (byte*) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [5] phi from main::@7 to main::@1 [phi:main::@7->main::@1]
  __b1_from___b7:
    // [5] phi (byte*) main::screen#3 = (byte*) main::screen#2 [phi:main::@7->main::@1#0] -- register_copy 
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@7->main::@1#1] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1 -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #1
    // [7] if((byte) 0!=(byte~) main::$0) goto main::@2 -- vbuc1_neq_vbuaa_then_la1 
    cmp #0
    bne __b2
    jmp __b3
    // main::@3
  __b3:
    // [8] (byte~) main::$2 ← (byte) main::i#2 << (byte) 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // [9] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
  __b4_from___b2:
  __b4_from___b3:
    // [9] phi (byte~) main::$5 = (byte~) main::$4 [phi:main::@2/main::@3->main::@4#0] -- register_copy 
    jmp __b4
    // main::@4
  __b4:
    // [10] *((byte*) main::screen#3) ← (byte~) main::$5 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // [11] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [12] (byte~) main::$6 ← (byte) main::i#2 & (byte) 1 -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #1
    // [13] if((byte) 0!=(byte~) main::$6) goto main::@5 -- vbuc1_neq_vbuaa_then_la1 
    cmp #0
    bne __b5
    jmp __b6
    // main::@6
  __b6:
    // [14] (byte~) main::$8 ← (byte) main::i#2 << (byte) 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // [15] phi from main::@5 main::@6 to main::@7 [phi:main::@5/main::@6->main::@7]
  __b7_from___b5:
  __b7_from___b6:
    // [15] phi (byte~) main::$11 = (byte~) main::$10 [phi:main::@5/main::@6->main::@7#0] -- register_copy 
    jmp __b7
    // main::@7
  __b7:
    // [16] *((byte*) main::screen#1) ← (byte~) main::$11 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // [17] (byte*) main::screen#2 ← ++ (byte*) main::screen#1 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [18] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [19] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne __b1_from___b7
    jmp __breturn
    // main::@return
  __breturn:
    // [20] return 
    rts
    // main::@5
  __b5:
    // [21] (byte~) main::$10 ← (byte) main::i#2 + (byte) 3 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #3
    jmp __b7_from___b5
    // main::@2
  __b2:
    // [22] (byte~) main::$4 ← (byte) main::i#2 + (byte) 3 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #3
    jmp __b4_from___b2
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __b4
Removing instruction jmp __b6
Removing instruction jmp __b7
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b7 with __b1
Replacing label __b7_from___b5 with __b7
Replacing label __b4_from___b2 with __b4
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b7:
Removing instruction __b4_from___b2:
Removing instruction __b4_from___b3:
Removing instruction __b7_from___b5:
Removing instruction __b7_from___b6:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b3:
Removing instruction __b6:
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
(void()) main()
(byte~) main::$0 reg byte a 22.0
(byte~) main::$10 reg byte a 22.0
(byte~) main::$11 reg byte a 33.0
(byte~) main::$2 reg byte a 22.0
(byte~) main::$4 reg byte a 22.0
(byte~) main::$5 reg byte a 33.0
(byte~) main::$6 reg byte a 22.0
(byte~) main::$8 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@7
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 5.866666666666666
(byte*) main::screen
(byte*) main::screen#1 screen zp[2]:2 4.714285714285714
(byte*) main::screen#2 screen zp[2]:2 7.333333333333333
(byte*) main::screen#3 screen zp[2]:2 4.714285714285714

reg byte x [ main::i#2 main::i#1 ]
zp[2]:2 [ main::screen#3 main::screen#2 main::screen#1 ]
reg byte a [ main::$5 main::$4 main::$2 ]
reg byte a [ main::$11 main::$10 main::$8 ]
reg byte a [ main::$0 ]
reg byte a [ main::$6 ]


FINAL ASSEMBLER
Score: 1071

  // File Comments
// Tests optimization of identical sub-expressions
  // 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 = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte*) main::screen#3 = (byte*) 1024 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi from main::@7 to main::@1 [phi:main::@7->main::@1]
    // [5] phi (byte*) main::screen#3 = (byte*) main::screen#2 [phi:main::@7->main::@1#0] -- register_copy 
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@7->main::@1#1] -- register_copy 
    // main::@1
  __b1:
    // i&1
    // [6] (byte~) main::$0 ← (byte) main::i#2 & (byte) 1 -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #1
    // (i&1)?i+3:i*4
    // [7] if((byte) 0!=(byte~) main::$0) goto main::@2 -- vbuc1_neq_vbuaa_then_la1 
    cmp #0
    bne __b2
    // main::@3
    // [8] (byte~) main::$2 ← (byte) main::i#2 << (byte) 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // [9] phi from main::@2 main::@3 to main::@4 [phi:main::@2/main::@3->main::@4]
    // [9] phi (byte~) main::$5 = (byte~) main::$4 [phi:main::@2/main::@3->main::@4#0] -- register_copy 
    // main::@4
  __b4:
    // *screen++ = (i&1)?i+3:i*4
    // [10] *((byte*) main::screen#3) ← (byte~) main::$5 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // *screen++ = (i&1)?i+3:i*4;
    // [11] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // i&1
    // [12] (byte~) main::$6 ← (byte) main::i#2 & (byte) 1 -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #1
    // (i&1)?i+3:i*4
    // [13] if((byte) 0!=(byte~) main::$6) goto main::@5 -- vbuc1_neq_vbuaa_then_la1 
    cmp #0
    bne __b5
    // main::@6
    // [14] (byte~) main::$8 ← (byte) main::i#2 << (byte) 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // [15] phi from main::@5 main::@6 to main::@7 [phi:main::@5/main::@6->main::@7]
    // [15] phi (byte~) main::$11 = (byte~) main::$10 [phi:main::@5/main::@6->main::@7#0] -- register_copy 
    // main::@7
  __b7:
    // *screen++ = (i&1)?i+3:i*4
    // [16] *((byte*) main::screen#1) ← (byte~) main::$11 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // *screen++ = (i&1)?i+3:i*4;
    // [17] (byte*) main::screen#2 ← ++ (byte*) main::screen#1 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // for( byte i: 0..2)
    // [18] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [19] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne __b1
    // main::@return
    // }
    // [20] return 
    rts
    // main::@5
  __b5:
    // (i&1)?i+3:i*4
    // [21] (byte~) main::$10 ← (byte) main::i#2 + (byte) 3 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #3
    jmp __b7
    // main::@2
  __b2:
    // [22] (byte~) main::$4 ← (byte) main::i#2 + (byte) 3 -- vbuaa=vbuxx_plus_vbuc1 
    txa
    clc
    adc #3
    jmp __b4
}
  // File Data

