Culled Empty Block (label) main::@2

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::@1
  (byte*) main::screen#3 ← phi( main/(byte*) main::screen#0 main::@1/(byte*) main::screen#2 )
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
  (number~) main::$0 ← (byte) main::i#2 * (number) 2
  (number~) main::$1 ← (number~) main::$0 + (byte) main::i#2
  (number~) main::$2 ← (number~) main::$1 + (number) 3
  *((byte*) main::screen#3) ← (number~) main::$2
  (byte*) main::screen#1 ← ++ (byte*) main::screen#3
  (number~) main::$3 ← (byte) main::i#2 * (number) 2
  (number~) main::$4 ← (number~) main::$3 + (byte) main::i#2
  (number~) main::$5 ← (number~) main::$4 + (number) 3
  *((byte*) main::screen#1) ← (number~) main::$5
  (byte*) main::screen#2 ← ++ (byte*) main::screen#1
  (byte) main::i#1 ← (byte) main::i#2 + rangenext(0,2)
  (bool~) main::$6 ← (byte) main::i#1 != rangelast(0,2)
  if((bool~) main::$6) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  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::$2
(number~) main::$3
(number~) main::$4
(number~) main::$5
(bool~) main::$6
(label) main::@1
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte*) main::screen
(byte*) main::screen#0
(byte*) main::screen#1
(byte*) main::screen#2
(byte*) main::screen#3

Adding number conversion cast (unumber) 2 in (number~) main::$0 ← (byte) main::i#2 * (number) 2
Adding number conversion cast (unumber) main::$0 in (number~) main::$0 ← (byte) main::i#2 * (unumber)(number) 2
Adding number conversion cast (unumber) main::$1 in (number~) main::$1 ← (unumber~) main::$0 + (byte) main::i#2
Adding number conversion cast (unumber) 3 in (number~) main::$2 ← (unumber~) main::$1 + (number) 3
Adding number conversion cast (unumber) main::$2 in (number~) main::$2 ← (unumber~) main::$1 + (unumber)(number) 3
Adding number conversion cast (unumber) 2 in (number~) main::$3 ← (byte) main::i#2 * (number) 2
Adding number conversion cast (unumber) main::$3 in (number~) main::$3 ← (byte) main::i#2 * (unumber)(number) 2
Adding number conversion cast (unumber) main::$4 in (number~) main::$4 ← (unumber~) main::$3 + (byte) main::i#2
Adding number conversion cast (unumber) 3 in (number~) main::$5 ← (unumber~) main::$4 + (number) 3
Adding number conversion cast (unumber) main::$5 in (number~) main::$5 ← (unumber~) main::$4 + (unumber)(number) 3
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 2
Simplifying constant integer cast 3
Simplifying constant integer cast 2
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 3
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$0 ← (byte) main::i#2 * (byte) 2
Inferred type updated to byte in (unumber~) main::$1 ← (byte~) main::$0 + (byte) main::i#2
Inferred type updated to byte in (unumber~) main::$2 ← (byte~) main::$1 + (byte) 3
Inferred type updated to byte in (unumber~) main::$3 ← (byte) main::i#2 * (byte) 2
Inferred type updated to byte in (unumber~) main::$4 ← (byte~) main::$3 + (byte) main::i#2
Inferred type updated to byte in (unumber~) main::$5 ← (byte~) main::$4 + (byte) 3
Identified duplicate assignment right side [8] (byte~) main::$3 ← (byte) main::i#2 * (byte) 2
Successful SSA optimization Pass2DuplicateRValueIdentification
Simple Condition (bool~) main::$6 [15] 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 [13] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [15] 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
Alias (byte~) main::$3 = (byte~) main::$0 
Successful SSA optimization Pass2AliasElimination
Rewriting multiplication to use shift [1] (byte~) main::$3 ← (byte) main::i#2 * (byte) 2
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::@3(between main::@1 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 2 initial phi equivalence classes
Coalesced [19] main::i#3 ← main::i#1
Coalesced [20] main::screen#4 ← main::screen#2
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) 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

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::@1
  [5] (byte*) main::screen#3 ← phi( main/(byte*) 1024 main::@1/(byte*) main::screen#2 )
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@1/(byte) main::i#1 )
  [6] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1
  [7] (byte~) main::$1 ← (byte~) main::$3 + (byte) main::i#2
  [8] (byte~) main::$2 ← (byte~) main::$1 + (byte) 3
  [9] *((byte*) main::screen#3) ← (byte~) main::$2
  [10] (byte*) main::screen#1 ← ++ (byte*) main::screen#3
  [11] (byte~) main::$4 ← (byte~) main::$3 + (byte) main::i#2
  [12] (byte~) main::$5 ← (byte~) main::$4 + (byte) 3
  [13] *((byte*) main::screen#1) ← (byte~) main::$5
  [14] (byte*) main::screen#2 ← ++ (byte*) main::screen#1
  [15] (byte) main::i#1 ← ++ (byte) main::i#2
  [16] if((byte) main::i#1!=(byte) 3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [17] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$1 22.0
(byte~) main::$2 22.0
(byte~) main::$3 6.6000000000000005
(byte~) main::$4 22.0
(byte~) main::$5 22.0
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 5.5
(byte*) main::screen
(byte*) main::screen#1 8.25
(byte*) main::screen#2 7.333333333333333
(byte*) main::screen#3 6.6000000000000005

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::screen#3 main::screen#2 ]
Added variable main::$3 to zero page equivalence class [ main::$3 ]
Added variable main::$1 to zero page equivalence class [ main::$1 ]
Added variable main::$2 to zero page equivalence class [ main::$2 ]
Added variable main::screen#1 to zero page equivalence class [ main::screen#1 ]
Added variable main::$4 to zero page equivalence class [ main::$4 ]
Added variable main::$5 to zero page equivalence class [ main::$5 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::screen#3 main::screen#2 ]
[ main::$3 ]
[ main::$1 ]
[ main::$2 ]
[ main::screen#1 ]
[ main::$4 ]
[ main::$5 ]
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::$3 ]
Allocated zp ZP_BYTE:6 [ main::$1 ]
Allocated zp ZP_BYTE:7 [ main::$2 ]
Allocated zp ZP_WORD:8 [ main::screen#1 ]
Allocated zp ZP_BYTE:10 [ main::$4 ]
Allocated zp ZP_BYTE:11 [ main::$5 ]

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 _1 = 6
    .label _2 = 7
    .label _3 = 5
    .label _4 = $a
    .label _5 = $b
    .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::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (byte*) main::screen#3 = (byte*) main::screen#2 [phi:main::@1->main::@1#0] -- register_copy 
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda i
    asl
    sta _3
    // [7] (byte~) main::$1 ← (byte~) main::$3 + (byte) main::i#2 -- vbuz1=vbuz2_plus_vbuz3 
    lda _3
    clc
    adc i
    sta _1
    // [8] (byte~) main::$2 ← (byte~) main::$1 + (byte) 3 -- vbuz1=vbuz2_plus_vbuc1 
    lax _1
    axs #-[3]
    stx _2
    // [9] *((byte*) main::screen#3) ← (byte~) main::$2 -- _deref_pbuz1=vbuz2 
    lda _2
    ldy #0
    sta (screen_3),y
    // [10] (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
    // [11] (byte~) main::$4 ← (byte~) main::$3 + (byte) main::i#2 -- vbuz1=vbuz2_plus_vbuz3 
    lda _3
    clc
    adc i
    sta _4
    // [12] (byte~) main::$5 ← (byte~) main::$4 + (byte) 3 -- vbuz1=vbuz2_plus_vbuc1 
    lax _4
    axs #-[3]
    stx _5
    // [13] *((byte*) main::screen#1) ← (byte~) main::$5 -- _deref_pbuz1=vbuz2 
    lda _5
    ldy #0
    sta (screen),y
    // [14] (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
    // [15] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc i
    // [16] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp i
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [17] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::screen#3 main::$3 ] ( main:2 [ main::i#2 main::screen#3 main::$3 ] ) 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 [7] (byte~) main::$1 ← (byte~) main::$3 + (byte) main::i#2 [ main::i#2 main::screen#3 main::$3 main::$1 ] ( main:2 [ main::i#2 main::screen#3 main::$3 main::$1 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:5 [ main::$3 ]
Statement [9] *((byte*) main::screen#3) ← (byte~) main::$2 [ main::i#2 main::screen#3 main::$3 ] ( main:2 [ main::i#2 main::screen#3 main::$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 ]
Removing always clobbered register reg byte y as potential for zp ZP_BYTE:5 [ main::$3 ]
Statement [10] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 [ main::i#2 main::$3 main::screen#1 ] ( main:2 [ main::i#2 main::$3 main::screen#1 ] ) always clobbers reg byte a 
Statement [11] (byte~) main::$4 ← (byte~) main::$3 + (byte) main::i#2 [ main::i#2 main::screen#1 main::$4 ] ( main:2 [ main::i#2 main::screen#1 main::$4 ] ) always clobbers reg byte a 
Statement [13] *((byte*) main::screen#1) ← (byte~) main::$5 [ main::i#2 main::screen#1 ] ( main:2 [ main::i#2 main::screen#1 ] ) always clobbers reg byte y 
Statement [14] (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 [6] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::screen#3 main::$3 ] ( main:2 [ main::i#2 main::screen#3 main::$3 ] ) always clobbers reg byte a 
Statement [7] (byte~) main::$1 ← (byte~) main::$3 + (byte) main::i#2 [ main::i#2 main::screen#3 main::$3 main::$1 ] ( main:2 [ main::i#2 main::screen#3 main::$3 main::$1 ] ) always clobbers reg byte a 
Statement [9] *((byte*) main::screen#3) ← (byte~) main::$2 [ main::i#2 main::screen#3 main::$3 ] ( main:2 [ main::i#2 main::screen#3 main::$3 ] ) always clobbers reg byte y 
Statement [10] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 [ main::i#2 main::$3 main::screen#1 ] ( main:2 [ main::i#2 main::$3 main::screen#1 ] ) always clobbers reg byte a 
Statement [11] (byte~) main::$4 ← (byte~) main::$3 + (byte) main::i#2 [ main::i#2 main::screen#1 main::$4 ] ( main:2 [ main::i#2 main::screen#1 main::$4 ] ) always clobbers reg byte a 
Statement [13] *((byte*) main::screen#1) ← (byte~) main::$5 [ main::i#2 main::screen#1 ] ( main:2 [ main::i#2 main::screen#1 ] ) always clobbers reg byte y 
Statement [14] (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 
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::$3 ] : zp ZP_BYTE:5 , reg byte x , 
Potential registers zp ZP_BYTE:6 [ main::$1 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:7 [ main::$2 ] : 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::$4 ] : zp ZP_BYTE:10 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:11 [ main::$5 ] : zp ZP_BYTE:11 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 22: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 22: zp ZP_BYTE:6 [ main::$1 ] 22: zp ZP_BYTE:7 [ main::$2 ] 22: zp ZP_BYTE:10 [ main::$4 ] 22: zp ZP_BYTE:11 [ main::$5 ] 13.93: zp ZP_WORD:3 [ main::screen#3 main::screen#2 ] 8.25: zp ZP_WORD:8 [ main::screen#1 ] 6.6: zp ZP_BYTE:5 [ main::$3 ] 
Uplift Scope [] 

Uplifting [main] best 1163 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$1 ] reg byte a [ main::$2 ] reg byte a [ main::$4 ] zp ZP_BYTE:11 [ main::$5 ] zp ZP_WORD:3 [ main::screen#3 main::screen#2 ] zp ZP_WORD:8 [ main::screen#1 ] zp ZP_BYTE:5 [ main::$3 ] 
Limited combination testing to 100 combinations of 1024 possible.
Uplifting [] best 1163 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:11 [ main::$5 ]
Uplifting [main] best 1103 combination reg byte a [ main::$5 ] 
Attempting to uplift remaining variables inzp ZP_BYTE:5 [ main::$3 ]
Uplifting [main] best 1103 combination zp ZP_BYTE:5 [ main::$3 ] 
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 ]
Allocated (was zp ZP_BYTE:5) zp ZP_BYTE:4 [ main::$3 ]

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 _3 = 4
    .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::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (byte*) main::screen#3 = (byte*) main::screen#2 [phi:main::@1->main::@1#0] -- register_copy 
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuxx_rol_1 
    txa
    asl
    sta _3
    // [7] (byte~) main::$1 ← (byte~) main::$3 + (byte) main::i#2 -- vbuaa=vbuz1_plus_vbuxx 
    txa
    clc
    adc _3
    // [8] (byte~) main::$2 ← (byte~) main::$1 + (byte) 3 -- vbuaa=vbuaa_plus_vbuc1 
    clc
    adc #3
    // [9] *((byte*) main::screen#3) ← (byte~) main::$2 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // [10] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [11] (byte~) main::$4 ← (byte~) main::$3 + (byte) main::i#2 -- vbuaa=vbuz1_plus_vbuxx 
    txa
    clc
    adc _3
    // [12] (byte~) main::$5 ← (byte~) main::$4 + (byte) 3 -- vbuaa=vbuaa_plus_vbuc1 
    clc
    adc #3
    // [13] *((byte*) main::screen#1) ← (byte~) main::$5 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // [14] (byte*) main::screen#2 ← ++ (byte*) main::screen#1 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [15] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [16] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [17] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
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::$1 reg byte a 22.0
(byte~) main::$2 reg byte a 22.0
(byte~) main::$3 $3 zp ZP_BYTE:4 6.6000000000000005
(byte~) main::$4 reg byte a 22.0
(byte~) main::$5 reg byte a 22.0
(label) main::@1
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 5.5
(byte*) main::screen
(byte*) main::screen#1 screen zp ZP_WORD:2 8.25
(byte*) main::screen#2 screen zp ZP_WORD:2 7.333333333333333
(byte*) main::screen#3 screen zp ZP_WORD:2 6.6000000000000005

reg byte x [ main::i#2 main::i#1 ]
zp ZP_WORD:2 [ main::screen#3 main::screen#2 main::screen#1 ]
zp ZP_BYTE:4 [ main::$3 ]
reg byte a [ main::$1 ]
reg byte a [ main::$2 ]
reg byte a [ main::$4 ]
reg byte a [ main::$5 ]


FINAL ASSEMBLER
Score: 891

  // 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 _3 = 4
    .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::@1 to main::@1 [phi:main::@1->main::@1]
    // [5] phi (byte*) main::screen#3 = (byte*) main::screen#2 [phi:main::@1->main::@1#0] -- register_copy 
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#1] -- register_copy 
    // main::@1
  b1:
    // i*2
    // [6] (byte~) main::$3 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuxx_rol_1 
    txa
    asl
    sta _3
    // i*2+i
    // [7] (byte~) main::$1 ← (byte~) main::$3 + (byte) main::i#2 -- vbuaa=vbuz1_plus_vbuxx 
    txa
    clc
    adc _3
    // i*2+i+3
    // [8] (byte~) main::$2 ← (byte~) main::$1 + (byte) 3 -- vbuaa=vbuaa_plus_vbuc1 
    clc
    adc #3
    // *screen++ = i*2+i+3
    // [9] *((byte*) main::screen#3) ← (byte~) main::$2 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // *screen++ = i*2+i+3;
    // [10] (byte*) main::screen#1 ← ++ (byte*) main::screen#3 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // i*2+i
    // [11] (byte~) main::$4 ← (byte~) main::$3 + (byte) main::i#2 -- vbuaa=vbuz1_plus_vbuxx 
    txa
    clc
    adc _3
    // i*2+i+3
    // [12] (byte~) main::$5 ← (byte~) main::$4 + (byte) 3 -- vbuaa=vbuaa_plus_vbuc1 
    clc
    adc #3
    // *screen++ = i*2+i+3
    // [13] *((byte*) main::screen#1) ← (byte~) main::$5 -- _deref_pbuz1=vbuaa 
    ldy #0
    sta (screen),y
    // *screen++ = i*2+i+3;
    // [14] (byte*) main::screen#2 ← ++ (byte*) main::screen#1 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // for( byte i: 0..2)
    // [15] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [16] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne b1
    // main::@return
    // }
    // [17] return 
    rts
}
  // File Data

