Culled Empty Block (label) @1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte) cnt#0 ← (number) 0
  (byte[$100]) SCREEN#0 ← ((byte[$100])) (number) $400
  to:@2
main: scope:[main]  from @2
  (byte) cnt#15 ← phi( @2/(byte) cnt#16 )
  call inccnt 
  to:main::@1
main::@1: scope:[main]  from main
  (byte) cnt#9 ← phi( main/(byte) cnt#7 )
  (byte) cnt#1 ← (byte) cnt#9
  *((byte[$100]) SCREEN#0 + (number) 0) ← (byte) cnt#1
  (byte) cnt#2 ← ++ (byte) cnt#1
  call inccnt 
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte) cnt#10 ← phi( main::@1/(byte) cnt#7 )
  (byte) cnt#3 ← (byte) cnt#10
  (byte) cnt#4 ← ++ (byte) cnt#3
  *((byte[$100]) SCREEN#0 + (number) 1) ← (byte) cnt#4
  to:main::@return
main::@return: scope:[main]  from main::@2
  (byte) cnt#11 ← phi( main::@2/(byte) cnt#4 )
  (byte) cnt#5 ← (byte) cnt#11
  return 
  to:@return
inccnt: scope:[inccnt]  from main main::@1
  (byte) cnt#12 ← phi( main/(byte) cnt#15 main::@1/(byte) cnt#2 )
  (byte) cnt#6 ← ++ (byte) cnt#12
  to:inccnt::@return
inccnt::@return: scope:[inccnt]  from inccnt
  (byte) cnt#13 ← phi( inccnt/(byte) cnt#6 )
  (byte) cnt#7 ← (byte) cnt#13
  return 
  to:@return
@2: scope:[]  from @begin
  (byte) cnt#16 ← phi( @begin/(byte) cnt#0 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) cnt#14 ← phi( @2/(byte) cnt#5 )
  (byte) cnt#8 ← (byte) cnt#14
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(byte[$100]) SCREEN
(byte[$100]) SCREEN#0
(byte) cnt
(byte) cnt#0
(byte) cnt#1
(byte) cnt#10
(byte) cnt#11
(byte) cnt#12
(byte) cnt#13
(byte) cnt#14
(byte) cnt#15
(byte) cnt#16
(byte) cnt#2
(byte) cnt#3
(byte) cnt#4
(byte) cnt#5
(byte) cnt#6
(byte) cnt#7
(byte) cnt#8
(byte) cnt#9
(void()) inccnt()
(label) inccnt::@return
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return

Adding number conversion cast (unumber) 0 in (byte) cnt#0 ← (number) 0
Adding number conversion cast (unumber) 0 in *((byte[$100]) SCREEN#0 + (number) 0) ← (byte) cnt#1
Adding number conversion cast (unumber) 1 in *((byte[$100]) SCREEN#0 + (number) 1) ← (byte) cnt#4
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte) cnt#0 ← (unumber)(number) 0
Inlining cast (byte[$100]) SCREEN#0 ← (byte[$100])(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant integer cast 0
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) cnt#1 = (byte) cnt#9 
Alias (byte) cnt#10 = (byte) cnt#3 
Alias (byte) cnt#11 = (byte) cnt#4 (byte) cnt#5 
Alias (byte) cnt#13 = (byte) cnt#6 (byte) cnt#7 
Alias (byte) cnt#0 = (byte) cnt#16 
Alias (byte) cnt#14 = (byte) cnt#8 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) cnt#15 (byte) cnt#0
Identical Phi Values (byte) cnt#1 (byte) cnt#13
Identical Phi Values (byte) cnt#10 (byte) cnt#13
Identical Phi Values (byte) cnt#14 (byte) cnt#11
Successful SSA optimization Pass2IdenticalPhiElimination
Constant (const byte) cnt#0 = 0
Constant (const byte[$100]) SCREEN#0 = (byte*) 1024
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero SCREEN#0 in [6] *((const byte[$100]) SCREEN#0 + (byte) 0) ← (byte) cnt#13
Successful SSA optimization PassNSimplifyExpressionWithZero
Inlining constant with var siblings (const byte) cnt#0
Constant inlined cnt#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN#0+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to inccnt:6 inccnt:10 

Created 1 initial phi equivalence classes
Coalesced [9] cnt#17 ← cnt#2
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @3
Renumbering block @2 to @1
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()
  [5] call inccnt 
  to:main::@1
main::@1: scope:[main]  from main
  [6] *((const byte[$100]) SCREEN#0) ← (byte) cnt#13
  [7] (byte) cnt#2 ← ++ (byte) cnt#13
  [8] call inccnt 
  to:main::@2
main::@2: scope:[main]  from main::@1
  [9] (byte) cnt#11 ← ++ (byte) cnt#13
  [10] *((const byte[$100]) SCREEN#0+(byte) 1) ← (byte) cnt#11
  to:main::@return
main::@return: scope:[main]  from main::@2
  [11] return 
  to:@return
inccnt: scope:[inccnt]  from main main::@1
  [12] (byte) cnt#12 ← phi( main/(byte) 0 main::@1/(byte) cnt#2 )
  [13] (byte) cnt#13 ← ++ (byte) cnt#12
  to:inccnt::@return
inccnt::@return: scope:[inccnt]  from inccnt
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte[$100]) SCREEN
(byte) cnt
(byte) cnt#11 4.0
(byte) cnt#12 4.0
(byte) cnt#13 1.6
(byte) cnt#2 4.0
(void()) inccnt()
(void()) main()

Initial phi equivalence classes
[ cnt#12 cnt#2 ]
Added variable cnt#11 to zero page equivalence class [ cnt#11 ]
Added variable cnt#13 to zero page equivalence class [ cnt#13 ]
Complete equivalence classes
[ cnt#12 cnt#2 ]
[ cnt#11 ]
[ cnt#13 ]
Allocated zp ZP_BYTE:2 [ cnt#12 cnt#2 ]
Allocated zp ZP_BYTE:3 [ cnt#11 ]
Allocated zp ZP_BYTE:4 [ cnt#13 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label cnt = 2
  .label cnt_11 = 3
  .label cnt_13 = 4
  // @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: {
    // [5] call inccnt 
    // [12] phi from main to inccnt [phi:main->inccnt]
  inccnt_from_main:
    // [12] phi (byte) cnt#12 = (byte) 0 [phi:main->inccnt#0] -- vbuz1=vbuc1 
    lda #0
    sta.z cnt
    jsr inccnt
    jmp b1
    // main::@1
  b1:
    // [6] *((const byte[$100]) SCREEN#0) ← (byte) cnt#13 -- _deref_pbuc1=vbuz1 
    lda.z cnt_13
    sta SCREEN
    // [7] (byte) cnt#2 ← ++ (byte) cnt#13 -- vbuz1=_inc_vbuz2 
    ldy.z cnt_13
    iny
    sty.z cnt
    // [8] call inccnt 
    // [12] phi from main::@1 to inccnt [phi:main::@1->inccnt]
  inccnt_from_b1:
    // [12] phi (byte) cnt#12 = (byte) cnt#2 [phi:main::@1->inccnt#0] -- register_copy 
    jsr inccnt
    jmp b2
    // main::@2
  b2:
    // [9] (byte) cnt#11 ← ++ (byte) cnt#13 -- vbuz1=_inc_vbuz2 
    ldy.z cnt_13
    iny
    sty.z cnt_11
    // [10] *((const byte[$100]) SCREEN#0+(byte) 1) ← (byte) cnt#11 -- _deref_pbuc1=vbuz1 
    lda.z cnt_11
    sta SCREEN+1
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // inccnt
inccnt: {
    // [13] (byte) cnt#13 ← ++ (byte) cnt#12 -- vbuz1=_inc_vbuz2 
    ldy.z cnt
    iny
    sty.z cnt_13
    jmp breturn
    // inccnt::@return
  breturn:
    // [14] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp ZP_BYTE:2 [ cnt#12 cnt#2 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ cnt#11 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ cnt#13 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 8: zp ZP_BYTE:2 [ cnt#12 cnt#2 ] 4: zp ZP_BYTE:3 [ cnt#11 ] 1.6: zp ZP_BYTE:4 [ cnt#13 ] 
Uplift Scope [main] 
Uplift Scope [inccnt] 

Uplifting [] best 64 combination reg byte x [ cnt#12 cnt#2 ] reg byte x [ cnt#11 ] reg byte x [ cnt#13 ] 
Uplifting [main] best 64 combination 
Uplifting [inccnt] best 64 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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: {
    // [5] call inccnt 
    // [12] phi from main to inccnt [phi:main->inccnt]
  inccnt_from_main:
    // [12] phi (byte) cnt#12 = (byte) 0 [phi:main->inccnt#0] -- vbuxx=vbuc1 
    ldx #0
    jsr inccnt
    jmp b1
    // main::@1
  b1:
    // [6] *((const byte[$100]) SCREEN#0) ← (byte) cnt#13 -- _deref_pbuc1=vbuxx 
    stx SCREEN
    // [7] (byte) cnt#2 ← ++ (byte) cnt#13 -- vbuxx=_inc_vbuxx 
    inx
    // [8] call inccnt 
    // [12] phi from main::@1 to inccnt [phi:main::@1->inccnt]
  inccnt_from_b1:
    // [12] phi (byte) cnt#12 = (byte) cnt#2 [phi:main::@1->inccnt#0] -- register_copy 
    jsr inccnt
    jmp b2
    // main::@2
  b2:
    // [9] (byte) cnt#11 ← ++ (byte) cnt#13 -- vbuxx=_inc_vbuxx 
    inx
    // [10] *((const byte[$100]) SCREEN#0+(byte) 1) ← (byte) cnt#11 -- _deref_pbuc1=vbuxx 
    stx SCREEN+1
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // inccnt
inccnt: {
    // [13] (byte) cnt#13 ← ++ (byte) cnt#12 -- vbuxx=_inc_vbuxx 
    inx
    jmp breturn
    // inccnt::@return
  breturn:
    // [14] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction inccnt_from_main:
Removing instruction b1:
Removing instruction inccnt_from_b1:
Removing instruction b2:
Removing instruction breturn:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte[$100]) SCREEN
(const byte[$100]) SCREEN#0 SCREEN = (byte*) 1024
(byte) cnt
(byte) cnt#11 reg byte x 4.0
(byte) cnt#12 reg byte x 4.0
(byte) cnt#13 reg byte x 1.6
(byte) cnt#2 reg byte x 4.0
(void()) inccnt()
(label) inccnt::@return
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return

reg byte x [ cnt#12 cnt#2 ]
reg byte x [ cnt#11 ]
reg byte x [ cnt#13 ]


FINAL ASSEMBLER
Score: 40

  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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: {
    // inccnt()
    // [5] call inccnt 
    // [12] phi from main to inccnt [phi:main->inccnt]
    // [12] phi (byte) cnt#12 = (byte) 0 [phi:main->inccnt#0] -- vbuxx=vbuc1 
    ldx #0
    jsr inccnt
    // main::@1
    // SCREEN[0]=cnt++
    // [6] *((const byte[$100]) SCREEN#0) ← (byte) cnt#13 -- _deref_pbuc1=vbuxx 
    stx SCREEN
    // SCREEN[0]=cnt++;
    // [7] (byte) cnt#2 ← ++ (byte) cnt#13 -- vbuxx=_inc_vbuxx 
    inx
    // inccnt()
    // [8] call inccnt 
    // [12] phi from main::@1 to inccnt [phi:main::@1->inccnt]
    // [12] phi (byte) cnt#12 = (byte) cnt#2 [phi:main::@1->inccnt#0] -- register_copy 
    jsr inccnt
    // main::@2
    // SCREEN[1]=++cnt;
    // [9] (byte) cnt#11 ← ++ (byte) cnt#13 -- vbuxx=_inc_vbuxx 
    inx
    // SCREEN[1]=++cnt
    // [10] *((const byte[$100]) SCREEN#0+(byte) 1) ← (byte) cnt#11 -- _deref_pbuc1=vbuxx 
    stx SCREEN+1
    // main::@return
    // }
    // [11] return 
    rts
}
  // inccnt
inccnt: {
    // ++cnt;
    // [13] (byte) cnt#13 ← ++ (byte) cnt#12 -- vbuxx=_inc_vbuxx 
    inx
    // inccnt::@return
    // }
    // [14] return 
    rts
}
  // File Data

