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

(void()) main()
main: scope:[main]  from @1
  (word) main::u#0 ← (word) $22b
  (word~) main::$0 ← *((word*)(number) $a0) - (word) main::u#0
  (word) main::u#1 ← (word~) main::$0
  *((word*)(number) $400) ← (word) main::u#1
  (byte*~) main::$1 ← *((byte**)(number) $d1) + (number) $d400
  *((byte**)(number) $f3) ← (byte*~) main::$1
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(void()) main()
(word~) main::$0
(byte*~) main::$1
(label) main::@return
(word) main::u
(word) main::u#0
(word) main::u#1

Adding number conversion cast (unumber) $d400 in (byte*~) main::$1 ← *((byte**)(number) $d1) + (number) $d400
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (word*) 160
Simplifying constant pointer cast (word*) 1024
Simplifying constant pointer cast (byte**) 209
Simplifying constant integer cast $d400
Simplifying constant pointer cast (byte**) 243
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $d400
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (word) main::u#1 = (word~) main::$0 
Successful SSA optimization Pass2AliasElimination
Constant (const word) main::u#0 = $22b
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const word) main::u#0
Constant inlined main::u#0 = (word) $22b
Successful SSA optimization Pass2ConstantInlining
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2 

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

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] (word) main::u#1 ← *((word*) 160) - (word) $22b
  [5] *((word*) 1024) ← (word) main::u#1
  [6] (byte*~) main::$1 ← *((byte**) 209) + (word) $d400
  [7] *((byte**) 243) ← (byte*~) main::$1
  to:main::@return
main::@return: scope:[main]  from main
  [8] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte*~) main::$1 4.0
(word) main::u
(word) main::u#1 4.0

Initial phi equivalence classes
Added variable main::u#1 to live range equivalence class [ main::u#1 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Complete equivalence classes
[ main::u#1 ]
[ main::$1 ]
Allocated zp[2]:2 [ main::u#1 ]
Allocated zp[2]:4 [ main::$1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test some forced zeropage access
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label __1 = 4
    .label u = 2
    // [4] (word) main::u#1 ← *((word*) 160) - (word) $22b -- vwuz1=_deref_pwuc1_minus_vwuc2 
    sec
    lda $a0
    sbc #<$22b
    sta.z u
    lda $a0+1
    sbc #>$22b
    sta.z u+1
    // [5] *((word*) 1024) ← (word) main::u#1 -- _deref_pwuc1=vwuz1 
    lda.z u
    sta $400
    lda.z u+1
    sta $400+1
    // [6] (byte*~) main::$1 ← *((byte**) 209) + (word) $d400 -- pbuz1=_deref_pptc1_plus_vwuc2 
    clc
    lda $d1
    adc #<$d400
    sta.z __1
    lda $d1+1
    adc #>$d400
    sta.z __1+1
    // [7] *((byte**) 243) ← (byte*~) main::$1 -- _deref_pptc1=pbuz1 
    lda.z __1
    sta $f3
    lda.z __1+1
    sta $f3+1
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (word) main::u#1 ← *((word*) 160) - (word) $22b [ main::u#1 ] ( main:2 [ main::u#1 ] ) always clobbers reg byte a 
Statement [5] *((word*) 1024) ← (word) main::u#1 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [6] (byte*~) main::$1 ← *((byte**) 209) + (word) $d400 [ main::$1 ] ( main:2 [ main::$1 ] ) always clobbers reg byte a 
Statement [7] *((byte**) 243) ← (byte*~) main::$1 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Potential registers zp[2]:2 [ main::u#1 ] : zp[2]:2 , 
Potential registers zp[2]:4 [ main::$1 ] : zp[2]:4 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp[2]:2 [ main::u#1 ] 4: zp[2]:4 [ main::$1 ] 
Uplift Scope [] 

Uplifting [main] best 89 combination zp[2]:2 [ main::u#1 ] zp[2]:4 [ main::$1 ] 
Uplifting [] best 89 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test some forced zeropage access
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label __1 = 4
    .label u = 2
    // [4] (word) main::u#1 ← *((word*) 160) - (word) $22b -- vwuz1=_deref_pwuc1_minus_vwuc2 
    sec
    lda $a0
    sbc #<$22b
    sta.z u
    lda $a0+1
    sbc #>$22b
    sta.z u+1
    // [5] *((word*) 1024) ← (word) main::u#1 -- _deref_pwuc1=vwuz1 
    lda.z u
    sta $400
    lda.z u+1
    sta $400+1
    // [6] (byte*~) main::$1 ← *((byte**) 209) + (word) $d400 -- pbuz1=_deref_pptc1_plus_vwuc2 
    clc
    lda $d1
    adc #<$d400
    sta.z __1
    lda $d1+1
    adc #>$d400
    sta.z __1+1
    // [7] *((byte**) 243) ← (byte*~) main::$1 -- _deref_pptc1=pbuz1 
    lda.z __1
    sta $f3
    lda.z __1+1
    sta $f3+1
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __breturn:
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()) main()
(byte*~) main::$1 zp[2]:4 4.0
(label) main::@return
(word) main::u
(word) main::u#1 u zp[2]:2 4.0

zp[2]:2 [ main::u#1 ]
zp[2]:4 [ main::$1 ]


FINAL ASSEMBLER
Score: 74

  // File Comments
// Test some forced zeropage access
  // 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 
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label __1 = 4
    .label u = 2
    // u = *(word *)0xA0 - u
    // [4] (word) main::u#1 ← *((word*) 160) - (word) $22b -- vwuz1=_deref_pwuc1_minus_vwuc2 
    sec
    lda $a0
    sbc #<$22b
    sta.z u
    lda $a0+1
    sbc #>$22b
    sta.z u+1
    // *((word*)0x0400) = u
    // [5] *((word*) 1024) ← (word) main::u#1 -- _deref_pwuc1=vwuz1 
    lda.z u
    sta $400
    lda.z u+1
    sta $400+1
    // *(byte **)0xD1 + 0xD400
    // [6] (byte*~) main::$1 ← *((byte**) 209) + (word) $d400 -- pbuz1=_deref_pptc1_plus_vwuc2 
    clc
    lda $d1
    adc #<$d400
    sta.z __1
    lda $d1+1
    adc #>$d400
    sta.z __1+1
    // *(byte **)0xF3 = *(byte **)0xD1 + 0xD400
    // [7] *((byte**) 243) ← (byte*~) main::$1 -- _deref_pptc1=pbuz1 
    lda.z __1
    sta $f3
    lda.z __1+1
    sta $f3+1
    // main::@return
    // }
    // [8] return 
    rts
}
  // File Data

