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

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (number) $400
  (byte) idx#0 ← (number) 0
  to:@2
main: scope:[main]  from @2
  (byte) idx#3 ← phi( @2/(byte) idx#6 )
  (void()*~) main::$0 ← & (void()) fn1()
  (void()*) main::f#0 ← (void()*~) main::$0
  call *((void()*) main::f#0) 
  *((byte*) SCREEN#0 + (byte) idx#3) ← (byte) 'a'
  call *((void()*) main::f#0) 
  *((byte*) SCREEN#0 + (byte) idx#3) ← (byte) 'a'
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
fn1: scope:[fn1]  from
  (byte) idx#4 ← phi( @2/(byte) idx#6 )
  (byte) idx#1 ← ++ (byte) idx#4
  to:fn1::@return
fn1::@return: scope:[fn1]  from fn1
  (byte) idx#5 ← phi( fn1/(byte) idx#1 )
  (byte) idx#2 ← (byte) idx#5
  return 
  to:@return
@2: scope:[]  from @begin
  (byte) idx#6 ← phi( @begin/(byte) idx#0 )
  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
(byte*) SCREEN
(byte*) SCREEN#0
(void()) fn1()
(label) fn1::@return
(byte) idx
(byte) idx#0
(byte) idx#1
(byte) idx#2
(byte) idx#3
(byte) idx#4
(byte) idx#5
(byte) idx#6
(void()) main()
(void()*~) main::$0
(label) main::@return
(void()*) main::f
(void()*) main::f#0

Adding number conversion cast (unumber) 0 in (byte) idx#0 ← (number) 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Inlining cast (byte) idx#0 ← (unumber)(number) 0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (void()*) main::f#0 = (void()*~) main::$0 
Alias (byte) idx#1 = (byte) idx#5 (byte) idx#2 
Alias (byte) idx#0 = (byte) idx#6 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) idx#3 (byte) idx#0
Identical Phi Values (byte) idx#4 (byte) idx#0
Successful SSA optimization Pass2IdenticalPhiElimination
Constant right-side identified [3] (void()*) main::f#0 ← & (void()) fn1()
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) SCREEN#0 = (byte*) 1024
Constant (const void()*) main::f#0 = &fn1
Successful SSA optimization Pass2ConstantIdentification
Replacing constant pointer function [5] call fn1 
Replacing constant pointer function [7] call fn1 
Successful SSA optimization Pass2ConstantCallPointerIdentification
Eliminating unused constant (const void()*) main::f#0
Successful SSA optimization PassNEliminateUnusedVars
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 fn1:6 fn1:8 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @3
Renumbering block @2 to @1
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] (byte) idx#0 ← (byte) 0
  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 fn1 
  [6] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a'
  [7] call fn1 
  [8] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a'
  to:main::@return
main::@return: scope:[main]  from main
  [9] return 
  to:@return
fn1: scope:[fn1]  from main
  [10] (byte) idx#1 ← ++ (byte) idx#0
  to:fn1::@return
fn1::@return: scope:[fn1]  from fn1
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(void()) fn1()
(byte) idx
(byte) idx#0 1.0
(byte) idx#1 20.0
(void()) main()
(void()*) main::f

Initial phi equivalence classes
Coalescing volatile variable equivalence classes [ idx#0 ] and [ idx#1 ]
Complete equivalence classes
[ idx#0 idx#1 ]
Allocated zp ZP_BYTE:2 [ idx#0 idx#1 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
// Tests calling into a function pointer which modifies global volatile
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label idx = 2
  // @begin
bbegin:
  // [0] (byte) idx#0 ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta.z idx
  // [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 fn1 
    jsr fn1
    // [6] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'a'
    ldy.z idx
    sta SCREEN,y
    // [7] call fn1 
    jsr fn1
    // [8] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'a'
    ldy.z idx
    sta SCREEN,y
    jmp breturn
    // main::@return
  breturn:
    // [9] return 
    rts
}
  // fn1
fn1: {
    // [10] (byte) idx#1 ← ++ (byte) idx#0 -- vbuz1=_inc_vbuz1 
    inc.z idx
    jmp breturn
    // fn1::@return
  breturn:
    // [11] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (byte) idx#0 ← (byte) 0 [ idx#0 ] (  [ idx#0 ] ) always clobbers reg byte a 
Statement [6] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a' [ idx#0 ] ( main:2 [ idx#0 ] ) always clobbers reg byte a reg byte y 
Statement [8] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a' [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y 
Potential registers zp ZP_BYTE:2 [ idx#0 idx#1 ] : zp ZP_BYTE:2 , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 21: zp ZP_BYTE:2 [ idx#0 idx#1 ] 
Uplift Scope [main] 
Uplift Scope [fn1] 

Uplifting [] best 72 combination zp ZP_BYTE:2 [ idx#0 idx#1 ] 
Uplifting [main] best 72 combination 
Uplifting [fn1] best 72 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:2 [ idx#0 idx#1 ]
Uplifting [] best 72 combination zp ZP_BYTE:2 [ idx#0 idx#1 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests calling into a function pointer which modifies global volatile
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label idx = 2
  // @begin
bbegin:
  // [0] (byte) idx#0 ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta.z idx
  // [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 fn1 
    jsr fn1
    // [6] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'a'
    ldy.z idx
    sta SCREEN,y
    // [7] call fn1 
    jsr fn1
    // [8] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'a'
    ldy.z idx
    sta SCREEN,y
    jmp breturn
    // main::@return
  breturn:
    // [9] return 
    rts
}
  // fn1
fn1: {
    // [10] (byte) idx#1 ← ++ (byte) idx#0 -- vbuz1=_inc_vbuz1 
    inc.z idx
    jmp breturn
    // fn1::@return
  breturn:
    // [11] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction b1_from_bbegin:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b1:
Removing instruction bend:
Removing instruction breturn:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Adding RTS to root block 
Succesful ASM optimization Pass5AddMainRts

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (byte*) 1024
(void()) fn1()
(label) fn1::@return
(byte) idx
(byte) idx#0 idx zp ZP_BYTE:2 1.0
(byte) idx#1 idx zp ZP_BYTE:2 20.0
(void()) main()
(label) main::@return
(void()*) main::f

zp ZP_BYTE:2 [ idx#0 idx#1 ]


FINAL ASSEMBLER
Score: 66

  // File Comments
// Tests calling into a function pointer which modifies global volatile
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label idx = 2
  // @begin
bbegin:
  // idx = 0
  // [0] (byte) idx#0 ← (byte) 0 -- vbuz1=vbuc1 
  lda #0
  sta.z idx
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
  jsr main
  rts
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    // (*f)()
    // [5] call fn1 
    jsr fn1
    // SCREEN[idx] = 'a'
    // [6] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'a'
    ldy.z idx
    sta SCREEN,y
    // (*f)()
    // [7] call fn1 
    jsr fn1
    // SCREEN[idx] = 'a'
    // [8] *((const byte*) SCREEN#0 + (byte) idx#0) ← (byte) 'a' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'a'
    ldy.z idx
    sta SCREEN,y
    // main::@return
    // }
    // [9] return 
    rts
}
  // fn1
fn1: {
    // idx++;
    // [10] (byte) idx#1 ← ++ (byte) idx#0 -- vbuz1=_inc_vbuz1 
    inc.z idx
    // fn1::@return
    // }
    // [11] return 
    rts
}
  // File Data

