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

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (number) $400
  (byte) line#0 ← (number) $40
  (byte) ch#0 ← (byte) line#0
  to:@2
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
  *((byte*) SCREEN#0) ← (byte) ch#5
  (byte*~) main::$3 ← (byte*) SCREEN#0 + (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
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
(byte*) SCREEN
(byte*) SCREEN#0
(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) $40 in (byte) line#0 ← (number) $40
Adding number conversion cast (unumber) $28 in (byte*~) main::$3 ← (byte*) SCREEN#0 + (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
Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Inlining cast (byte) line#0 ← (unumber)(number) $40
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $40
Simplifying constant integer cast $28
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $40
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 (const byte*) SCREEN#0 = (byte*) 1024
Constant (const byte) line#0 = $40
Successful SSA optimization Pass2ConstantIdentification
Converting *(pointer+n) to pointer[n] [20] *((byte*~) main::$3) ← (byte) line#13  -- *(SCREEN#0 + $28)
Successful SSA optimization Pass2InlineDerefIdx
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
Eliminating unused variable (byte*~) main::$3 and assignment [6] (byte*~) main::$3 ← (const byte*) SCREEN#0 + (byte) $28
Successful SSA optimization PassNEliminateUnusedVars
Inlining constant with var siblings (const byte) line#0
Constant inlined line#0 = (byte) $40
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(SCREEN#0+$28)
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 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()
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#0) ← (byte) line#13
  [11] *((const byte*) SCREEN#0+(byte) $28) ← (byte) line#13
  to:main::@return
main::@return: scope:[main]  from main::@3
  [12] return 
  to:@return
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*) SCREEN
(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 ZP_BYTE:2 [ line#12 line#13 ]

INITIAL ASM
  // File Comments
  // Basic 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 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#0) ← (byte) line#13 -- _deref_pbuc1=vbuz1 
    lda line
    sta SCREEN
    // [11] *((const byte*) SCREEN#0+(byte) $28) ← (byte) line#13 -- _deref_pbuc1=vbuz1 
    lda 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 line
    clc
    adc #2
    sta line
    jmp breturn
    // ln::@return
  breturn:
    // [15] return 
    rts
}
  // File Data

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 , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 7.25: zp ZP_BYTE: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
  // Basic 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#0) ← (byte) line#13 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // [11] *((const byte*) SCREEN#0+(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
Removing instruction b1_from_bbegin:
Removing instruction b1:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 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
  // Basic 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#0) ← (byte) line#13 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // *(SCREEN+40) = line
    // [11] *((const byte*) SCREEN#0+(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

