Setting inferred volatile on symbol affected by address-of (void~) main::$0 ← call sub (byte) 'a' &(byte*) main::screen 
Setting inferred volatile on symbol affected by address-of (void~) main::$1 ← call sub (byte) 'b' &(byte*) main::screen 
Culled Empty Block (label) @1

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

(void()) main()
main: scope:[main]  from @2
  (byte*) main::screen ← (byte*)(number) $400
  (byte) sub::ch#0 ← (byte) 'a'
  (byte**) sub::dst#0 ← &(byte*) main::screen
  call sub 
  to:main::@1
main::@1: scope:[main]  from main
  (byte) sub::ch#1 ← (byte) 'b'
  (byte**) sub::dst#1 ← &(byte*) main::screen
  call sub 
  to:main::@2
main::@2: scope:[main]  from main::@1
  to:main::@return
main::@return: scope:[main]  from main::@2
  return 
  to:@return

(void()) sub((byte) sub::ch , (byte**) sub::dst)
sub: scope:[sub]  from main main::@1
  (byte**) sub::dst#2 ← phi( main/(byte**) sub::dst#0 main::@1/(byte**) sub::dst#1 )
  (byte) sub::ch#2 ← phi( main/(byte) sub::ch#0 main::@1/(byte) sub::ch#1 )
  *(*((byte**) sub::dst#2)) ← (byte) sub::ch#2
  *((byte**) sub::dst#2) ← ++ *((byte**) sub::dst#2)
  to:sub::@return
sub::@return: scope:[sub]  from sub
  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
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(byte*) main::screen loadstore
(void()) sub((byte) sub::ch , (byte**) sub::dst)
(label) sub::@return
(byte) sub::ch
(byte) sub::ch#0
(byte) sub::ch#1
(byte) sub::ch#2
(byte**) sub::dst
(byte**) sub::dst#0
(byte**) sub::dst#1
(byte**) sub::dst#2

Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Constant (const byte) sub::ch#0 = 'a'
Constant (const byte**) sub::dst#0 = &main::screen
Constant (const byte) sub::ch#1 = 'b'
Constant (const byte**) sub::dst#1 = &main::screen
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const byte) sub::ch#0
Inlining constant with var siblings (const byte**) sub::dst#0
Inlining constant with var siblings (const byte) sub::ch#1
Inlining constant with var siblings (const byte**) sub::dst#1
Constant inlined sub::ch#1 = (byte) 'b'
Constant inlined sub::ch#0 = (byte) 'a'
Constant inlined sub::dst#1 = &(byte*) main::screen
Constant inlined sub::dst#0 = &(byte*) main::screen
Successful SSA optimization Pass2ConstantInlining
Identical Phi Values (byte**) sub::dst#2 &(byte*) main::screen
Successful SSA optimization Pass2IdenticalPhiElimination
Adding NOP phi() at start of @begin
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
Adding NOP phi() at start of main::@2
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to sub:6 sub:8 

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

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] (byte*) main::screen ← (byte*) 1024
  [5] call sub 
  to:main::@1
main::@1: scope:[main]  from main
  [6] phi()
  [7] call sub 
  to:main::@return
main::@return: scope:[main]  from main::@1
  [8] return 
  to:@return

(void()) sub((byte) sub::ch , (byte**) sub::dst)
sub: scope:[sub]  from main main::@1
  [9] (byte) sub::ch#2 ← phi( main/(byte) 'a' main::@1/(byte) 'b' )
  [10] *(*(&(byte*) main::screen)) ← (byte) sub::ch#2
  [11] *(&(byte*) main::screen) ← ++ *(&(byte*) main::screen)
  to:sub::@return
sub::@return: scope:[sub]  from sub
  [12] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte*) main::screen loadstore 0.2857142857142857
(void()) sub((byte) sub::ch , (byte**) sub::dst)
(byte) sub::ch
(byte) sub::ch#2 2.0
(byte**) sub::dst

Initial phi equivalence classes
[ sub::ch#2 ]
Added variable main::screen to live range equivalence class [ main::screen ]
Complete equivalence classes
[ sub::ch#2 ]
[ main::screen ]
Allocated zp[1]:2 [ sub::ch#2 ]
Allocated zp[2]:3 [ main::screen ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Tests (non-)optimization of constant pointers to pointers
// The two examples of &screen is not detected as identical leading to ASM that could be optimized more
  // 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 screen = 3
    // [4] (byte*) main::screen ← (byte*) 1024 -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // [5] call sub 
    // [9] phi from main to sub [phi:main->sub]
  sub_from_main:
    // [9] phi (byte) sub::ch#2 = (byte) 'a' [phi:main->sub#0] -- vbuz1=vbuc1 
    lda #'a'
    sta.z sub.ch
    jsr sub
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call sub 
    // [9] phi from main::@1 to sub [phi:main::@1->sub]
  sub_from___b1:
    // [9] phi (byte) sub::ch#2 = (byte) 'b' [phi:main::@1->sub#0] -- vbuz1=vbuc1 
    lda #'b'
    sta.z sub.ch
    jsr sub
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // sub
// sub(byte zp(2) ch)
sub: {
    .label ch = 2
    // [10] *(*(&(byte*) main::screen)) ← (byte) sub::ch#2 -- _deref_(_deref_pptc1)=vbuz1 
    lda.z ch
    ldy.z main.screen
    sty.z $fe
    ldy.z main.screen+1
    sty.z $ff
    ldy #0
    sta ($fe),y
    // [11] *(&(byte*) main::screen) ← ++ *(&(byte*) main::screen) -- _deref_pptc1=_inc__deref_pptc1 
    inc.z main.screen
    bne !+
    inc.z main.screen+1
  !:
    jmp __breturn
    // sub::@return
  __breturn:
    // [12] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (byte*) main::screen ← (byte*) 1024 [ main::screen ] ( main:2 [ main::screen ] ) always clobbers reg byte a 
Statement [10] *(*(&(byte*) main::screen)) ← (byte) sub::ch#2 [ main::screen ] ( main:2::sub:5 [ main::screen ] main:2::sub:7 [ main::screen ] ) always clobbers reg byte y 
Potential registers zp[1]:2 [ sub::ch#2 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:3 [ main::screen ] : zp[2]:3 , 

REGISTER UPLIFT SCOPES
Uplift Scope [sub] 2: zp[1]:2 [ sub::ch#2 ] 
Uplift Scope [main] 0.29: zp[2]:3 [ main::screen ] 
Uplift Scope [] 

Uplifting [sub] best 91 combination reg byte a [ sub::ch#2 ] 
Uplifting [main] best 91 combination zp[2]:3 [ main::screen ] 
Uplifting [] best 91 combination 
Allocated (was zp[2]:3) zp[2]:2 [ main::screen ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests (non-)optimization of constant pointers to pointers
// The two examples of &screen is not detected as identical leading to ASM that could be optimized more
  // 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 screen = 2
    // [4] (byte*) main::screen ← (byte*) 1024 -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // [5] call sub 
    // [9] phi from main to sub [phi:main->sub]
  sub_from_main:
    // [9] phi (byte) sub::ch#2 = (byte) 'a' [phi:main->sub#0] -- vbuaa=vbuc1 
    lda #'a'
    jsr sub
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call sub 
    // [9] phi from main::@1 to sub [phi:main::@1->sub]
  sub_from___b1:
    // [9] phi (byte) sub::ch#2 = (byte) 'b' [phi:main::@1->sub#0] -- vbuaa=vbuc1 
    lda #'b'
    jsr sub
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // sub
// sub(byte register(A) ch)
sub: {
    // [10] *(*(&(byte*) main::screen)) ← (byte) sub::ch#2 -- _deref_(_deref_pptc1)=vbuaa 
    ldy.z main.screen
    sty.z $fe
    ldy.z main.screen+1
    sty.z $ff
    ldy #0
    sta ($fe),y
    // [11] *(&(byte*) main::screen) ← ++ *(&(byte*) main::screen) -- _deref_pptc1=_inc__deref_pptc1 
    inc.z main.screen
    bne !+
    inc.z main.screen+1
  !:
    jmp __breturn
    // sub::@return
  __breturn:
    // [12] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
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:
Removing instruction __b1_from_main:
Removing instruction sub_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction sub_from_main:
Removing instruction __b1:
Removing instruction __breturn:
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()
(label) main::@1
(label) main::@return
(byte*) main::screen loadstore zp[2]:2 0.2857142857142857
(void()) sub((byte) sub::ch , (byte**) sub::dst)
(label) sub::@return
(byte) sub::ch
(byte) sub::ch#2 reg byte a 2.0
(byte**) sub::dst

reg byte a [ sub::ch#2 ]
zp[2]:2 [ main::screen ]


FINAL ASSEMBLER
Score: 70

  // File Comments
// Tests (non-)optimization of constant pointers to pointers
// The two examples of &screen is not detected as identical leading to ASM that could be optimized more
  // 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 screen = 2
    // screen = 0x400
    // [4] (byte*) main::screen ← (byte*) 1024 -- pbuz1=pbuc1 
    lda #<$400
    sta.z screen
    lda #>$400
    sta.z screen+1
    // sub('a',&screen)
    // [5] call sub 
    // [9] phi from main to sub [phi:main->sub]
    // [9] phi (byte) sub::ch#2 = (byte) 'a' [phi:main->sub#0] -- vbuaa=vbuc1 
    lda #'a'
    jsr sub
    // [6] phi from main to main::@1 [phi:main->main::@1]
    // main::@1
    // sub('b',&screen)
    // [7] call sub 
    // [9] phi from main::@1 to sub [phi:main::@1->sub]
    // [9] phi (byte) sub::ch#2 = (byte) 'b' [phi:main::@1->sub#0] -- vbuaa=vbuc1 
    lda #'b'
    jsr sub
    // main::@return
    // }
    // [8] return 
    rts
}
  // sub
// sub(byte register(A) ch)
sub: {
    // *(*dst)++ = ch
    // [10] *(*(&(byte*) main::screen)) ← (byte) sub::ch#2 -- _deref_(_deref_pptc1)=vbuaa 
    ldy.z main.screen
    sty.z $fe
    ldy.z main.screen+1
    sty.z $ff
    ldy #0
    sta ($fe),y
    // *(*dst)++ = ch;
    // [11] *(&(byte*) main::screen) ← ++ *(&(byte*) main::screen) -- _deref_pptc1=_inc__deref_pptc1 
    inc.z main.screen
    bne !+
    inc.z main.screen+1
  !:
    // sub::@return
    // }
    // [12] return 
    rts
}
  // File Data

