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
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
Inlining cast (byte*) main::screen#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
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()
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 zero page equivalence class [ main::$0 ]
Added variable main::screen#1 to zero page equivalence class [ main::screen#1 ]
Added variable main::$6 to zero page 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 ZP_BYTE:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_WORD:3 [ main::screen#3 main::screen#2 ]
Allocated zp ZP_BYTE:5 [ main::$5 main::$4 main::$2 ]
Allocated zp ZP_BYTE:6 [ main::$11 main::$10 main::$8 ]
Allocated zp ZP_BYTE:7 [ main::$0 ]
Allocated zp ZP_WORD:8 [ main::screen#1 ]
Allocated zp ZP_BYTE:10 [ main::$6 ]

INITIAL ASM
  // File Comments
// Tests optimization of identical sub-expressions
  // Basic 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_2 = 3
    .label i = 2
    .label screen_3 = 3
    // [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 screen_3
    lda #>$400
    sta screen_3+1
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#1] -- vbuz1=vbuc1 
    lda #0
    sta 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 i
    sta _0
    // [7] if((byte) 0!=(byte~) main::$0) goto main::@2 -- vbuc1_neq_vbuz1_then_la1 
    lda #0
    cmp _0
    bne b2
    jmp b3
    // main::@3
  b3:
    // [8] (byte~) main::$2 ← (byte) main::i#2 << (byte) 2 -- vbuz1=vbuz2_rol_2 
    lda i
    asl
    asl
    sta _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 _5
    ldy #0
    sta (screen_3),y
    // [11] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 -- pbuz1=_inc_pbuz2 
    lda screen_3
    clc
    adc #1
    sta screen
    lda screen_3+1
    adc #0
    sta screen+1
    // [12] (byte~) main::$6 ← (byte) main::i#2 & (byte) 1 -- vbuz1=vbuz2_band_vbuc1 
    lda #1
    and i
    sta _6
    // [13] if((byte) 0!=(byte~) main::$6) goto main::@5 -- vbuc1_neq_vbuz1_then_la1 
    lda #0
    cmp _6
    bne b5
    jmp b6
    // main::@6
  b6:
    // [14] (byte~) main::$8 ← (byte) main::i#2 << (byte) 2 -- vbuz1=vbuz2_rol_2 
    lda i
    asl
    asl
    sta _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 _11
    ldy #0
    sta (screen),y
    // [17] (byte*) main::screen#2 ← ++ (byte*) main::screen#1 -- pbuz1=_inc_pbuz2 
    lda screen
    clc
    adc #1
    sta screen_2
    lda screen+1
    adc #0
    sta screen_2+1
    // [18] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc i
    // [19] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp 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 i
    axs #-[3]
    stx _10
    jmp b7_from_b5
    // main::@2
  b2:
    // [22] (byte~) main::$4 ← (byte) main::i#2 + (byte) 3 -- vbuz1=vbuz2_plus_vbuc1 
    lax i
    axs #-[3]
    stx _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 ZP_BYTE: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 ZP_BYTE: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 ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , 
Potential registers zp ZP_WORD:3 [ main::screen#3 main::screen#2 ] : zp ZP_WORD:3 , 
Potential registers zp ZP_BYTE:5 [ main::$5 main::$4 main::$2 ] : zp ZP_BYTE:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:6 [ main::$11 main::$10 main::$8 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:7 [ main::$0 ] : zp ZP_BYTE:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_WORD:8 [ main::screen#1 ] : zp ZP_WORD:8 , 
Potential registers zp ZP_BYTE:10 [ main::$6 ] : zp ZP_BYTE:10 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 77: zp ZP_BYTE:5 [ main::$5 main::$4 main::$2 ] 77: zp ZP_BYTE:6 [ main::$11 main::$10 main::$8 ] 22.37: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 22: zp ZP_BYTE:7 [ main::$0 ] 22: zp ZP_BYTE:10 [ main::$6 ] 12.05: zp ZP_WORD:3 [ main::screen#3 main::screen#2 ] 4.71: zp ZP_WORD: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 ZP_BYTE:10 [ main::$6 ] zp ZP_WORD:3 [ main::screen#3 main::screen#2 ] zp ZP_WORD:8 [ main::screen#1 ] 
Limited combination testing to 100 combinations of 512 possible.
Uplifting [] best 1443 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:10 [ main::$6 ]
Uplifting [main] best 1403 combination reg byte a [ main::$6 ] 
Coalescing zero page register with common assignment [ zp ZP_WORD:3 [ main::screen#3 main::screen#2 ] ] with [ zp ZP_WORD:8 [ main::screen#1 ] ] - score: 2
Allocated (was zp ZP_WORD:3) zp ZP_WORD:2 [ main::screen#3 main::screen#2 main::screen#1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests optimization of identical sub-expressions
  // Basic 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 screen
    lda #>$400
    sta 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 screen
    bne !+
    inc 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 screen
    bne !+
    inc 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 b1_from_b7 with b1
Replacing label b7_from_b5 with b7
Replacing label b4_from_b2 with b4
Removing instruction b1_from_bbegin:
Removing instruction b1:
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 bbegin:
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 ZP_WORD:2 4.714285714285714
(byte*) main::screen#2 screen zp ZP_WORD:2 7.333333333333333
(byte*) main::screen#3 screen zp ZP_WORD:2 4.714285714285714

reg byte x [ main::i#2 main::i#1 ]
zp ZP_WORD: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
  // Basic 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 screen
    lda #>$400
    sta 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 screen
    bne !+
    inc 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 screen
    bne !+
    inc 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

