Resolved forward reference fn1 to char fn1()
Resolved forward reference fn2 to char fn2()
Setting inferred __stackcall on procedure affected by address-of __stackcall char fn1() caused by statement main::f = &fn1
Setting inferred __stackcall on procedure affected by address-of __stackcall char fn2() caused by statement main::f = &fn2
Calling convention STACK_CALL adding stack return stackidx(char,fn1::OFFSET_STACK_RETURN_0) = fn1::return
Calling convention STACK_CALL adding stack return stackidx(char,fn2::OFFSET_STACK_RETURN_0) = fn2::return

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::f#0 = (char (*)()) 0
  main::i#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@4
  main::i#3 = phi( main/main::i#0, main::@4/main::i#4 )
  if(true) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  main::i#2 = phi( main::@1/main::i#3 )
  main::i#1 = ++ main::i#2
  main::$0 = main::i#1 & 1
  main::$1 = main::$0 == 0
  if(main::$1) goto main::@3
  to:main::@5
main::@3: scope:[main]  from main::@2
  main::i#5 = phi( main::@2/main::i#1 )
  main::f#1 = &fn1
  to:main::@4
main::@5: scope:[main]  from main::@2
  main::i#6 = phi( main::@2/main::i#1 )
  main::f#2 = &fn2
  to:main::@4
main::@4: scope:[main]  from main::@3 main::@5
  main::i#4 = phi( main::@3/main::i#5, main::@5/main::i#6 )
  main::f#3 = phi( main::@3/main::f#1, main::@5/main::f#2 )
  main::SCREEN[0] = (char)main::f#3
  to:main::@1
main::@return: scope:[main]  from main::@1
  return 
  to:@return

__stackcall char fn1()
fn1: scope:[fn1]  from
  *fn1::BORDER_COLOR = ++ *fn1::BORDER_COLOR
  fn1::return#0 = *fn1::BORDER_COLOR
  to:fn1::@return
fn1::@return: scope:[fn1]  from fn1
  fn1::return#2 = phi( fn1/fn1::return#0 )
  fn1::return#1 = fn1::return#2
  stackidx(char,fn1::OFFSET_STACK_RETURN_0) = fn1::return#1
  return 
  to:@return

__stackcall char fn2()
fn2: scope:[fn2]  from
  *fn2::BG_COLOR = ++ *fn2::BG_COLOR
  fn2::return#0 = *fn2::BG_COLOR
  to:fn2::@return
fn2::@return: scope:[fn2]  from fn2
  fn2::return#2 = phi( fn2/fn2::return#0 )
  fn2::return#1 = fn2::return#2
  stackidx(char,fn2::OFFSET_STACK_RETURN_0) = fn2::return#1
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  call main
  to:__start::@1
__start::@1: scope:[__start]  from __start
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  return 
  to:@return

SYMBOL TABLE SSA
__constant unsigned int STACK_BASE = $103
void __start()
__stackcall char fn1()
__constant char * const fn1::BORDER_COLOR = (char *)$d020
__constant char fn1::OFFSET_STACK_RETURN_0 = 0
char fn1::return
char fn1::return#0
char fn1::return#1
char fn1::return#2
__stackcall char fn2()
__constant char * const fn2::BG_COLOR = (char *)$d021
__constant char fn2::OFFSET_STACK_RETURN_0 = 0
char fn2::return
char fn2::return#0
char fn2::return#1
char fn2::return#2
void main()
number main::$0
bool main::$1
__constant char * const main::SCREEN = (char *)$400
char (*main::f)()
char (*main::f#0)()
char (*main::f#1)()
char (*main::f#2)()
char (*main::f#3)()
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i#3
char main::i#4
char main::i#5
char main::i#6

Adding number conversion cast (unumber) 1 in main::$0 = main::i#1 & 1
Adding number conversion cast (unumber) main::$0 in main::$0 = main::i#1 & (unumber)1
Adding number conversion cast (unumber) 0 in main::$1 = main::$0 == 0
Adding number conversion cast (unumber) 0 in main::SCREEN[0] = (char)main::f#3
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant pointer cast (char *) 53280
Simplifying constant pointer cast (char *) 53281
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$0 = main::i#1 & 1
Alias main::i#2 = main::i#3 
Alias main::i#1 = main::i#5 main::i#6 
Alias fn1::return#0 = fn1::return#2 fn1::return#1 
Alias fn2::return#0 = fn2::return#2 fn2::return#1 
Successful SSA optimization Pass2AliasElimination
Alias main::i#1 = main::i#4 
Successful SSA optimization Pass2AliasElimination
Simple Condition main::$1 [7] if(main::$0==0) goto main::@3
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::f#0 = (char (*)()) 0
Constant main::i#0 = 0
Constant main::f#1 = &fn1
Constant main::f#2 = &fn2
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [3] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Simplifying expression containing zero main::SCREEN in [11] main::SCREEN[0] = (char)main::f#3
Successful SSA optimization PassNSimplifyExpressionWithZero
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Eliminating unused constant main::f#0
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Inlining constant with var siblings main::i#0
Inlining constant with var siblings main::f#1
Inlining constant with var siblings main::f#2
Constant inlined main::i#0 = 0
Constant inlined main::f#2 = &fn2
Constant inlined main::f#1 = &fn1
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@5
Adding NOP phi() at start of main::@3
CALL GRAPH

Created 2 initial phi equivalence classes
Coalesced [16] main::i#7 = main::i#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@5
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3

FINAL CONTROL FLOW GRAPH

__stackcall char fn2()
fn2: scope:[fn2]  from
  [0] *fn2::BG_COLOR = ++ *fn2::BG_COLOR
  [1] fn2::return#0 = *fn2::BG_COLOR
  to:fn2::@return
fn2::@return: scope:[fn2]  from fn2
  [2] stackidx(char,fn2::OFFSET_STACK_RETURN_0) = fn2::return#0
  [3] return 
  to:@return

__stackcall char fn1()
fn1: scope:[fn1]  from
  [4] *fn1::BORDER_COLOR = ++ *fn1::BORDER_COLOR
  [5] fn1::return#0 = *fn1::BORDER_COLOR
  to:fn1::@return
fn1::@return: scope:[fn1]  from fn1
  [6] stackidx(char,fn1::OFFSET_STACK_RETURN_0) = fn1::return#0
  [7] return 
  to:@return

void main()
main: scope:[main]  from
  [8] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@4
  [9] main::i#2 = phi( main/0, main::@4/main::i#1 )
  to:main::@2
main::@2: scope:[main]  from main::@1
  [10] main::i#1 = ++ main::i#2
  [11] main::$0 = main::i#1 & 1
  [12] if(main::$0==0) goto main::@3
  to:main::@4
main::@3: scope:[main]  from main::@2
  [13] phi()
  to:main::@4
main::@4: scope:[main]  from main::@2 main::@3
  [14] main::f#3 = phi( main::@3/&fn1, main::@2/&fn2 )
  [15] *main::SCREEN = (char)main::f#3
  to:main::@1


VARIABLE REGISTER WEIGHTS
__stackcall char fn1()
char fn1::return
char fn1::return#0 // 4.0
__stackcall char fn2()
char fn2::return
char fn2::return#0 // 4.0
void main()
char main::$0 // 22.0
char (*main::f)()
char (*main::f#3)()
char main::i
char main::i#1 // 5.5
char main::i#2 // 22.0

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::f#3 ]
Added variable fn2::return#0 to live range equivalence class [ fn2::return#0 ]
Added variable fn1::return#0 to live range equivalence class [ fn1::return#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::f#3 ]
[ fn2::return#0 ]
[ fn1::return#0 ]
[ main::$0 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ main::$0 ]
Allocated zp[1]:4 [ fn2::return#0 ]
Allocated zp[1]:5 [ fn1::return#0 ]
Allocated zp[2]:6 [ main::f#3 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] stackidx(char,fn2::OFFSET_STACK_RETURN_0) = fn2::return#0 [ ] (  [ ] { }  ) always clobbers reg byte x 
Statement [6] stackidx(char,fn1::OFFSET_STACK_RETURN_0) = fn1::return#0 [ ] (  [ ] { }  ) always clobbers reg byte x 
Statement [15] *main::SCREEN = (char)main::f#3 [ main::i#1 ] (  [ main::i#1 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [2] stackidx(char,fn2::OFFSET_STACK_RETURN_0) = fn2::return#0 [ ] (  [ ] { }  ) always clobbers reg byte x 
Statement [6] stackidx(char,fn1::OFFSET_STACK_RETURN_0) = fn1::return#0 [ ] (  [ ] { }  ) always clobbers reg byte x 
Statement [11] main::$0 = main::i#1 & 1 [ main::i#1 main::$0 ] (  [ main::i#1 main::$0 ] { }  ) always clobbers reg byte a 
Statement [15] *main::SCREEN = (char)main::f#3 [ main::i#1 ] (  [ main::i#1 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[2]:6 [ main::f#3 ] : zp[2]:6 , 
Potential registers zp[1]:4 [ fn2::return#0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ fn1::return#0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::$0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 27.5: zp[1]:2 [ main::i#2 main::i#1 ] 22: zp[1]:3 [ main::$0 ] 0: zp[2]:6 [ main::f#3 ] 
Uplift Scope [fn1] 4: zp[1]:5 [ fn1::return#0 ] 
Uplift Scope [fn2] 4: zp[1]:4 [ fn2::return#0 ] 
Uplift Scope [] 

Uplifting [main] best 639 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$0 ] zp[2]:6 [ main::f#3 ] 
Uplifting [fn1] best 633 combination reg byte a [ fn1::return#0 ] 
Uplifting [fn2] best 627 combination reg byte a [ fn2::return#0 ] 
Uplifting [] best 627 combination 
Allocated (was zp[2]:6) zp[2]:2 [ main::f#3 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests creating and assigning pointers to non-args return with function value
  // Upstart
  // Commodore 64 PRG executable file
.file [name="function-pointer-return.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .const STACK_BASE = $103
.segment Code
  // fn2
fn2: {
    .const OFFSET_STACK_RETURN_0 = 0
    .label BG_COLOR = $d021
    // [0] *fn2::BG_COLOR = ++ *fn2::BG_COLOR -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BG_COLOR
    // [1] fn2::return#0 = *fn2::BG_COLOR -- vbuaa=_deref_pbuc1 
    lda BG_COLOR
    jmp __breturn
    // fn2::@return
  __breturn:
    // [2] stackidx(char,fn2::OFFSET_STACK_RETURN_0) = fn2::return#0 -- _stackidxbyte_vbuc1=vbuaa 
    tsx
    sta STACK_BASE+OFFSET_STACK_RETURN_0,x
    // [3] return 
    rts
}
  // fn1
fn1: {
    .const OFFSET_STACK_RETURN_0 = 0
    .label BORDER_COLOR = $d020
    // [4] *fn1::BORDER_COLOR = ++ *fn1::BORDER_COLOR -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BORDER_COLOR
    // [5] fn1::return#0 = *fn1::BORDER_COLOR -- vbuaa=_deref_pbuc1 
    lda BORDER_COLOR
    jmp __breturn
    // fn1::@return
  __breturn:
    // [6] stackidx(char,fn1::OFFSET_STACK_RETURN_0) = fn1::return#0 -- _stackidxbyte_vbuc1=vbuaa 
    tsx
    sta STACK_BASE+OFFSET_STACK_RETURN_0,x
    // [7] return 
    rts
}
  // main
main: {
    .label SCREEN = $400
    .label f = 2
    // [9] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [9] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // main::@1
  __b1:
    jmp __b2
    // main::@2
  __b2:
    // [10] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [11] main::$0 = main::i#1 & 1 -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #1
    // [12] if(main::$0==0) goto main::@3 -- vbuaa_eq_0_then_la1 
    cmp #0
    beq __b3_from___b2
    // [14] phi from main::@2 to main::@4 [phi:main::@2->main::@4]
  __b4_from___b2:
    // [14] phi main::f#3 = &fn2 [phi:main::@2->main::@4#0] -- pprz1=pprc1 
    lda #<fn2
    sta.z f
    lda #>fn2
    sta.z f+1
    jmp __b4
    // [13] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
  __b3_from___b2:
    jmp __b3
    // main::@3
  __b3:
    // [14] phi from main::@3 to main::@4 [phi:main::@3->main::@4]
  __b4_from___b3:
    // [14] phi main::f#3 = &fn1 [phi:main::@3->main::@4#0] -- pprz1=pprc1 
    lda #<fn1
    sta.z f
    lda #>fn1
    sta.z f+1
    jmp __b4
    // main::@4
  __b4:
    // [15] *main::SCREEN = (char)main::f#3 -- _deref_pbuc1=_byte_pprz1 
    lda.z f
    sta SCREEN
    // [9] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  __b1_from___b4:
    // [9] phi main::i#2 = main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Removing instruction jmp __b4
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b3_from___b2 with __b3
Replacing label __b1 with __b2
Removing instruction __b1:
Removing instruction __b3_from___b2:
Removing instruction __b4_from___b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __breturn:
Removing instruction __breturn:
Removing instruction __b1_from_main:
Removing instruction __b4_from___b2:
Removing instruction __b1_from___b4:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant unsigned int STACK_BASE = $103
__stackcall char fn1()
__constant char * const fn1::BORDER_COLOR = (char *) 53280
__constant char fn1::OFFSET_STACK_RETURN_0 = 0
char fn1::return
char fn1::return#0 // reg byte a 4.0
__stackcall char fn2()
__constant char * const fn2::BG_COLOR = (char *) 53281
__constant char fn2::OFFSET_STACK_RETURN_0 = 0
char fn2::return
char fn2::return#0 // reg byte a 4.0
void main()
char main::$0 // reg byte a 22.0
__constant char * const main::SCREEN = (char *) 1024
char (*main::f)()
char (*main::f#3)() // f zp[2]:2
char main::i
char main::i#1 // reg byte x 5.5
char main::i#2 // reg byte x 22.0

reg byte x [ main::i#2 main::i#1 ]
zp[2]:2 [ main::f#3 ]
reg byte a [ fn2::return#0 ]
reg byte a [ fn1::return#0 ]
reg byte a [ main::$0 ]


FINAL ASSEMBLER
Score: 501

  // File Comments
// Tests creating and assigning pointers to non-args return with function value
  // Upstart
  // Commodore 64 PRG executable file
.file [name="function-pointer-return.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .const STACK_BASE = $103
.segment Code
  // fn2
fn2: {
    .const OFFSET_STACK_RETURN_0 = 0
    .label BG_COLOR = $d021
    // (*BG_COLOR)++;
    // [0] *fn2::BG_COLOR = ++ *fn2::BG_COLOR -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BG_COLOR
    // return *BG_COLOR;
    // [1] fn2::return#0 = *fn2::BG_COLOR -- vbuaa=_deref_pbuc1 
    lda BG_COLOR
    // fn2::@return
    // }
    // [2] stackidx(char,fn2::OFFSET_STACK_RETURN_0) = fn2::return#0 -- _stackidxbyte_vbuc1=vbuaa 
    tsx
    sta STACK_BASE+OFFSET_STACK_RETURN_0,x
    // [3] return 
    rts
}
  // fn1
fn1: {
    .const OFFSET_STACK_RETURN_0 = 0
    .label BORDER_COLOR = $d020
    // (*BORDER_COLOR)++;
    // [4] *fn1::BORDER_COLOR = ++ *fn1::BORDER_COLOR -- _deref_pbuc1=_inc__deref_pbuc1 
    inc BORDER_COLOR
    // return *BORDER_COLOR;
    // [5] fn1::return#0 = *fn1::BORDER_COLOR -- vbuaa=_deref_pbuc1 
    lda BORDER_COLOR
    // fn1::@return
    // }
    // [6] stackidx(char,fn1::OFFSET_STACK_RETURN_0) = fn1::return#0 -- _stackidxbyte_vbuc1=vbuaa 
    tsx
    sta STACK_BASE+OFFSET_STACK_RETURN_0,x
    // [7] return 
    rts
}
  // main
main: {
    .label SCREEN = $400
    .label f = 2
    // [9] phi from main to main::@1 [phi:main->main::@1]
    // [9] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // main::@1
    // main::@2
  __b2:
    // ++i;
    // [10] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // i&1
    // [11] main::$0 = main::i#1 & 1 -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #1
    // if((i&1)==0)
    // [12] if(main::$0==0) goto main::@3 -- vbuaa_eq_0_then_la1 
    cmp #0
    beq __b3
    // [14] phi from main::@2 to main::@4 [phi:main::@2->main::@4]
    // [14] phi main::f#3 = &fn2 [phi:main::@2->main::@4#0] -- pprz1=pprc1 
    lda #<fn2
    sta.z f
    lda #>fn2
    sta.z f+1
    jmp __b4
    // [13] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
    // main::@3
  __b3:
    // [14] phi from main::@3 to main::@4 [phi:main::@3->main::@4]
    // [14] phi main::f#3 = &fn1 [phi:main::@3->main::@4#0] -- pprz1=pprc1 
    lda #<fn1
    sta.z f
    lda #>fn1
    sta.z f+1
    // main::@4
  __b4:
    // SCREEN[0] = (byte)f
    // [15] *main::SCREEN = (char)main::f#3 -- _deref_pbuc1=_byte_pprz1 
    lda.z f
    sta SCREEN
    // [9] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
    // [9] phi main::i#2 = main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    jmp __b2
}
  // File Data

