Culled Empty Block (label) @1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte) cnt#0 ← (byte) 0
  to:@2

(void()) main()
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
  *((const byte*) SCREEN + (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
  *((const byte*) SCREEN + (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

(void()) inccnt()
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
(const byte*) SCREEN[(number) $100]  = (byte*)(number) $400
(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 *((const byte*) SCREEN + (number) 0) ← (byte) cnt#1
Adding number conversion cast (unumber) 1 in *((const byte*) SCREEN + (number) 1) ← (byte) cnt#4
Successful SSA optimization PassNAddNumberTypeConversions
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) 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
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero SCREEN in [5] *((const byte*) SCREEN + (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+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()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  [5] call inccnt 
  to:main::@1
main::@1: scope:[main]  from main
  [6] *((const byte*) SCREEN) ← (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*) SCREEN+(byte) 1) ← (byte) cnt#11
  to:main::@return
main::@return: scope:[main]  from main::@2
  [11] return 
  to:@return

(void()) inccnt()
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) 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 live range equivalence class [ cnt#11 ]
Added variable cnt#13 to live range equivalence class [ cnt#13 ]
Complete equivalence classes
[ cnt#12 cnt#2 ]
[ cnt#11 ]
[ cnt#13 ]
Allocated zp[1]:2 [ cnt#12 cnt#2 ]
Allocated zp[1]:3 [ cnt#11 ]
Allocated zp[1]:4 [ cnt#13 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label cnt = 2
  .label cnt_1 = 3
  .label cnt_2 = 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*) SCREEN) ← (byte) cnt#13 -- _deref_pbuc1=vbuz1 
    lda.z cnt_2
    sta SCREEN
    // [7] (byte) cnt#2 ← ++ (byte) cnt#13 -- vbuz1=_inc_vbuz2 
    ldy.z cnt_2
    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_2
    iny
    sty.z cnt_1
    // [10] *((const byte*) SCREEN+(byte) 1) ← (byte) cnt#11 -- _deref_pbuc1=vbuz1 
    lda.z cnt_1
    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_2
    jmp __breturn
    // inccnt::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

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

REGISTER UPLIFT SCOPES
Uplift Scope [] 8: zp[1]:2 [ cnt#12 cnt#2 ] 4: zp[1]:3 [ cnt#11 ] 1.6: zp[1]: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*) SCREEN) ← (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*) SCREEN+(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
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
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 __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN[(number) $100]  = (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*) SCREEN) ← (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*) SCREEN+(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

