Setting inferred volatile on symbol affected by address-of (byte*~) main::$0 ← & (byte) A
Identified constant variable (byte*) SCREEN
Identified constant variable (byte) main::B
Identified constant variable (byte) sub::C
Culled Empty Block (label) @1

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (number) $400
  (byte) A#0 ← (byte) 'a'
  to:@2
main: scope:[main]  from @2
  (byte) A#1 ← phi( @2/(byte) A#3 )
  *((byte*) SCREEN#0 + (number) 0) ← (byte) A#1
  (byte) main::B#0 ← (byte) 'b'
  *((byte*) SCREEN#0 + (number) 1) ← (byte) main::B#0
  (byte*~) main::$0 ← & (byte) A#1
  (byte*) main::addrA#0 ← (byte*~) main::$0
  *((byte*) SCREEN#0 + (number) 2) ← *((byte*) main::addrA#0)
  call sub 
  to:main::@1
main::@1: scope:[main]  from main
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return
sub: scope:[sub]  from main
  (byte) A#2 ← phi( main/(byte) A#1 )
  (byte) sub::C#0 ← (byte) 'c'
  *((byte*) SCREEN#0 + (number) 3) ← (byte) sub::C#0
  (number~) sub::$0 ← (byte) A#2 + (number) 1
  (byte) sub::D#0 ← (number~) sub::$0
  *((byte*) SCREEN#0 + (number) 4) ← (byte) sub::D#0
  to:sub::@return
sub::@return: scope:[sub]  from sub
  return 
  to:@return
@2: scope:[]  from @begin
  (byte) A#3 ← phi( @begin/(byte) A#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) A
(byte) A#0
(byte) A#1
(byte) A#2
(byte) A#3
(byte*) SCREEN
(byte*) SCREEN#0
(void()) main()
(byte*~) main::$0
(label) main::@1
(label) main::@return
(byte) main::B
(byte) main::B#0
(byte*) main::addrA
(byte*) main::addrA#0
(void()) sub()
(number~) sub::$0
(label) sub::@return
(byte) sub::C
(byte) sub::C#0
(byte) sub::D
(byte) sub::D#0

Adding number conversion cast (unumber) 0 in *((byte*) SCREEN#0 + (number) 0) ← (byte) A#1
Adding number conversion cast (unumber) 1 in *((byte*) SCREEN#0 + (number) 1) ← (byte) main::B#0
Adding number conversion cast (unumber) 2 in *((byte*) SCREEN#0 + (number) 2) ← *((byte*) main::addrA#0)
Adding number conversion cast (unumber) 3 in *((byte*) SCREEN#0 + (number) 3) ← (byte) sub::C#0
Adding number conversion cast (unumber) 1 in (number~) sub::$0 ← (byte) A#2 + (number) 1
Adding number conversion cast (unumber) sub::$0 in (number~) sub::$0 ← (byte) A#2 + (unumber)(number) 1
Adding number conversion cast (unumber) 4 in *((byte*) SCREEN#0 + (number) 4) ← (byte) sub::D#0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 3
Simplifying constant integer cast 1
Simplifying constant integer cast 4
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) 3
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) sub::$0 ← (byte) A#2 + (byte) 1
Alias (byte*) main::addrA#0 = (byte*~) main::$0 
Alias (byte) sub::D#0 = (byte~) sub::$0 
Alias (byte) A#0 = (byte) A#3 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) A#1 (byte) A#0
Identical Phi Values (byte) A#2 (byte) A#1
Successful SSA optimization Pass2IdenticalPhiElimination
Constant right-side identified [6] (byte*) main::addrA#0 ← & (byte) A#0
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) SCREEN#0 = (byte*) 1024
Constant (const byte) main::B#0 = 'b'
Constant (const byte*) main::addrA#0 = &A#0
Constant (const byte) sub::C#0 = 'c'
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero SCREEN#0 in [3] *((const byte*) SCREEN#0 + (byte) 0) ← (byte) A#0
Successful SSA optimization PassNSimplifyExpressionWithZero
Consolidated array index constant in *(SCREEN#0+1)
Consolidated array index constant in *(SCREEN#0+2)
Consolidated array index constant in *(SCREEN#0+3)
Consolidated array index constant in *(SCREEN#0+4)
Successful SSA optimization Pass2ConstantAdditionElimination
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::@1
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to sub:8 

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

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] (byte) A#0 ← (byte) 'a'
  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] *((const byte*) SCREEN#0) ← (byte) A#0
  [5] *((const byte*) SCREEN#0+(byte) 1) ← (const byte) main::B#0
  [6] *((const byte*) SCREEN#0+(byte) 2) ← *((const byte*) main::addrA#0)
  [7] call sub 
  to:main::@return
main::@return: scope:[main]  from main
  [8] return 
  to:@return
sub: scope:[sub]  from main
  [9] *((const byte*) SCREEN#0+(byte) 3) ← (const byte) sub::C#0
  [10] (byte) sub::D#0 ← (byte) A#0 + (byte) 1
  [11] *((const byte*) SCREEN#0+(byte) 4) ← (byte) sub::D#0
  to:sub::@return
sub::@return: scope:[sub]  from sub
  [12] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) A
(byte) A#0 1.0
(byte*) SCREEN
(void()) main()
(byte) main::B
(byte*) main::addrA
(void()) sub()
(byte) sub::C
(byte) sub::D
(byte) sub::D#0 4.0

Initial phi equivalence classes
Added variable sub::D#0 to zero page equivalence class [ sub::D#0 ]
Complete equivalence classes
[ A#0 ]
[ sub::D#0 ]
Allocated zp ZP_BYTE:2 [ A#0 ]
Allocated zp ZP_BYTE:3 [ sub::D#0 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
// Tests that constants are identified early
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label A = 2
  // @begin
bbegin:
  // [0] (byte) A#0 ← (byte) 'a' -- vbuz1=vbuc1 
  // Not an early constant (address-of is used)
  lda #'a'
  sta.z A
  // [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: {
    .const B = 'b'
    .label addrA = A
    // [4] *((const byte*) SCREEN#0) ← (byte) A#0 -- _deref_pbuc1=vbuz1 
    lda.z A
    sta SCREEN
    // [5] *((const byte*) SCREEN#0+(byte) 1) ← (const byte) main::B#0 -- _deref_pbuc1=vbuc2 
    lda #B
    sta SCREEN+1
    // [6] *((const byte*) SCREEN#0+(byte) 2) ← *((const byte*) main::addrA#0) -- _deref_pbuc1=_deref_pbuc2 
    lda addrA
    sta SCREEN+2
    // [7] call sub 
    jsr sub
    jmp breturn
    // main::@return
  breturn:
    // [8] return 
    rts
}
  // sub
sub: {
    .const C = 'c'
    .label D = 3
    // [9] *((const byte*) SCREEN#0+(byte) 3) ← (const byte) sub::C#0 -- _deref_pbuc1=vbuc2 
    lda #C
    sta SCREEN+3
    // [10] (byte) sub::D#0 ← (byte) A#0 + (byte) 1 -- vbuz1=vbuz2_plus_1 
    ldy.z A
    iny
    sty.z D
    // [11] *((const byte*) SCREEN#0+(byte) 4) ← (byte) sub::D#0 -- _deref_pbuc1=vbuz1 
    lda.z D
    sta SCREEN+4
    jmp breturn
    // sub::@return
  breturn:
    // [12] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] (byte) A#0 ← (byte) 'a' [ A#0 ] (  [ A#0 ] ) always clobbers reg byte a 
Statement [4] *((const byte*) SCREEN#0) ← (byte) A#0 [ A#0 ] ( main:2 [ A#0 ] ) always clobbers reg byte a 
Statement [5] *((const byte*) SCREEN#0+(byte) 1) ← (const byte) main::B#0 [ A#0 ] ( main:2 [ A#0 ] ) always clobbers reg byte a 
Statement [6] *((const byte*) SCREEN#0+(byte) 2) ← *((const byte*) main::addrA#0) [ A#0 ] ( main:2 [ A#0 ] ) always clobbers reg byte a 
Statement [9] *((const byte*) SCREEN#0+(byte) 3) ← (const byte) sub::C#0 [ A#0 ] ( main:2::sub:7 [ A#0 ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ A#0 ] : zp ZP_BYTE:2 , 
Potential registers zp ZP_BYTE:3 [ sub::D#0 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [sub] 4: zp ZP_BYTE:3 [ sub::D#0 ] 
Uplift Scope [] 1: zp ZP_BYTE:2 [ A#0 ] 
Uplift Scope [main] 

Uplifting [sub] best 77 combination reg byte x [ sub::D#0 ] 
Uplifting [] best 77 combination zp ZP_BYTE:2 [ A#0 ] 
Uplifting [main] best 77 combination 
Attempting to uplift remaining variables inzp ZP_BYTE:2 [ A#0 ]
Uplifting [] best 77 combination zp ZP_BYTE:2 [ A#0 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests that constants are identified early
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label A = 2
  // @begin
bbegin:
  // [0] (byte) A#0 ← (byte) 'a' -- vbuz1=vbuc1 
  // Not an early constant (address-of is used)
  lda #'a'
  sta.z A
  // [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: {
    .const B = 'b'
    .label addrA = A
    // [4] *((const byte*) SCREEN#0) ← (byte) A#0 -- _deref_pbuc1=vbuz1 
    lda.z A
    sta SCREEN
    // [5] *((const byte*) SCREEN#0+(byte) 1) ← (const byte) main::B#0 -- _deref_pbuc1=vbuc2 
    lda #B
    sta SCREEN+1
    // [6] *((const byte*) SCREEN#0+(byte) 2) ← *((const byte*) main::addrA#0) -- _deref_pbuc1=_deref_pbuc2 
    lda addrA
    sta SCREEN+2
    // [7] call sub 
    jsr sub
    jmp breturn
    // main::@return
  breturn:
    // [8] return 
    rts
}
  // sub
sub: {
    .const C = 'c'
    // [9] *((const byte*) SCREEN#0+(byte) 3) ← (const byte) sub::C#0 -- _deref_pbuc1=vbuc2 
    lda #C
    sta SCREEN+3
    // [10] (byte) sub::D#0 ← (byte) A#0 + (byte) 1 -- vbuxx=vbuz1_plus_1 
    ldx.z A
    inx
    // [11] *((const byte*) SCREEN#0+(byte) 4) ← (byte) sub::D#0 -- _deref_pbuc1=vbuxx 
    stx SCREEN+4
    jmp breturn
    // sub::@return
  breturn:
    // [12] 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 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) A
(byte) A#0 A zp ZP_BYTE:2 1.0
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (byte*) 1024
(void()) main()
(label) main::@return
(byte) main::B
(const byte) main::B#0 B = (byte) 'b'
(byte*) main::addrA
(const byte*) main::addrA#0 addrA = &(byte) A#0
(void()) sub()
(label) sub::@return
(byte) sub::C
(const byte) sub::C#0 C = (byte) 'c'
(byte) sub::D
(byte) sub::D#0 reg byte x 4.0

zp ZP_BYTE:2 [ A#0 ]
reg byte x [ sub::D#0 ]


FINAL ASSEMBLER
Score: 71

  // File Comments
// Tests that constants are identified early
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label A = 2
  // @begin
bbegin:
  // A = 'a'
  // [0] (byte) A#0 ← (byte) 'a' -- vbuz1=vbuc1 
  // Not an early constant (address-of is used)
  lda #'a'
  sta.z A
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  jsr main
  rts
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .const B = 'b'
    .label addrA = A
    // SCREEN[0] = A
    // [4] *((const byte*) SCREEN#0) ← (byte) A#0 -- _deref_pbuc1=vbuz1 
    lda.z A
    sta SCREEN
    // SCREEN[1] = B
    // [5] *((const byte*) SCREEN#0+(byte) 1) ← (const byte) main::B#0 -- _deref_pbuc1=vbuc2 
    lda #B
    sta SCREEN+1
    // SCREEN[2] = *addrA
    // [6] *((const byte*) SCREEN#0+(byte) 2) ← *((const byte*) main::addrA#0) -- _deref_pbuc1=_deref_pbuc2 
    lda addrA
    sta SCREEN+2
    // sub()
    // [7] call sub 
    jsr sub
    // main::@return
    // }
    // [8] return 
    rts
}
  // sub
sub: {
    .const C = 'c'
    // SCREEN[3] = C
    // [9] *((const byte*) SCREEN#0+(byte) 3) ← (const byte) sub::C#0 -- _deref_pbuc1=vbuc2 
    lda #C
    sta SCREEN+3
    // D = A+1
    // [10] (byte) sub::D#0 ← (byte) A#0 + (byte) 1 -- vbuxx=vbuz1_plus_1 
    ldx.z A
    inx
    // SCREEN[4] = D
    // [11] *((const byte*) SCREEN#0+(byte) 4) ← (byte) sub::D#0 -- _deref_pbuc1=vbuxx 
    stx SCREEN+4
    // sub::@return
    // }
    // [12] return 
    rts
}
  // File Data

