Resolved forward reference fn1 to (void()) fn1()
Culled Empty Block (label) main::@2
Culled Empty Block (label) @1
Culled Empty Block (label) fn1::@2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@2
main: scope:[main]  from @2
  (void()*~) main::$0 ← & (void()) fn1()
  (void()*) main::cls#0 ← (void()*~) main::$0
  (byte*) main::cols#0 ← ((byte*)) (number) $d800
  to:main::@1
main::@1: scope:[main]  from main main::@1
  (byte*) main::cols#2 ← phi( main/(byte*) main::cols#0 main::@1/(byte*) main::cols#1 )
  (void()*) main::cls#1 ← phi( main/(void()*) main::cls#0 main::@1/(void()*) main::cls#1 )
  call *((void()*) main::cls#1) 
  *((byte*) main::cols#2) ← ++ *((byte*) main::cols#2)
  (byte*) main::cols#1 ← ++ (byte*) main::cols#2
  (bool~) main::$2 ← (byte*) main::cols#1 < (number) $d800+(number) $3e8
  if((bool~) main::$2) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return
fn1: scope:[fn1]  from
  (byte*) fn1::screen#0 ← ((byte*)) (number) $400
  to:fn1::@1
fn1::@1: scope:[fn1]  from fn1 fn1::@1
  (byte*) fn1::screen#2 ← phi( fn1/(byte*) fn1::screen#0 fn1::@1/(byte*) fn1::screen#1 )
  *((byte*) fn1::screen#2) ← ++ *((byte*) fn1::screen#2)
  (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#2
  (bool~) fn1::$0 ← (byte*) fn1::screen#1 < (number) $400+(number) $3e8
  if((bool~) fn1::$0) goto fn1::@1
  to:fn1::@return
fn1::@return: scope:[fn1]  from fn1::@1
  return 
  to:@return
@2: scope:[]  from @begin
  call main 
  to:@3
@3: scope:[]  from @2
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(void()) fn1()
(bool~) fn1::$0
(label) fn1::@1
(label) fn1::@return
(byte*) fn1::screen
(byte*) fn1::screen#0
(byte*) fn1::screen#1
(byte*) fn1::screen#2
(void()) main()
(void()*~) main::$0
(bool~) main::$2
(label) main::@1
(label) main::@return
(void()*) main::cls
(void()*) main::cls#0
(void()*) main::cls#1
(byte*) main::cols
(byte*) main::cols#0
(byte*) main::cols#1
(byte*) main::cols#2

Adding number conversion cast (unumber) $d800+$3e8 in (bool~) main::$2 ← (byte*) main::cols#1 < (number) $d800+(number) $3e8
Adding number conversion cast (unumber) $400+$3e8 in (bool~) fn1::$0 ← (byte*) fn1::screen#1 < (number) $400+(number) $3e8
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) main::cols#0 ← (byte*)(number) $d800
Inlining cast (byte*) fn1::screen#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 55296
Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Alias (void()*) main::cls#0 = (void()*~) main::$0 
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (void()*) main::cls#1
Successful SSA optimization Pass2SelfPhiElimination
Identical Phi Values (void()*) main::cls#1 (void()*) main::cls#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$2 [8] if((byte*) main::cols#1<(word)(number) $d800+(number) $3e8) goto main::@1
Simple Condition (bool~) fn1::$0 [15] if((byte*) fn1::screen#1<(word)(number) $400+(number) $3e8) goto fn1::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [0] (void()*) main::cls#0 ← & (void()) fn1()
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const void()*) main::cls#0 = &fn1
Constant (const byte*) main::cols#0 = (byte*) 55296
Constant (const byte*) fn1::screen#0 = (byte*) 1024
Successful SSA optimization Pass2ConstantIdentification
Replacing constant pointer function [4] call fn1 
Successful SSA optimization Pass2ConstantCallPointerIdentification
Eliminating unused constant (const void()*) main::cls#0
Successful SSA optimization PassNEliminateUnusedVars
Inlining constant with var siblings (const byte*) main::cols#0
Inlining constant with var siblings (const byte*) fn1::screen#0
Constant inlined fn1::screen#0 = (byte*) 1024
Constant inlined main::cols#0 = (byte*) 55296
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@3(between main::@1 and main::@1)
Added new block during phi lifting fn1::@3(between fn1::@1 and fn1::@1)
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
Adding NOP phi() at start of fn1
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to fn1:7 

Created 2 initial phi equivalence classes
Coalesced [12] main::cols#3 ← main::cols#1
Coalesced [19] fn1::screen#3 ← fn1::screen#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) main::@3
Culled Empty Block (label) fn1::@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 fn1

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()
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [5] (byte*) main::cols#2 ← phi( main/(byte*) 55296 main::@1/(byte*) main::cols#1 )
  [6] call fn1 
  [7] *((byte*) main::cols#2) ← ++ *((byte*) main::cols#2)
  [8] (byte*) main::cols#1 ← ++ (byte*) main::cols#2
  [9] if((byte*) main::cols#1<(word)(number) $d800+(number) $3e8) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [10] return 
  to:@return
fn1: scope:[fn1]  from main::@1
  [11] phi()
  to:fn1::@1
fn1::@1: scope:[fn1]  from fn1 fn1::@1
  [12] (byte*) fn1::screen#2 ← phi( fn1/(byte*) 1024 fn1::@1/(byte*) fn1::screen#1 )
  [13] *((byte*) fn1::screen#2) ← ++ *((byte*) fn1::screen#2)
  [14] (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#2
  [15] if((byte*) fn1::screen#1<(word)(number) $400+(number) $3e8) goto fn1::@1
  to:fn1::@return
fn1::@return: scope:[fn1]  from fn1::@1
  [16] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) fn1()
(byte*) fn1::screen
(byte*) fn1::screen#1 151.5
(byte*) fn1::screen#2 202.0
(void()) main()
(void()*) main::cls
(byte*) main::cols
(byte*) main::cols#1 16.5
(byte*) main::cols#2 14.666666666666666

Initial phi equivalence classes
[ main::cols#2 main::cols#1 ]
[ fn1::screen#2 fn1::screen#1 ]
Complete equivalence classes
[ main::cols#2 main::cols#1 ]
[ fn1::screen#2 fn1::screen#1 ]
Allocated zp ZP_WORD:2 [ main::cols#2 main::cols#1 ]
Allocated zp ZP_WORD:4 [ fn1::screen#2 fn1::screen#1 ]

INITIAL ASM
  // File Comments
// Tests calling into a function pointer with local variables
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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: {
    .label cols = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte*) main::cols#2 = (byte*) 55296 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$d800
    sta cols
    lda #>$d800
    sta cols+1
    jmp b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (byte*) main::cols#2 = (byte*) main::cols#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] call fn1 
    // [11] phi from main::@1 to fn1 [phi:main::@1->fn1]
  fn1_from_b1:
    jsr fn1
    // [7] *((byte*) main::cols#2) ← ++ *((byte*) main::cols#2) -- _deref_pbuz1=_inc__deref_pbuz1 
    ldy #0
    lda (cols),y
    clc
    adc #1
    ldy #0
    sta (cols),y
    // [8] (byte*) main::cols#1 ← ++ (byte*) main::cols#2 -- pbuz1=_inc_pbuz1 
    inc cols
    bne !+
    inc cols+1
  !:
    // [9] if((byte*) main::cols#1<(word)(number) $d800+(number) $3e8) goto main::@1 -- pbuz1_lt_vwuc1_then_la1 
    lda cols+1
    cmp #>$d800+$3e8
    bcc b1_from_b1
    bne !+
    lda cols
    cmp #<$d800+$3e8
    bcc b1_from_b1
  !:
    jmp breturn
    // main::@return
  breturn:
    // [10] return 
    rts
}
  // fn1
fn1: {
    .label screen = 4
    // [12] phi from fn1 to fn1::@1 [phi:fn1->fn1::@1]
  b1_from_fn1:
    // [12] phi (byte*) fn1::screen#2 = (byte*) 1024 [phi:fn1->fn1::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    jmp b1
    // [12] phi from fn1::@1 to fn1::@1 [phi:fn1::@1->fn1::@1]
  b1_from_b1:
    // [12] phi (byte*) fn1::screen#2 = (byte*) fn1::screen#1 [phi:fn1::@1->fn1::@1#0] -- register_copy 
    jmp b1
    // fn1::@1
  b1:
    // [13] *((byte*) fn1::screen#2) ← ++ *((byte*) fn1::screen#2) -- _deref_pbuz1=_inc__deref_pbuz1 
    ldy #0
    lda (screen),y
    clc
    adc #1
    ldy #0
    sta (screen),y
    // [14] (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#2 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [15] if((byte*) fn1::screen#1<(word)(number) $400+(number) $3e8) goto fn1::@1 -- pbuz1_lt_vwuc1_then_la1 
    lda screen+1
    cmp #>$400+$3e8
    bcc b1_from_b1
    bne !+
    lda screen
    cmp #<$400+$3e8
    bcc b1_from_b1
  !:
    jmp breturn
    // fn1::@return
  breturn:
    // [16] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] *((byte*) main::cols#2) ← ++ *((byte*) main::cols#2) [ main::cols#2 ] ( main:2 [ main::cols#2 ] ) always clobbers reg byte a reg byte y 
Statement [9] if((byte*) main::cols#1<(word)(number) $d800+(number) $3e8) goto main::@1 [ main::cols#1 ] ( main:2 [ main::cols#1 ] ) always clobbers reg byte a 
Statement [13] *((byte*) fn1::screen#2) ← ++ *((byte*) fn1::screen#2) [ fn1::screen#2 ] ( main:2::fn1:6 [ main::cols#2 fn1::screen#2 ] ) always clobbers reg byte a reg byte y 
Statement [15] if((byte*) fn1::screen#1<(word)(number) $400+(number) $3e8) goto fn1::@1 [ fn1::screen#1 ] ( main:2::fn1:6 [ main::cols#2 fn1::screen#1 ] ) always clobbers reg byte a 
Potential registers zp ZP_WORD:2 [ main::cols#2 main::cols#1 ] : zp ZP_WORD:2 , 
Potential registers zp ZP_WORD:4 [ fn1::screen#2 fn1::screen#1 ] : zp ZP_WORD:4 , 

REGISTER UPLIFT SCOPES
Uplift Scope [fn1] 353.5: zp ZP_WORD:4 [ fn1::screen#2 fn1::screen#1 ] 
Uplift Scope [main] 31.17: zp ZP_WORD:2 [ main::cols#2 main::cols#1 ] 
Uplift Scope [] 

Uplifting [fn1] best 7565 combination zp ZP_WORD:4 [ fn1::screen#2 fn1::screen#1 ] 
Uplifting [main] best 7565 combination zp ZP_WORD:2 [ main::cols#2 main::cols#1 ] 
Uplifting [] best 7565 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests calling into a function pointer with local variables
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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: {
    .label cols = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte*) main::cols#2 = (byte*) 55296 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$d800
    sta cols
    lda #>$d800
    sta cols+1
    jmp b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (byte*) main::cols#2 = (byte*) main::cols#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] call fn1 
    // [11] phi from main::@1 to fn1 [phi:main::@1->fn1]
  fn1_from_b1:
    jsr fn1
    // [7] *((byte*) main::cols#2) ← ++ *((byte*) main::cols#2) -- _deref_pbuz1=_inc__deref_pbuz1 
    ldy #0
    lda (cols),y
    clc
    adc #1
    ldy #0
    sta (cols),y
    // [8] (byte*) main::cols#1 ← ++ (byte*) main::cols#2 -- pbuz1=_inc_pbuz1 
    inc cols
    bne !+
    inc cols+1
  !:
    // [9] if((byte*) main::cols#1<(word)(number) $d800+(number) $3e8) goto main::@1 -- pbuz1_lt_vwuc1_then_la1 
    lda cols+1
    cmp #>$d800+$3e8
    bcc b1_from_b1
    bne !+
    lda cols
    cmp #<$d800+$3e8
    bcc b1_from_b1
  !:
    jmp breturn
    // main::@return
  breturn:
    // [10] return 
    rts
}
  // fn1
fn1: {
    .label screen = 4
    // [12] phi from fn1 to fn1::@1 [phi:fn1->fn1::@1]
  b1_from_fn1:
    // [12] phi (byte*) fn1::screen#2 = (byte*) 1024 [phi:fn1->fn1::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    jmp b1
    // [12] phi from fn1::@1 to fn1::@1 [phi:fn1::@1->fn1::@1]
  b1_from_b1:
    // [12] phi (byte*) fn1::screen#2 = (byte*) fn1::screen#1 [phi:fn1::@1->fn1::@1#0] -- register_copy 
    jmp b1
    // fn1::@1
  b1:
    // [13] *((byte*) fn1::screen#2) ← ++ *((byte*) fn1::screen#2) -- _deref_pbuz1=_inc__deref_pbuz1 
    ldy #0
    lda (screen),y
    clc
    adc #1
    ldy #0
    sta (screen),y
    // [14] (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#2 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [15] if((byte*) fn1::screen#1<(word)(number) $400+(number) $3e8) goto fn1::@1 -- pbuz1_lt_vwuc1_then_la1 
    lda screen+1
    cmp #>$400+$3e8
    bcc b1_from_b1
    bne !+
    lda screen
    cmp #<$400+$3e8
    bcc b1_from_b1
  !:
    jmp breturn
    // fn1::@return
  breturn:
    // [16] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction ldy #0
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label b1_from_b1 with b1
Replacing label b1_from_b1 with b1
Replacing label b1_from_b1 with b1
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Removing instruction fn1_from_b1:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction breturn:
Removing instruction b1_from_fn1:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp b1
Removing instruction jmp b1
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) fn1()
(label) fn1::@1
(label) fn1::@return
(byte*) fn1::screen
(byte*) fn1::screen#1 screen zp ZP_WORD:4 151.5
(byte*) fn1::screen#2 screen zp ZP_WORD:4 202.0
(void()) main()
(label) main::@1
(label) main::@return
(void()*) main::cls
(byte*) main::cols
(byte*) main::cols#1 cols zp ZP_WORD:2 16.5
(byte*) main::cols#2 cols zp ZP_WORD:2 14.666666666666666

zp ZP_WORD:2 [ main::cols#2 main::cols#1 ]
zp ZP_WORD:4 [ fn1::screen#2 fn1::screen#1 ]


FINAL ASSEMBLER
Score: 6343

  // File Comments
// Tests calling into a function pointer with local variables
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // @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: {
    .label cols = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte*) main::cols#2 = (byte*) 55296 [phi:main->main::@1#0] -- pbuz1=pbuc1 
    lda #<$d800
    sta cols
    lda #>$d800
    sta cols+1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [5] phi (byte*) main::cols#2 = (byte*) main::cols#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  b1:
    // (*cls)()
    // [6] call fn1 
    // [11] phi from main::@1 to fn1 [phi:main::@1->fn1]
    jsr fn1
    // (*cols)++;
    // [7] *((byte*) main::cols#2) ← ++ *((byte*) main::cols#2) -- _deref_pbuz1=_inc__deref_pbuz1 
    ldy #0
    lda (cols),y
    clc
    adc #1
    sta (cols),y
    // for(byte* cols = $d800; cols<$d800+1000;cols++)
    // [8] (byte*) main::cols#1 ← ++ (byte*) main::cols#2 -- pbuz1=_inc_pbuz1 
    inc cols
    bne !+
    inc cols+1
  !:
    // [9] if((byte*) main::cols#1<(word)(number) $d800+(number) $3e8) goto main::@1 -- pbuz1_lt_vwuc1_then_la1 
    lda cols+1
    cmp #>$d800+$3e8
    bcc b1
    bne !+
    lda cols
    cmp #<$d800+$3e8
    bcc b1
  !:
    // main::@return
    // }
    // [10] return 
    rts
}
  // fn1
fn1: {
    .label screen = 4
    // [12] phi from fn1 to fn1::@1 [phi:fn1->fn1::@1]
    // [12] phi (byte*) fn1::screen#2 = (byte*) 1024 [phi:fn1->fn1::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    // [12] phi from fn1::@1 to fn1::@1 [phi:fn1::@1->fn1::@1]
    // [12] phi (byte*) fn1::screen#2 = (byte*) fn1::screen#1 [phi:fn1::@1->fn1::@1#0] -- register_copy 
    // fn1::@1
  b1:
    // (*screen)++;
    // [13] *((byte*) fn1::screen#2) ← ++ *((byte*) fn1::screen#2) -- _deref_pbuz1=_inc__deref_pbuz1 
    ldy #0
    lda (screen),y
    clc
    adc #1
    sta (screen),y
    // for(byte* screen=$400;screen<$400+1000;screen++)
    // [14] (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#2 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [15] if((byte*) fn1::screen#1<(word)(number) $400+(number) $3e8) goto fn1::@1 -- pbuz1_lt_vwuc1_then_la1 
    lda screen+1
    cmp #>$400+$3e8
    bcc b1
    bne !+
    lda screen
    cmp #<$400+$3e8
    bcc b1
  !:
    // fn1::@return
    // }
    // [16] return 
    rts
}
  // File Data

