Identified constant variable (void()*) main::f
Culled Empty Block (label) @1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte) idx ← (byte) 0
  to:@2

(void()) fn1()
fn1: scope:[fn1]  from
  (byte) idx ← ++ (byte) idx
  to:fn1::@return
fn1::@return: scope:[fn1]  from fn1
  return 
  to:@return

(void()) main()
main: scope:[main]  from @2
  call *((const void()*) main::f) 
  *((const byte*) SCREEN + (byte) idx) ← (byte) 'a'
  call *((const void()*) main::f) 
  *((const byte*) SCREEN + (byte) idx) ← (byte) 'a'
  to:main::@return
main::@return: scope:[main]  from main
  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
(const byte*) SCREEN = (byte*)(number) $400
(void()) fn1()
(label) fn1::@return
(byte) idx loadstore
(void()) main()
(label) main::@return
(const void()*) main::f = &(void()) fn1()

Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Replacing constant pointer function [3] call fn1 
Replacing constant pointer function [5] call fn1 
Successful SSA optimization Pass2ConstantCallPointerIdentification
Eliminating unused constant (const void()*) main::f
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 ← (byte) 0
  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()
  [5] call fn1 
  [6] *((const byte*) SCREEN + (byte) idx) ← (byte) 'a'
  [7] call fn1 
  [8] *((const byte*) SCREEN + (byte) idx) ← (byte) 'a'
  to:main::@return
main::@return: scope:[main]  from main
  [9] return 
  to:@return

(void()) fn1()
fn1: scope:[fn1]  from main
  [10] (byte) idx ← ++ (byte) idx
  to:fn1::@return
fn1::@return: scope:[fn1]  from fn1
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) fn1()
(byte) idx loadstore 2.5
(void()) main()

Initial phi equivalence classes
Added variable idx to live range equivalence class [ idx ]
Complete equivalence classes
[ idx ]
Allocated zp[1]:2 [ idx ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // 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 ← (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 + (byte) idx) ← (byte) 'a' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'a'
    ldy.z idx
    sta SCREEN,y
    // [7] call fn1 
    jsr fn1
    // [8] *((const byte*) SCREEN + (byte) idx) ← (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 ← ++ (byte) idx -- vbuz1=_inc_vbuz1 
    inc.z idx
    jmp __breturn
    // fn1::@return
  __breturn:
    // [11] return 
    rts
}
  // File Data

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

REGISTER UPLIFT SCOPES
Uplift Scope [] 2.5: zp[1]:2 [ idx ] 
Uplift Scope [fn1] 
Uplift Scope [main] 

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

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 ← (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 + (byte) idx) ← (byte) 'a' -- pbuc1_derefidx_vbuz1=vbuc2 
    lda #'a'
    ldy.z idx
    sta SCREEN,y
    // [7] call fn1 
    jsr fn1
    // [8] *((const byte*) SCREEN + (byte) idx) ← (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 ← ++ (byte) idx -- 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
(const byte*) SCREEN = (byte*) 1024
(void()) fn1()
(label) fn1::@return
(byte) idx loadstore zp[1]:2 2.5
(void()) main()
(label) main::@return

zp[1]:2 [ idx ]


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 ← (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 + (byte) idx) ← (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 + (byte) idx) ← (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 ← ++ (byte) idx -- vbuz1=_inc_vbuz1 
    inc.z idx
    // fn1::@return
    // }
    // [11] return 
    rts
}
  // File Data

