
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte) cnt#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
  (byte[256]) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  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[256]) SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) 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[256]) SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) 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[256]) SCREEN
(byte[256]) 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

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
Redundant Phi (byte) cnt#15 (byte) cnt#0
Redundant Phi (byte) cnt#1 (byte) cnt#13
Redundant Phi (byte) cnt#10 (byte) cnt#13
Redundant Phi (byte) cnt#14 (byte) cnt#11
Successful SSA optimization Pass2RedundantPhiElimination
Constant (const byte) cnt#0 = 0
Constant (const byte[256]) SCREEN#0 = ((byte*))1024
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(SCREEN#0+0)
Consolidated array index constant in *(SCREEN#0+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Culled Empty Block (label) @3
Successful SSA optimization Pass2CullEmptyBlocks
Inlining constant with var siblings (const byte) cnt#0
Constant inlined cnt#0 = (byte/signed byte/word/signed word/dword/signed dword) 0
Successful SSA optimization Pass2ConstantInlining
Simplifying constant plus zero SCREEN#0+0
Adding NOP phi() at start of @begin
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 
Calls in [main] to inccnt:5 inccnt:9 

Created 1 initial phi equivalence classes
Coalesced [8] cnt#17 ← cnt#2
Coalesced down to 1 phi equivalence classes
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@2
@2: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @2
  [3] phi()
main: scope:[main]  from @2
  [4] phi()
  [5] call inccnt 
  to:main::@1
main::@1: scope:[main]  from main
  [6] *((const byte[256]) 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[256]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 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/signed byte/word/signed word/dword/signed dword) 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[256]) 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
//SEG0 File Comments
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
  .label cnt = 2
  .label cnt_11 = 3
  .label cnt_13 = 4
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @2 [phi:@begin->@2]
b2_from_bbegin:
  jmp b2
//SEG5 @2
b2:
//SEG6 [2] call main 
//SEG7 [4] phi from @2 to main [phi:@2->main]
main_from_b2:
  jsr main
//SEG8 [3] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
  jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
  //SEG11 [5] call inccnt 
  //SEG12 [12] phi from main to inccnt [phi:main->inccnt]
  inccnt_from_main:
  //SEG13 [12] phi (byte) cnt#12 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->inccnt#0] -- vbuz1=vbuc1 
    lda #0
    sta cnt
    jsr inccnt
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [6] *((const byte[256]) SCREEN#0) ← (byte) cnt#13 -- _deref_pbuc1=vbuz1 
    lda cnt_13
    sta SCREEN
  //SEG16 [7] (byte) cnt#2 ← ++ (byte) cnt#13 -- vbuz1=_inc_vbuz2 
    ldy cnt_13
    iny
    sty cnt
  //SEG17 [8] call inccnt 
  //SEG18 [12] phi from main::@1 to inccnt [phi:main::@1->inccnt]
  inccnt_from_b1:
  //SEG19 [12] phi (byte) cnt#12 = (byte) cnt#2 [phi:main::@1->inccnt#0] -- register_copy 
    jsr inccnt
    jmp b2
  //SEG20 main::@2
  b2:
  //SEG21 [9] (byte) cnt#11 ← ++ (byte) cnt#13 -- vbuz1=_inc_vbuz2 
    ldy cnt_13
    iny
    sty cnt_11
  //SEG22 [10] *((const byte[256]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte) cnt#11 -- _deref_pbuc1=vbuz1 
    lda cnt_11
    sta SCREEN+1
    jmp breturn
  //SEG23 main::@return
  breturn:
  //SEG24 [11] return 
    rts
}
//SEG25 inccnt
inccnt: {
  //SEG26 [13] (byte) cnt#13 ← ++ (byte) cnt#12 -- vbuz1=_inc_vbuz2 
    ldy cnt
    iny
    sty cnt_13
    jmp breturn
  //SEG27 inccnt::@return
  breturn:
  //SEG28 [14] return 
    rts
}

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
//SEG0 File Comments
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @2 [phi:@begin->@2]
b2_from_bbegin:
  jmp b2
//SEG5 @2
b2:
//SEG6 [2] call main 
//SEG7 [4] phi from @2 to main [phi:@2->main]
main_from_b2:
  jsr main
//SEG8 [3] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
  jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
  //SEG11 [5] call inccnt 
  //SEG12 [12] phi from main to inccnt [phi:main->inccnt]
  inccnt_from_main:
  //SEG13 [12] phi (byte) cnt#12 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->inccnt#0] -- vbuxx=vbuc1 
    ldx #0
    jsr inccnt
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [6] *((const byte[256]) SCREEN#0) ← (byte) cnt#13 -- _deref_pbuc1=vbuxx 
    stx SCREEN
  //SEG16 [7] (byte) cnt#2 ← ++ (byte) cnt#13 -- vbuxx=_inc_vbuxx 
    inx
  //SEG17 [8] call inccnt 
  //SEG18 [12] phi from main::@1 to inccnt [phi:main::@1->inccnt]
  inccnt_from_b1:
  //SEG19 [12] phi (byte) cnt#12 = (byte) cnt#2 [phi:main::@1->inccnt#0] -- register_copy 
    jsr inccnt
    jmp b2
  //SEG20 main::@2
  b2:
  //SEG21 [9] (byte) cnt#11 ← ++ (byte) cnt#13 -- vbuxx=_inc_vbuxx 
    inx
  //SEG22 [10] *((const byte[256]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte) cnt#11 -- _deref_pbuc1=vbuxx 
    stx SCREEN+1
    jmp breturn
  //SEG23 main::@return
  breturn:
  //SEG24 [11] return 
    rts
}
//SEG25 inccnt
inccnt: {
  //SEG26 [13] (byte) cnt#13 ← ++ (byte) cnt#12 -- vbuxx=_inc_vbuxx 
    inx
    jmp breturn
  //SEG27 inccnt::@return
  breturn:
  //SEG28 [14] return 
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b2
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 b2_from_bbegin:
Removing instruction b2:
Removing instruction main_from_b2:
Removing instruction bend_from_b2:
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) @2
(label) @begin
(label) @end
(byte[256]) SCREEN
(const byte[256]) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 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

//SEG0 File Comments
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
//SEG3 @begin
//SEG4 [1] phi from @begin to @2 [phi:@begin->@2]
//SEG5 @2
//SEG6 [2] call main 
//SEG7 [4] phi from @2 to main [phi:@2->main]
//SEG8 [3] phi from @2 to @end [phi:@2->@end]
//SEG9 @end
//SEG10 main
main: {
  //SEG11 [5] call inccnt 
  //SEG12 [12] phi from main to inccnt [phi:main->inccnt]
  //SEG13 [12] phi (byte) cnt#12 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->inccnt#0] -- vbuxx=vbuc1 
    ldx #0
    jsr inccnt
  //SEG14 main::@1
  //SEG15 [6] *((const byte[256]) SCREEN#0) ← (byte) cnt#13 -- _deref_pbuc1=vbuxx 
    stx SCREEN
  //SEG16 [7] (byte) cnt#2 ← ++ (byte) cnt#13 -- vbuxx=_inc_vbuxx 
    inx
  //SEG17 [8] call inccnt 
  //SEG18 [12] phi from main::@1 to inccnt [phi:main::@1->inccnt]
  //SEG19 [12] phi (byte) cnt#12 = (byte) cnt#2 [phi:main::@1->inccnt#0] -- register_copy 
    jsr inccnt
  //SEG20 main::@2
  //SEG21 [9] (byte) cnt#11 ← ++ (byte) cnt#13 -- vbuxx=_inc_vbuxx 
    inx
  //SEG22 [10] *((const byte[256]) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte) cnt#11 -- _deref_pbuc1=vbuxx 
    stx SCREEN+1
  //SEG23 main::@return
  //SEG24 [11] return 
    rts
}
//SEG25 inccnt
inccnt: {
  //SEG26 [13] (byte) cnt#13 ← ++ (byte) cnt#12 -- vbuxx=_inc_vbuxx 
    inx
  //SEG27 inccnt::@return
  //SEG28 [14] return 
    rts
}

