Setting inferred volatile on symbol affected by address-of main::addrA = &A
Inlined call call __init
Eliminating unused variable with no statement sub::$0

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  SCREEN[0] = A
  SCREEN[1] = main::B
  SCREEN[2] = *main::addrA
  call sub
  to:main::@1
main::@1: scope:[main]  from main
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return

void sub()
sub: scope:[sub]  from main
  SCREEN[3] = sub::C
  sub::D#0 = A + 1
  SCREEN[4] = sub::D#0
  to:sub::@return
sub::@return: scope:[sub]  from sub
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  A = 'a'
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  return 
  to:@return

SYMBOL TABLE SSA
__loadstore volatile char A
__constant char *SCREEN = (char *)$400
void __start()
void main()
__constant char main::B = 'b'
__constant char *main::addrA = &A
void sub()
__constant char sub::C = 'c'
char sub::D
char sub::D#0

Adding number conversion cast (unumber) 0 in SCREEN[0] = A
Adding number conversion cast (unumber) 1 in SCREEN[1] = main::B
Adding number conversion cast (unumber) 2 in SCREEN[2] = *main::addrA
Adding number conversion cast (unumber) 3 in SCREEN[3] = sub::C
Adding number conversion cast (unumber) 1 in sub::D#0 = A + 1
Adding number conversion cast (unumber) 4 in SCREEN[4] = sub::D#0
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 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 (char) 0
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) 3
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying expression containing zero SCREEN in [0] SCREEN[0] = A
Successful SSA optimization PassNSimplifyExpressionWithZero
Consolidated array index constant in *(SCREEN+1)
Consolidated array index constant in *(SCREEN+2)
Consolidated array index constant in *(SCREEN+3)
Consolidated array index constant in *(SCREEN+4)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of __start
Adding NOP phi() at start of __start::@1
Adding NOP phi() at start of __start::@2
Adding NOP phi() at start of main::@1
CALL GRAPH
Calls in [__start] to main:3 
Calls in [main] to sub:9 

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

FINAL CONTROL FLOW GRAPH

void __start()
__start: scope:[__start]  from
  [0] phi()
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  [1] A = 'a'
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  [2] phi()
  [3] call main
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  [4] return 
  to:@return

void main()
main: scope:[main]  from __start::@1
  [5] *SCREEN = A
  [6] *(SCREEN+1) = main::B
  [7] *(SCREEN+2) = *main::addrA
  [8] call sub
  to:main::@return
main::@return: scope:[main]  from main
  [9] return 
  to:@return

void sub()
sub: scope:[sub]  from main
  [10] *(SCREEN+3) = sub::C
  [11] sub::D#0 = A + 1
  [12] *(SCREEN+4) = sub::D#0
  to:sub::@return
sub::@return: scope:[sub]  from sub
  [13] return 
  to:@return


VARIABLE REGISTER WEIGHTS
__loadstore volatile char A // 19.0
void __start()
void main()
void sub()
char sub::D
char sub::D#0 // 202.0

Initial phi equivalence classes
Added variable A to live range equivalence class [ A ]
Added variable sub::D#0 to live range equivalence class [ sub::D#0 ]
Complete equivalence classes
[ A ]
[ sub::D#0 ]
Allocated zp[1]:2 [ sub::D#0 ]
Allocated zp[1]:3 [ A ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] A = 'a' [ A ] (  [ A ] { }  ) always clobbers reg byte a 
Statement [5] *SCREEN = A [ A ] ( main:3 [ A ] { }  ) always clobbers reg byte a 
Statement [6] *(SCREEN+1) = main::B [ A ] ( main:3 [ A ] { }  ) always clobbers reg byte a 
Statement [7] *(SCREEN+2) = *main::addrA [ A ] ( main:3 [ A ] { }  ) always clobbers reg byte a 
Statement [10] *(SCREEN+3) = sub::C [ A ] ( main:3::sub:8 [ A ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:3 [ A ] : zp[1]:3 , 
Potential registers zp[1]:2 [ sub::D#0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [sub] 202: zp[1]:2 [ sub::D#0 ] 
Uplift Scope [] 19: zp[1]:3 [ A ] 
Uplift Scope [main] 
Uplift Scope [__start] 

Uplifting [sub] best 112 combination reg byte x [ sub::D#0 ] 
Uplifting [] best 112 combination zp[1]:3 [ A ] 
Uplifting [main] best 112 combination 
Uplifting [__start] best 112 combination 
Attempting to uplift remaining variables inzp[1]:3 [ A ]
Uplifting [] best 112 combination zp[1]:3 [ A ] 
Allocated (was zp[1]:3) zp[1]:2 [ A ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests that constants are identified early
  // Upstart
  // Commodore 64 PRG executable file
.file [name="const-early-identification.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(__start)
  // Global Constants & labels
  .label SCREEN = $400
  // Not an early constant (address-of is used)
  .label A = 2
.segment Code
  // __start
__start: {
    jmp __init1
    // __start::__init1
  __init1:
    // [1] A = 'a' -- vbuz1=vbuc1 
    lda #'a'
    sta.z A
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
  __b1_from___init1:
    jmp __b1
    // __start::@1
  __b1:
    // [3] call main
    jsr main
    jmp __breturn
    // __start::@return
  __breturn:
    // [4] return 
    rts
}
  // main
main: {
    .const B = 'b'
    .label addrA = A
    // [5] *SCREEN = A -- _deref_pbuc1=vbuz1 
    lda.z A
    sta SCREEN
    // [6] *(SCREEN+1) = main::B -- _deref_pbuc1=vbuc2 
    lda #B
    sta SCREEN+1
    // [7] *(SCREEN+2) = *main::addrA -- _deref_pbuc1=_deref_pbuc2 
    lda.z addrA
    sta SCREEN+2
    // [8] call sub
    jsr sub
    jmp __breturn
    // main::@return
  __breturn:
    // [9] return 
    rts
}
  // sub
sub: {
    .const C = 'c'
    // [10] *(SCREEN+3) = sub::C -- _deref_pbuc1=vbuc2 
    lda #C
    sta SCREEN+3
    // [11] sub::D#0 = A + 1 -- vbuxx=vbuz1_plus_1 
    // Not an early constant (expression)
    ldx.z A
    inx
    // [12] *(SCREEN+4) = sub::D#0 -- _deref_pbuc1=vbuxx 
    stx SCREEN+4
    jmp __breturn
    // sub::@return
  __breturn:
    // [13] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __init1
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from___init1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __init1:
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__loadstore volatile char A // zp[1]:2 19.0
__constant char *SCREEN = (char *) 1024
void __start()
void main()
__constant char main::B = 'b'
__constant char *main::addrA = &A
void sub()
__constant char sub::C = 'c'
char sub::D
char sub::D#0 // reg byte x 202.0

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


FINAL ASSEMBLER
Score: 70

  // File Comments
// Tests that constants are identified early
  // Upstart
  // Commodore 64 PRG executable file
.file [name="const-early-identification.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(__start)
  // Global Constants & labels
  .label SCREEN = $400
  // Not an early constant (address-of is used)
  .label A = 2
.segment Code
  // __start
__start: {
    // __start::__init1
    // byte A = 'a'
    // [1] A = 'a' -- vbuz1=vbuc1 
    lda #'a'
    sta.z A
    // [2] phi from __start::__init1 to __start::@1 [phi:__start::__init1->__start::@1]
    // __start::@1
    // [3] call main
    jsr main
    // __start::@return
    // [4] return 
    rts
}
  // main
main: {
    .const B = 'b'
    .label addrA = A
    // SCREEN[0] = A
    // [5] *SCREEN = A -- _deref_pbuc1=vbuz1 
    lda.z A
    sta SCREEN
    // SCREEN[1] = B
    // [6] *(SCREEN+1) = main::B -- _deref_pbuc1=vbuc2 
    lda #B
    sta SCREEN+1
    // SCREEN[2] = *addrA
    // [7] *(SCREEN+2) = *main::addrA -- _deref_pbuc1=_deref_pbuc2 
    lda.z addrA
    sta SCREEN+2
    // sub()
    // [8] call sub
    jsr sub
    // main::@return
    // }
    // [9] return 
    rts
}
  // sub
sub: {
    .const C = 'c'
    // SCREEN[3] = C
    // [10] *(SCREEN+3) = sub::C -- _deref_pbuc1=vbuc2 
    lda #C
    sta SCREEN+3
    // byte D = A+1
    // [11] sub::D#0 = A + 1 -- vbuxx=vbuz1_plus_1 
    // Not an early constant (expression)
    ldx.z A
    inx
    // SCREEN[4] = D
    // [12] *(SCREEN+4) = sub::D#0 -- _deref_pbuc1=vbuxx 
    stx SCREEN+4
    // sub::@return
    // }
    // [13] return 
    rts
}
  // File Data

