Identified constant variable (void()*) main::cls
Culled Empty Block (label) fn1::@4
Culled Empty Block (label) fn1::@3
Culled Empty Block (label) fn1::@5
Culled Empty Block (label) fn1::@6
Culled Empty Block (label) @1
Culled Empty Block (label) main::@4
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@2

(void()) fn1()
fn1: scope:[fn1]  from
  (byte*) fn1::screen#0 ← (byte*)(number) $400
  to:fn1::@1
fn1::@1: scope:[fn1]  from fn1 fn1::@2
  (byte*) fn1::screen#2 ← phi( fn1/(byte*) fn1::screen#0 fn1::@2/(byte*) fn1::screen#1 )
  (bool~) fn1::$0 ← (byte*) fn1::screen#2 < (number) $400+(number) $3e8
  if((bool~) fn1::$0) goto fn1::@2
  to:fn1::@return
fn1::@2: scope:[fn1]  from fn1::@1
  (byte*) fn1::screen#3 ← phi( fn1::@1/(byte*) fn1::screen#2 )
  *((byte*) fn1::screen#3) ← ++ *((byte*) fn1::screen#3)
  (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#3
  to:fn1::@1
fn1::@return: scope:[fn1]  from fn1::@1
  return 
  to:@return

(void()) main()
main: scope:[main]  from @2
  (byte*) main::cols#0 ← (byte*)(number) $d800
  to:main::@1
main::@1: scope:[main]  from main main::@2
  (byte*) main::cols#2 ← phi( main/(byte*) main::cols#0 main::@2/(byte*) main::cols#1 )
  (bool~) main::$0 ← (byte*) main::cols#2 < (number) $d800+(number) $3e8
  if((bool~) main::$0) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  (byte*) main::cols#3 ← phi( main::@1/(byte*) main::cols#2 )
  call *((const void()*) main::cls) 
  *((byte*) main::cols#3) ← ++ *((byte*) main::cols#3)
  (byte*) main::cols#1 ← ++ (byte*) main::cols#3
  to:main::@1
main::@return: scope:[main]  from main::@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::@2
(label) fn1::@return
(byte*) fn1::screen
(byte*) fn1::screen#0
(byte*) fn1::screen#1
(byte*) fn1::screen#2
(byte*) fn1::screen#3
(void()) main()
(bool~) main::$0
(label) main::@1
(label) main::@2
(label) main::@return
(const void()*) main::cls = &(void()) fn1()
(byte*) main::cols
(byte*) main::cols#0
(byte*) main::cols#1
(byte*) main::cols#2
(byte*) main::cols#3

Adding number conversion cast (unumber) $400+$3e8 in (bool~) fn1::$0 ← (byte*) fn1::screen#2 < (number) $400+(number) $3e8
Adding number conversion cast (unumber) $d800+$3e8 in (bool~) main::$0 ← (byte*) main::cols#2 < (number) $d800+(number) $3e8
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant pointer cast (byte*) 55296
Successful SSA optimization PassNCastSimplification
Alias (byte*) fn1::screen#2 = (byte*) fn1::screen#3 
Alias (byte*) main::cols#2 = (byte*) main::cols#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) fn1::$0 [3] if((byte*) fn1::screen#2<(word)(number) $400+(number) $3e8) goto fn1::@2
Simple Condition (bool~) main::$0 [11] if((byte*) main::cols#2<(word)(number) $d800+(number) $3e8) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) fn1::screen#0 = (byte*) 1024
Constant (const byte*) main::cols#0 = (byte*) 55296
Successful SSA optimization Pass2ConstantIdentification
Replacing constant pointer function [13] call fn1 
Successful SSA optimization Pass2ConstantCallPointerIdentification
Eliminating unused constant (const void()*) main::cls
Successful SSA optimization PassNEliminateUnusedVars
Inlining constant with var siblings (const byte*) fn1::screen#0
Inlining constant with var siblings (const byte*) main::cols#0
Constant inlined fn1::screen#0 = (byte*) 1024
Constant inlined main::cols#0 = (byte*) 55296
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
Adding NOP phi() at start of main::@2
Adding NOP phi() at start of fn1
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to fn1:10 

Created 2 initial phi equivalence classes
Coalesced [13] main::cols#4 ← main::cols#1
Coalesced [20] fn1::screen#4 ← fn1::screen#1
Coalesced down to 2 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::@2
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()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [5] (byte*) main::cols#2 ← phi( main/(byte*) 55296 main::@2/(byte*) main::cols#1 )
  [6] if((byte*) main::cols#2<(word)(number) $d800+(number) $3e8) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@1
  [7] return 
  to:@return
main::@2: scope:[main]  from main::@1
  [8] phi()
  [9] call fn1 
  [10] *((byte*) main::cols#2) ← ++ *((byte*) main::cols#2)
  [11] (byte*) main::cols#1 ← ++ (byte*) main::cols#2
  to:main::@1

(void()) fn1()
fn1: scope:[fn1]  from main::@2
  [12] phi()
  to:fn1::@1
fn1::@1: scope:[fn1]  from fn1 fn1::@2
  [13] (byte*) fn1::screen#2 ← phi( fn1/(byte*) 1024 fn1::@2/(byte*) fn1::screen#1 )
  [14] if((byte*) fn1::screen#2<(word)(number) $400+(number) $3e8) goto fn1::@2
  to:fn1::@return
fn1::@return: scope:[fn1]  from fn1::@1
  [15] return 
  to:@return
fn1::@2: scope:[fn1]  from fn1::@1
  [16] *((byte*) fn1::screen#2) ← ++ *((byte*) fn1::screen#2)
  [17] (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#2
  to:fn1::@1


VARIABLE REGISTER WEIGHTS
(void()) fn1()
(byte*) fn1::screen
(byte*) fn1::screen#1 202.0
(byte*) fn1::screen#2 168.33333333333331
(void()) main()
(byte*) main::cols
(byte*) main::cols#1 22.0
(byte*) main::cols#2 11.0

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[2]:2 [ main::cols#2 main::cols#1 ]
Allocated zp[2]:4 [ fn1::screen#2 fn1::screen#1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Tests calling into a function pointer with local variables
  // 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.z cols
    lda #>$d800
    sta.z cols+1
    jmp __b1
    // main::@1
  __b1:
    // [6] if((byte*) main::cols#2<(word)(number) $d800+(number) $3e8) goto main::@2 -- pbuz1_lt_vwuc1_then_la1 
    lda.z cols+1
    cmp #>$d800+$3e8
    bcc __b2_from___b1
    bne !+
    lda.z cols
    cmp #<$d800+$3e8
    bcc __b2_from___b1
  !:
    jmp __breturn
    // main::@return
  __breturn:
    // [7] return 
    rts
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [9] call fn1 
    // [12] phi from main::@2 to fn1 [phi:main::@2->fn1]
  fn1_from___b2:
    jsr fn1
    // [10] *((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
    // [11] (byte*) main::cols#1 ← ++ (byte*) main::cols#2 -- pbuz1=_inc_pbuz1 
    inc.z cols
    bne !+
    inc.z cols+1
  !:
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (byte*) main::cols#2 = (byte*) main::cols#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // fn1
fn1: {
    .label screen = 4
    // [13] phi from fn1 to fn1::@1 [phi:fn1->fn1::@1]
  __b1_from_fn1:
    // [13] phi (byte*) fn1::screen#2 = (byte*) 1024 [phi:fn1->fn1::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    jmp __b1
    // fn1::@1
  __b1:
    // [14] if((byte*) fn1::screen#2<(word)(number) $400+(number) $3e8) goto fn1::@2 -- pbuz1_lt_vwuc1_then_la1 
    lda.z screen+1
    cmp #>$400+$3e8
    bcc __b2
    bne !+
    lda.z screen
    cmp #<$400+$3e8
    bcc __b2
  !:
    jmp __breturn
    // fn1::@return
  __breturn:
    // [15] return 
    rts
    // fn1::@2
  __b2:
    // [16] *((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
    // [17] (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#2 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [13] phi from fn1::@2 to fn1::@1 [phi:fn1::@2->fn1::@1]
  __b1_from___b2:
    // [13] phi (byte*) fn1::screen#2 = (byte*) fn1::screen#1 [phi:fn1::@2->fn1::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] if((byte*) main::cols#2<(word)(number) $d800+(number) $3e8) goto main::@2 [ main::cols#2 ] ( main:2 [ main::cols#2 ] ) always clobbers reg byte a 
Statement [10] *((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 [14] if((byte*) fn1::screen#2<(word)(number) $400+(number) $3e8) goto fn1::@2 [ fn1::screen#2 ] ( main:2::fn1:9 [ main::cols#2 fn1::screen#2 ] ) always clobbers reg byte a 
Statement [16] *((byte*) fn1::screen#2) ← ++ *((byte*) fn1::screen#2) [ fn1::screen#2 ] ( main:2::fn1:9 [ main::cols#2 fn1::screen#2 ] ) always clobbers reg byte a reg byte y 
Potential registers zp[2]:2 [ main::cols#2 main::cols#1 ] : zp[2]:2 , 
Potential registers zp[2]:4 [ fn1::screen#2 fn1::screen#1 ] : zp[2]:4 , 

REGISTER UPLIFT SCOPES
Uplift Scope [fn1] 370.33: zp[2]:4 [ fn1::screen#2 fn1::screen#1 ] 
Uplift Scope [main] 33: zp[2]:2 [ main::cols#2 main::cols#1 ] 
Uplift Scope [] 

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

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests calling into a function pointer with local variables
  // 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.z cols
    lda #>$d800
    sta.z cols+1
    jmp __b1
    // main::@1
  __b1:
    // [6] if((byte*) main::cols#2<(word)(number) $d800+(number) $3e8) goto main::@2 -- pbuz1_lt_vwuc1_then_la1 
    lda.z cols+1
    cmp #>$d800+$3e8
    bcc __b2_from___b1
    bne !+
    lda.z cols
    cmp #<$d800+$3e8
    bcc __b2_from___b1
  !:
    jmp __breturn
    // main::@return
  __breturn:
    // [7] return 
    rts
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [9] call fn1 
    // [12] phi from main::@2 to fn1 [phi:main::@2->fn1]
  fn1_from___b2:
    jsr fn1
    // [10] *((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
    // [11] (byte*) main::cols#1 ← ++ (byte*) main::cols#2 -- pbuz1=_inc_pbuz1 
    inc.z cols
    bne !+
    inc.z cols+1
  !:
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [5] phi (byte*) main::cols#2 = (byte*) main::cols#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // fn1
fn1: {
    .label screen = 4
    // [13] phi from fn1 to fn1::@1 [phi:fn1->fn1::@1]
  __b1_from_fn1:
    // [13] phi (byte*) fn1::screen#2 = (byte*) 1024 [phi:fn1->fn1::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    jmp __b1
    // fn1::@1
  __b1:
    // [14] if((byte*) fn1::screen#2<(word)(number) $400+(number) $3e8) goto fn1::@2 -- pbuz1_lt_vwuc1_then_la1 
    lda.z screen+1
    cmp #>$400+$3e8
    bcc __b2
    bne !+
    lda.z screen
    cmp #<$400+$3e8
    bcc __b2
  !:
    jmp __breturn
    // fn1::@return
  __breturn:
    // [15] return 
    rts
    // fn1::@2
  __b2:
    // [16] *((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
    // [17] (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#2 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [13] phi from fn1::@2 to fn1::@1 [phi:fn1::@2->fn1::@1]
  __b1_from___b2:
    // [13] phi (byte*) fn1::screen#2 = (byte*) fn1::screen#1 [phi:fn1::@2->fn1::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __b2
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 __bbegin with __b1
Replacing label __b2_from___b1 with __b2
Replacing label __b2_from___b1 with __b2
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b2_from___b1:
Removing instruction fn1_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Removing instruction __b1_from_fn1:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
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
(void()) fn1()
(label) fn1::@1
(label) fn1::@2
(label) fn1::@return
(byte*) fn1::screen
(byte*) fn1::screen#1 screen zp[2]:4 202.0
(byte*) fn1::screen#2 screen zp[2]:4 168.33333333333331
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(byte*) main::cols
(byte*) main::cols#1 cols zp[2]:2 22.0
(byte*) main::cols#2 cols zp[2]:2 11.0

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


FINAL ASSEMBLER
Score: 6673

  // File Comments
// Tests calling into a function pointer with local variables
  // 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.z cols
    lda #>$d800
    sta.z cols+1
    // main::@1
  __b1:
    // for(byte* cols = $d800; cols<$d800+1000;cols++)
    // [6] if((byte*) main::cols#2<(word)(number) $d800+(number) $3e8) goto main::@2 -- pbuz1_lt_vwuc1_then_la1 
    lda.z cols+1
    cmp #>$d800+$3e8
    bcc __b2
    bne !+
    lda.z cols
    cmp #<$d800+$3e8
    bcc __b2
  !:
    // main::@return
    // }
    // [7] return 
    rts
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // main::@2
  __b2:
    // (*cls)()
    // [9] call fn1 
    // [12] phi from main::@2 to fn1 [phi:main::@2->fn1]
    jsr fn1
    // (*cols)++;
    // [10] *((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++)
    // [11] (byte*) main::cols#1 ← ++ (byte*) main::cols#2 -- pbuz1=_inc_pbuz1 
    inc.z cols
    bne !+
    inc.z cols+1
  !:
    // [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [5] phi (byte*) main::cols#2 = (byte*) main::cols#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // fn1
fn1: {
    .label screen = 4
    // [13] phi from fn1 to fn1::@1 [phi:fn1->fn1::@1]
    // [13] phi (byte*) fn1::screen#2 = (byte*) 1024 [phi:fn1->fn1::@1#0] -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // fn1::@1
  __b1:
    // for(byte* screen=$400;screen<$400+1000;screen++)
    // [14] if((byte*) fn1::screen#2<(word)(number) $400+(number) $3e8) goto fn1::@2 -- pbuz1_lt_vwuc1_then_la1 
    lda.z screen+1
    cmp #>$400+$3e8
    bcc __b2
    bne !+
    lda.z screen
    cmp #<$400+$3e8
    bcc __b2
  !:
    // fn1::@return
    // }
    // [15] return 
    rts
    // fn1::@2
  __b2:
    // (*screen)++;
    // [16] *((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++)
    // [17] (byte*) fn1::screen#1 ← ++ (byte*) fn1::screen#2 -- pbuz1=_inc_pbuz1 
    inc.z screen
    bne !+
    inc.z screen+1
  !:
    // [13] phi from fn1::@2 to fn1::@1 [phi:fn1::@2->fn1::@1]
    // [13] phi (byte*) fn1::screen#2 = (byte*) fn1::screen#1 [phi:fn1::@2->fn1::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

