Identified constant variable (byte*) SCREEN
Culled Empty Block (label) @1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte) line#0 ← (byte) $40
  (byte) ch#0 ← (byte) line#0
  to:@2

(void()) main()
main: scope:[main]  from @2
  (byte) ch#16 ← phi( @2/(byte) ch#17 )
  (byte) line#15 ← phi( @2/(byte) line#16 )
  call ln 
  to:main::@1
main::@1: scope:[main]  from main
  (byte) ch#10 ← phi( main/(byte) ch#8 )
  (byte) line#8 ← phi( main/(byte) line#6 )
  (byte) line#1 ← (byte) line#8
  (byte) ch#1 ← (byte) ch#10
  (byte) ch#2 ← ++ (byte) ch#1
  call ln 
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte) ch#11 ← phi( main::@1/(byte) ch#8 )
  (byte) line#9 ← phi( main::@1/(byte) line#6 )
  (byte) line#2 ← (byte) line#9
  (byte) ch#3 ← (byte) ch#11
  (byte) ch#4 ← ++ (byte) ch#3
  call ln 
  to:main::@3
main::@3: scope:[main]  from main::@2
  (byte) ch#12 ← phi( main::@2/(byte) ch#8 )
  (byte) line#10 ← phi( main::@2/(byte) line#6 )
  (byte) line#3 ← (byte) line#10
  (byte) ch#5 ← (byte) ch#12
  *((const byte*) SCREEN) ← (byte) ch#5
  (byte*~) main::$3 ← (const byte*) SCREEN + (number) $28
  *((byte*~) main::$3) ← (byte) line#3
  to:main::@return
main::@return: scope:[main]  from main::@3
  (byte) ch#13 ← phi( main::@3/(byte) ch#5 )
  (byte) line#11 ← phi( main::@3/(byte) line#3 )
  (byte) line#4 ← (byte) line#11
  (byte) ch#6 ← (byte) ch#13
  return 
  to:@return

(void()) ln()
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 )
  (number~) ln::$0 ← (byte) line#12 + (number) 2
  (byte) line#5 ← (number~) ln::$0
  (byte) ch#7 ← (byte) line#5
  to:ln::@return
ln::@return: scope:[ln]  from ln
  (byte) ch#14 ← phi( ln/(byte) ch#7 )
  (byte) line#13 ← phi( ln/(byte) line#5 )
  (byte) line#6 ← (byte) line#13
  (byte) ch#8 ← (byte) ch#14
  return 
  to:@return
@2: scope:[]  from @begin
  (byte) ch#17 ← phi( @begin/(byte) ch#0 )
  (byte) line#16 ← phi( @begin/(byte) line#0 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) ch#15 ← phi( @2/(byte) ch#6 )
  (byte) line#14 ← phi( @2/(byte) line#4 )
  (byte) line#7 ← (byte) line#14
  (byte) ch#9 ← (byte) ch#15
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(byte) ch
(byte) ch#0
(byte) ch#1
(byte) ch#10
(byte) ch#11
(byte) ch#12
(byte) ch#13
(byte) ch#14
(byte) ch#15
(byte) ch#16
(byte) ch#17
(byte) ch#2
(byte) ch#3
(byte) ch#4
(byte) ch#5
(byte) ch#6
(byte) ch#7
(byte) ch#8
(byte) ch#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()
(number~) ln::$0
(label) ln::@return
(void()) main()
(byte*~) main::$3
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return

Adding number conversion cast (unumber) $28 in (byte*~) main::$3 ← (const byte*) SCREEN + (number) $28
Adding number conversion cast (unumber) 2 in (number~) ln::$0 ← (byte) line#12 + (number) 2
Adding number conversion cast (unumber) ln::$0 in (number~) ln::$0 ← (byte) line#12 + (unumber)(number) 2
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $28
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $28
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) ln::$0 ← (byte) line#12 + (byte) 2
Alias (byte) line#0 = (byte) ch#0 (byte) line#16 (byte) ch#17 
Alias (byte) line#1 = (byte) line#8 
Alias (byte) ch#1 = (byte) ch#10 
Alias (byte) line#2 = (byte) line#9 
Alias (byte) ch#11 = (byte) ch#3 
Alias (byte) line#10 = (byte) line#3 (byte) line#11 (byte) line#4 
Alias (byte) ch#12 = (byte) ch#5 (byte) ch#13 (byte) ch#6 
Alias (byte) line#13 = (byte) line#5 (byte~) ln::$0 (byte) ch#7 (byte) ch#14 (byte) line#6 (byte) ch#8 
Alias (byte) line#14 = (byte) line#7 
Alias (byte) ch#15 = (byte) ch#9 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) line#15 (byte) line#0
Identical Phi Values (byte) ch#16 (byte) line#0
Identical Phi Values (byte) line#1 (byte) line#13
Identical Phi Values (byte) ch#1 (byte) line#13
Identical Phi Values (byte) line#2 (byte) line#13
Identical Phi Values (byte) ch#11 (byte) line#13
Identical Phi Values (byte) line#10 (byte) line#13
Identical Phi Values (byte) ch#12 (byte) line#13
Identical Phi Values (byte) line#14 (byte) line#10
Identical Phi Values (byte) ch#15 (byte) ch#12
Successful SSA optimization Pass2IdenticalPhiElimination
Constant right-side identified [11] (byte*~) main::$3 ← (const byte*) SCREEN + (byte) $28
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) line#0 = $40
Constant (const byte*) main::$3 = SCREEN+$28
Successful SSA optimization Pass2ConstantIdentification
Eliminating unused variable (byte) ch#2 and assignment [1] (byte) ch#2 ← ++ (byte) line#13
Eliminating unused variable (byte) ch#4 and assignment [3] (byte) ch#4 ← ++ (byte) line#13
Successful SSA optimization PassNEliminateUnusedVars
Inlining constant with var siblings (const byte) line#0
Constant inlined main::$3 = (const byte*) SCREEN+(byte) $28
Constant inlined line#0 = (byte) $40
Successful SSA optimization Pass2ConstantInlining
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 ln:6 ln:8 ln:10 

Created 1 initial phi equivalence classes
Coalesced [7] line#17 ← line#13
Coalesced (already) [9] line#18 ← line#13
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
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@2

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 ln 
  to:main::@1
main::@1: scope:[main]  from main
  [6] phi()
  [7] call ln 
  to:main::@2
main::@2: scope:[main]  from main::@1
  [8] phi()
  [9] call ln 
  to:main::@3
main::@3: scope:[main]  from main::@2
  [10] *((const byte*) SCREEN) ← (byte) line#13
  [11] *((const byte*) SCREEN+(byte) $28) ← (byte) line#13
  to:main::@return
main::@return: scope:[main]  from main::@3
  [12] return 
  to:@return

(void()) ln()
ln: scope:[ln]  from main main::@1 main::@2
  [13] (byte) line#12 ← phi( main/(byte) $40 main::@1/(byte) line#13 main::@2/(byte) line#13 )
  [14] (byte) line#13 ← (byte) line#12 + (byte) 2
  to:ln::@return
ln::@return: scope:[ln]  from ln
  [15] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) ch
(byte) line
(byte) line#12 6.0
(byte) line#13 1.25
(void()) ln()
(void()) main()

Initial phi equivalence classes
[ line#12 line#13 ]
Complete equivalence classes
[ line#12 line#13 ]
Allocated zp[1]:2 [ line#12 line#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 line = 2
  // @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 ln 
    // [13] phi from main to ln [phi:main->ln]
  ln_from_main:
    // [13] phi (byte) line#12 = (byte) $40 [phi:main->ln#0] -- vbuz1=vbuc1 
    lda #$40
    sta.z line
    jsr ln
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call ln 
    // [13] phi from main::@1 to ln [phi:main::@1->ln]
  ln_from___b1:
    // [13] phi (byte) line#12 = (byte) line#13 [phi:main::@1->ln#0] -- register_copy 
    jsr ln
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [9] call ln 
    // [13] phi from main::@2 to ln [phi:main::@2->ln]
  ln_from___b2:
    // [13] phi (byte) line#12 = (byte) line#13 [phi:main::@2->ln#0] -- register_copy 
    jsr ln
    jmp __b3
    // main::@3
  __b3:
    // [10] *((const byte*) SCREEN) ← (byte) line#13 -- _deref_pbuc1=vbuz1 
    lda.z line
    sta SCREEN
    // [11] *((const byte*) SCREEN+(byte) $28) ← (byte) line#13 -- _deref_pbuc1=vbuz1 
    lda.z line
    sta SCREEN+$28
    jmp __breturn
    // main::@return
  __breturn:
    // [12] return 
    rts
}
  // ln
ln: {
    // [14] (byte) line#13 ← (byte) line#12 + (byte) 2 -- vbuz1=vbuz1_plus_2 
    lda.z line
    clc
    adc #2
    sta.z line
    jmp __breturn
    // ln::@return
  __breturn:
    // [15] return 
    rts
}
  // File Data

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

REGISTER UPLIFT SCOPES
Uplift Scope [] 7.25: zp[1]:2 [ line#12 line#13 ] 
Uplift Scope [main] 
Uplift Scope [ln] 

Uplifting [] best 71 combination reg byte a [ line#12 line#13 ] 
Uplifting [main] best 71 combination 
Uplifting [ln] best 71 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 ln 
    // [13] phi from main to ln [phi:main->ln]
  ln_from_main:
    // [13] phi (byte) line#12 = (byte) $40 [phi:main->ln#0] -- vbuaa=vbuc1 
    lda #$40
    jsr ln
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call ln 
    // [13] phi from main::@1 to ln [phi:main::@1->ln]
  ln_from___b1:
    // [13] phi (byte) line#12 = (byte) line#13 [phi:main::@1->ln#0] -- register_copy 
    jsr ln
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [9] call ln 
    // [13] phi from main::@2 to ln [phi:main::@2->ln]
  ln_from___b2:
    // [13] phi (byte) line#12 = (byte) line#13 [phi:main::@2->ln#0] -- register_copy 
    jsr ln
    jmp __b3
    // main::@3
  __b3:
    // [10] *((const byte*) SCREEN) ← (byte) line#13 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // [11] *((const byte*) SCREEN+(byte) $28) ← (byte) line#13 -- _deref_pbuc1=vbuaa 
    sta SCREEN+$28
    jmp __breturn
    // main::@return
  __breturn:
    // [12] return 
    rts
}
  // ln
ln: {
    // [14] (byte) line#13 ← (byte) line#12 + (byte) 2 -- vbuaa=vbuaa_plus_2 
    clc
    adc #2
    jmp __breturn
    // ln::@return
  __breturn:
    // [15] 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 __b3
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:
Removing instruction __b1_from_main:
Removing instruction ln_from___b1:
Removing instruction __b2_from___b1:
Removing instruction ln_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction ln_from_main:
Removing instruction __b1:
Removing instruction __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 __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(byte) ch
(byte) line
(byte) line#12 reg byte a 6.0
(byte) line#13 reg byte a 1.25
(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 ]


FINAL ASSEMBLER
Score: 44

  // 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: {
    // ln()
    // [5] call ln 
    // [13] phi from main to ln [phi:main->ln]
    // [13] phi (byte) line#12 = (byte) $40 [phi:main->ln#0] -- vbuaa=vbuc1 
    lda #$40
    jsr ln
    // [6] phi from main to main::@1 [phi:main->main::@1]
    // main::@1
    // ln()
    // [7] call ln 
    // [13] phi from main::@1 to ln [phi:main::@1->ln]
    // [13] phi (byte) line#12 = (byte) line#13 [phi:main::@1->ln#0] -- register_copy 
    jsr ln
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // main::@2
    // ln()
    // [9] call ln 
    // [13] phi from main::@2 to ln [phi:main::@2->ln]
    // [13] phi (byte) line#12 = (byte) line#13 [phi:main::@2->ln#0] -- register_copy 
    jsr ln
    // main::@3
    // *SCREEN = ch
    // [10] *((const byte*) SCREEN) ← (byte) line#13 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // *(SCREEN+40) = line
    // [11] *((const byte*) SCREEN+(byte) $28) ← (byte) line#13 -- _deref_pbuc1=vbuaa 
    sta SCREEN+$28
    // main::@return
    // }
    // [12] return 
    rts
}
  // ln
ln: {
    // line + $2
    // [14] (byte) line#13 ← (byte) line#12 + (byte) 2 -- vbuaa=vbuaa_plus_2 
    clc
    adc #2
    // ln::@return
    // }
    // [15] return 
    rts
}
  // File Data

