
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  (byte) line#0 ← (byte/signed byte/word/signed word/dword/signed dword) 64
  (byte) char#0 ← (byte) line#0
  to:@2
main: scope:[main]  from @2
  (byte*) SCREEN#4 ← phi( @2/(byte*) SCREEN#5 )
  (byte) char#16 ← phi( @2/(byte) char#17 )
  (byte) line#15 ← phi( @2/(byte) line#16 )
  call ln 
  to:main::@1
main::@1: scope:[main]  from main
  (byte*) SCREEN#3 ← phi( main/(byte*) SCREEN#4 )
  (byte) char#10 ← phi( main/(byte) char#8 )
  (byte) line#8 ← phi( main/(byte) line#6 )
  (byte) line#1 ← (byte) line#8
  (byte) char#1 ← (byte) char#10
  (byte) char#2 ← ++ (byte) char#1
  call ln 
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte*) SCREEN#2 ← phi( main::@1/(byte*) SCREEN#3 )
  (byte) char#11 ← phi( main::@1/(byte) char#8 )
  (byte) line#9 ← phi( main::@1/(byte) line#6 )
  (byte) line#2 ← (byte) line#9
  (byte) char#3 ← (byte) char#11
  (byte) char#4 ← ++ (byte) char#3
  call ln 
  to:main::@3
main::@3: scope:[main]  from main::@2
  (byte*) SCREEN#1 ← phi( main::@2/(byte*) SCREEN#2 )
  (byte) char#12 ← phi( main::@2/(byte) char#8 )
  (byte) line#10 ← phi( main::@2/(byte) line#6 )
  (byte) line#3 ← (byte) line#10
  (byte) char#5 ← (byte) char#12
  *((byte*) SCREEN#1) ← (byte) char#5
  to:main::@return
main::@return: scope:[main]  from main::@3
  (byte) char#13 ← phi( main::@3/(byte) char#5 )
  (byte) line#11 ← phi( main::@3/(byte) line#3 )
  (byte) line#4 ← (byte) line#11
  (byte) char#6 ← (byte) char#13
  return 
  to:@return
ln: scope:[ln]  from main main::@1 main::@2
  (byte) line#12 ← phi( main/(byte) line#15 main::@1/(byte) line#1 main::@2/(byte) line#2 )
  (byte/signed word/word/dword/signed dword~) ln::$0 ← (byte) line#12 + (byte/signed byte/word/signed word/dword/signed dword) 2
  (byte) line#5 ← (byte/signed word/word/dword/signed dword~) ln::$0
  (byte) char#7 ← (byte) line#5
  to:ln::@return
ln::@return: scope:[ln]  from ln
  (byte) char#14 ← phi( ln/(byte) char#7 )
  (byte) line#13 ← phi( ln/(byte) line#5 )
  (byte) line#6 ← (byte) line#13
  (byte) char#8 ← (byte) char#14
  return 
  to:@return
@2: scope:[]  from @begin
  (byte*) SCREEN#5 ← phi( @begin/(byte*) SCREEN#0 )
  (byte) char#17 ← phi( @begin/(byte) char#0 )
  (byte) line#16 ← phi( @begin/(byte) line#0 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) char#15 ← phi( @2/(byte) char#6 )
  (byte) line#14 ← phi( @2/(byte) line#4 )
  (byte) line#7 ← (byte) line#14
  (byte) char#9 ← (byte) char#15
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(byte*) SCREEN
(byte*) SCREEN#0
(byte*) SCREEN#1
(byte*) SCREEN#2
(byte*) SCREEN#3
(byte*) SCREEN#4
(byte*) SCREEN#5
(byte) char
(byte) char#0
(byte) char#1
(byte) char#10
(byte) char#11
(byte) char#12
(byte) char#13
(byte) char#14
(byte) char#15
(byte) char#16
(byte) char#17
(byte) char#2
(byte) char#3
(byte) char#4
(byte) char#5
(byte) char#6
(byte) char#7
(byte) char#8
(byte) char#9
(byte) line
(byte) line#0
(byte) line#1
(byte) line#10
(byte) line#11
(byte) line#12
(byte) line#13
(byte) line#14
(byte) line#15
(byte) line#16
(byte) line#2
(byte) line#3
(byte) line#4
(byte) line#5
(byte) line#6
(byte) line#7
(byte) line#8
(byte) line#9
(void()) ln()
(byte/signed word/word/dword/signed dword~) ln::$0
(label) ln::@return
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return

Alias (byte) line#0 = (byte) char#0 (byte) line#16 (byte) char#17 
Alias (byte*) SCREEN#1 = (byte*) SCREEN#3 (byte*) SCREEN#4 (byte*) SCREEN#2 
Alias (byte) line#1 = (byte) line#8 
Alias (byte) char#1 = (byte) char#10 
Alias (byte) line#2 = (byte) line#9 
Alias (byte) char#11 = (byte) char#3 
Alias (byte) line#10 = (byte) line#3 (byte) line#11 (byte) line#4 
Alias (byte) char#12 = (byte) char#5 (byte) char#13 (byte) char#6 
Alias (byte) line#13 = (byte) line#5 (byte/signed word/word/dword/signed dword~) ln::$0 (byte) char#7 (byte) char#14 (byte) line#6 (byte) char#8 
Alias (byte*) SCREEN#0 = (byte*) SCREEN#5 
Alias (byte) line#14 = (byte) line#7 
Alias (byte) char#15 = (byte) char#9 
Successful SSA optimization Pass2AliasElimination
Redundant Phi (byte) line#15 (byte) line#0
Redundant Phi (byte) char#16 (byte) line#0
Redundant Phi (byte*) SCREEN#1 (byte*) SCREEN#0
Redundant Phi (byte) line#1 (byte) line#13
Redundant Phi (byte) char#1 (byte) line#13
Redundant Phi (byte) line#2 (byte) line#13
Redundant Phi (byte) char#11 (byte) line#13
Redundant Phi (byte) line#10 (byte) line#13
Redundant Phi (byte) char#12 (byte) line#13
Redundant Phi (byte) line#14 (byte) line#10
Redundant Phi (byte) char#15 (byte) char#12
Successful SSA optimization Pass2RedundantPhiElimination
Constant (const byte*) SCREEN#0 = ((byte*))1024
Constant (const byte) line#0 = 64
Successful SSA optimization Pass2ConstantIdentification
Culled Empty Block (label) @3
Successful SSA optimization Pass2CullEmptyBlocks
Inlining constant with var siblings (const byte) line#0
Constant inlined line#0 = (byte/signed byte/word/signed word/dword/signed dword) 64
Successful SSA optimization Pass2ConstantInlining
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 ln:5 ln:8 ln:11 

Created 1 initial phi equivalence classes
Coalesced [7] line#17 ← line#13
Coalesced (already) [10] line#18 ← line#13
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 ln 
  to:main::@1
main::@1: scope:[main]  from main
  [6] (byte) char#2 ← ++ (byte) line#13
  [7] call ln 
  to:main::@2
main::@2: scope:[main]  from main::@1
  [8] (byte) char#4 ← ++ (byte) line#13
  [9] call ln 
  to:main::@3
main::@3: scope:[main]  from main::@2
  [10] *((const byte*) SCREEN#0) ← (byte) line#13
  to:main::@return
main::@return: scope:[main]  from main::@3
  [11] return 
  to:@return
ln: scope:[ln]  from main main::@1 main::@2
  [12] (byte) line#12 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 64 main::@1/(byte) line#13 main::@2/(byte) line#13 )
  [13] (byte) line#13 ← (byte) line#12 + (byte/signed byte/word/signed word/dword/signed dword) 2
  to:ln::@return
ln::@return: scope:[ln]  from ln
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(byte) char
(byte) char#2 20.0
(byte) char#4 20.0
(byte) line
(byte) line#12 6.0
(byte) line#13 1.714285714285714
(void()) ln()
(void()) main()

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

INITIAL ASM
//SEG0 File Comments
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .label SCREEN = $400
  .label char = 3
  .label char_4 = 4
  .label line = 2
//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 ln 
  //SEG12 [12] phi from main to ln [phi:main->ln]
  ln_from_main:
  //SEG13 [12] phi (byte) line#12 = (byte/signed byte/word/signed word/dword/signed dword) 64 [phi:main->ln#0] -- vbuz1=vbuc1 
    lda #$40
    sta line
    jsr ln
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [6] (byte) char#2 ← ++ (byte) line#13 -- vbuz1=_inc_vbuz2 
    ldy line
    iny
    sty char
  //SEG16 [7] call ln 
  //SEG17 [12] phi from main::@1 to ln [phi:main::@1->ln]
  ln_from_b1:
  //SEG18 [12] phi (byte) line#12 = (byte) line#13 [phi:main::@1->ln#0] -- register_copy 
    jsr ln
    jmp b2
  //SEG19 main::@2
  b2:
  //SEG20 [8] (byte) char#4 ← ++ (byte) line#13 -- vbuz1=_inc_vbuz2 
    ldy line
    iny
    sty char_4
  //SEG21 [9] call ln 
  //SEG22 [12] phi from main::@2 to ln [phi:main::@2->ln]
  ln_from_b2:
  //SEG23 [12] phi (byte) line#12 = (byte) line#13 [phi:main::@2->ln#0] -- register_copy 
    jsr ln
    jmp b3
  //SEG24 main::@3
  b3:
  //SEG25 [10] *((const byte*) SCREEN#0) ← (byte) line#13 -- _deref_pbuc1=vbuz1 
    lda line
    sta SCREEN
    jmp breturn
  //SEG26 main::@return
  breturn:
  //SEG27 [11] return 
    rts
}
//SEG28 ln
ln: {
  //SEG29 [13] (byte) line#13 ← (byte) line#12 + (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuz1=vbuz1_plus_2 
    lda line
    clc
    adc #2
    sta line
    jmp breturn
  //SEG30 ln::@return
  breturn:
  //SEG31 [14] return 
    rts
}

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

REGISTER UPLIFT SCOPES
Uplift Scope [] 20: zp ZP_BYTE:3 [ char#2 ] 20: zp ZP_BYTE:4 [ char#4 ] 7.71: zp ZP_BYTE:2 [ line#12 line#13 ] 
Uplift Scope [main] 
Uplift Scope [ln] 

Uplifting [] best 75 combination reg byte x [ char#2 ] reg byte x [ char#4 ] reg byte a [ line#12 line#13 ] 
Uplifting [main] best 75 combination 
Uplifting [ln] best 75 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 ln 
  //SEG12 [12] phi from main to ln [phi:main->ln]
  ln_from_main:
  //SEG13 [12] phi (byte) line#12 = (byte/signed byte/word/signed word/dword/signed dword) 64 [phi:main->ln#0] -- vbuaa=vbuc1 
    lda #$40
    jsr ln
    jmp b1
  //SEG14 main::@1
  b1:
  //SEG15 [6] (byte) char#2 ← ++ (byte) line#13 -- vbuxx=_inc_vbuaa 
    tax
    inx
  //SEG16 [7] call ln 
  //SEG17 [12] phi from main::@1 to ln [phi:main::@1->ln]
  ln_from_b1:
  //SEG18 [12] phi (byte) line#12 = (byte) line#13 [phi:main::@1->ln#0] -- register_copy 
    jsr ln
    jmp b2
  //SEG19 main::@2
  b2:
  //SEG20 [8] (byte) char#4 ← ++ (byte) line#13 -- vbuxx=_inc_vbuaa 
    tax
    inx
  //SEG21 [9] call ln 
  //SEG22 [12] phi from main::@2 to ln [phi:main::@2->ln]
  ln_from_b2:
  //SEG23 [12] phi (byte) line#12 = (byte) line#13 [phi:main::@2->ln#0] -- register_copy 
    jsr ln
    jmp b3
  //SEG24 main::@3
  b3:
  //SEG25 [10] *((const byte*) SCREEN#0) ← (byte) line#13 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    jmp breturn
  //SEG26 main::@return
  breturn:
  //SEG27 [11] return 
    rts
}
//SEG28 ln
ln: {
  //SEG29 [13] (byte) line#13 ← (byte) line#12 + (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuaa=vbuaa_plus_2 
    clc
    adc #2
    jmp breturn
  //SEG30 ln::@return
  breturn:
  //SEG31 [14] return 
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b2
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b3
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 ln_from_main:
Removing instruction b1:
Removing instruction ln_from_b1:
Removing instruction b2:
Removing instruction ln_from_b2:
Removing instruction b3:
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*) SCREEN
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024
(byte) char
(byte) char#2 reg byte x 20.0
(byte) char#4 reg byte x 20.0
(byte) line
(byte) line#12 reg byte a 6.0
(byte) line#13 reg byte a 1.714285714285714
(void()) ln()
(label) ln::@return
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return

reg byte a [ line#12 line#13 ]
reg byte x [ char#2 ]
reg byte x [ char#4 ]


FINAL ASSEMBLER
Score: 48

//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 ln 
  //SEG12 [12] phi from main to ln [phi:main->ln]
  //SEG13 [12] phi (byte) line#12 = (byte/signed byte/word/signed word/dword/signed dword) 64 [phi:main->ln#0] -- vbuaa=vbuc1 
    lda #$40
    jsr ln
  //SEG14 main::@1
  //SEG15 [6] (byte) char#2 ← ++ (byte) line#13 -- vbuxx=_inc_vbuaa 
    tax
    inx
  //SEG16 [7] call ln 
  //SEG17 [12] phi from main::@1 to ln [phi:main::@1->ln]
  //SEG18 [12] phi (byte) line#12 = (byte) line#13 [phi:main::@1->ln#0] -- register_copy 
    jsr ln
  //SEG19 main::@2
  //SEG20 [8] (byte) char#4 ← ++ (byte) line#13 -- vbuxx=_inc_vbuaa 
    tax
    inx
  //SEG21 [9] call ln 
  //SEG22 [12] phi from main::@2 to ln [phi:main::@2->ln]
  //SEG23 [12] phi (byte) line#12 = (byte) line#13 [phi:main::@2->ln#0] -- register_copy 
    jsr ln
  //SEG24 main::@3
  //SEG25 [10] *((const byte*) SCREEN#0) ← (byte) line#13 -- _deref_pbuc1=vbuaa 
    sta SCREEN
  //SEG26 main::@return
  //SEG27 [11] return 
    rts
}
//SEG28 ln
ln: {
  //SEG29 [13] (byte) line#13 ← (byte) line#12 + (byte/signed byte/word/signed word/dword/signed dword) 2 -- vbuaa=vbuaa_plus_2 
    clc
    adc #2
  //SEG30 ln::@return
  //SEG31 [14] return 
    rts
}

