Inlined call main::$0 = call getScreen(0)
Inlined call main::$1 = call spritePtr(main::screen)

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::screen#0 = (char *) 0
  main::getScreen1_id#0 = 0
  to:main::getScreen1
main::getScreen1: scope:[main]  from main
  main::getScreen1_id#1 = phi( main/main::getScreen1_id#0 )
  main::getScreen1_$0 = main::getScreen1_id#1 * SIZEOF_POINTER
  main::getScreen1_return#0 = screens[main::getScreen1_$0]
  to:main::getScreen1_@return
main::getScreen1_@return: scope:[main]  from main::getScreen1
  main::getScreen1_return#2 = phi( main::getScreen1/main::getScreen1_return#0 )
  main::getScreen1_return#1 = main::getScreen1_return#2
  to:main::@1
main::@1: scope:[main]  from main::getScreen1_@return
  main::getScreen1_return#3 = phi( main::getScreen1_@return/main::getScreen1_return#1 )
  main::$0 = main::getScreen1_return#3
  main::screen#1 = main::$0
  main::spritePtr1_screen#0 = main::screen#1
  to:main::spritePtr1
main::spritePtr1: scope:[main]  from main::@1
  main::spritePtr1_screen#1 = phi( main::@1/main::spritePtr1_screen#0 )
  main::spritePtr1_$0 = main::spritePtr1_screen#1 + $378
  main::spritePtr1_return#0 = (char *)main::spritePtr1_$0
  to:main::spritePtr1_@return
main::spritePtr1_@return: scope:[main]  from main::spritePtr1
  main::spritePtr1_return#2 = phi( main::spritePtr1/main::spritePtr1_return#0 )
  main::spritePtr1_return#1 = main::spritePtr1_return#2
  to:main::@2
main::@2: scope:[main]  from main::spritePtr1_@return
  main::spritePtr1_return#3 = phi( main::spritePtr1_@return/main::spritePtr1_return#1 )
  main::$1 = main::spritePtr1_return#3
  *main::$1 = $22
  to:main::@return
main::@return: scope:[main]  from main::@2
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  call main
  to:__start::@1
__start::@1: scope:[__start]  from __start
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  return 
  to:@return

SYMBOL TABLE SSA
__constant char SIZEOF_POINTER = 2
void __start()
void main()
char *main::$0
char *main::$1
char main::getScreen1_$0
char main::getScreen1_id
char main::getScreen1_id#0
char main::getScreen1_id#1
char *main::getScreen1_return
char *main::getScreen1_return#0
char *main::getScreen1_return#1
char *main::getScreen1_return#2
char *main::getScreen1_return#3
char *main::screen
char *main::screen#0
char *main::screen#1
char *main::spritePtr1_$0
char *main::spritePtr1_return
char *main::spritePtr1_return#0
char *main::spritePtr1_return#1
char *main::spritePtr1_return#2
char *main::spritePtr1_return#3
char *main::spritePtr1_screen
char *main::spritePtr1_screen#0
char *main::spritePtr1_screen#1
__constant char *screens[] = { (char *)$400, (char *)$1400 }

Adding number conversion cast (unumber) 0 in main::getScreen1_id#0 = 0
Adding number conversion cast (unumber) $378 in main::spritePtr1_$0 = main::spritePtr1_screen#1 + $378
Adding number conversion cast (unumber) $22 in *main::$1 = $22
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast main::getScreen1_id#0 = (unumber)0
Inlining cast *main::$1 = (unumber)$22
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant pointer cast (char *) 5120
Simplifying constant integer cast 0
Simplifying constant integer cast $378
Simplifying constant integer cast main::spritePtr1_$0
Simplifying constant integer cast $22
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (unsigned int) $378
Finalized unsigned number type (char) $22
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::getScreen1_id#0 = main::getScreen1_id#1 
Alias main::getScreen1_return#0 = main::getScreen1_return#2 main::getScreen1_return#1 main::getScreen1_return#3 main::$0 main::screen#1 main::spritePtr1_screen#0 main::spritePtr1_screen#1 
Alias main::spritePtr1_return#0 = main::spritePtr1_$0 main::spritePtr1_return#2 main::spritePtr1_return#1 main::spritePtr1_return#3 main::$1 
Successful SSA optimization Pass2AliasElimination
Constant main::screen#0 = (char *) 0
Constant main::getScreen1_id#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Eliminating unused constant main::screen#0
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Constant right-side identified [0] main::getScreen1_$0 = main::getScreen1_id#0 * SIZEOF_POINTER
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::getScreen1_$0 = main::getScreen1_id#0*SIZEOF_POINTER
Successful SSA optimization Pass2ConstantIdentification
Simplifying constant evaluating to zero main::getScreen1_id#0*SIZEOF_POINTER in 
Successful SSA optimization PassNSimplifyConstantZero
Simplifying expression containing zero screens in [1] main::getScreen1_return#0 = screens[main::getScreen1_$0]
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant main::getScreen1_id#0
Eliminating unused constant main::getScreen1_$0
Eliminating unused constant SIZEOF_POINTER
Successful SSA optimization PassNEliminateUnusedVars
Adding NOP phi() at start of main
Adding NOP phi() at start of main::getScreen1_@return
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::spritePtr1_@return
CALL GRAPH

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

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  to:main::getScreen1
main::getScreen1: scope:[main]  from main
  [1] main::getScreen1_return#0 = *screens
  to:main::spritePtr1
main::spritePtr1: scope:[main]  from main::getScreen1
  [2] main::spritePtr1_return#0 = main::getScreen1_return#0 + $378
  to:main::@1
main::@1: scope:[main]  from main::spritePtr1
  [3] *main::spritePtr1_return#0 = $22
  to:main::@return
main::@return: scope:[main]  from main::@1
  [4] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::getScreen1_id
char *main::getScreen1_return
char *main::getScreen1_return#0 // 4.0
char *main::screen
char *main::spritePtr1_return
char *main::spritePtr1_return#0 // 4.0
char *main::spritePtr1_screen

Initial phi equivalence classes
Added variable main::getScreen1_return#0 to live range equivalence class [ main::getScreen1_return#0 ]
Added variable main::spritePtr1_return#0 to live range equivalence class [ main::spritePtr1_return#0 ]
Complete equivalence classes
[ main::getScreen1_return#0 ]
[ main::spritePtr1_return#0 ]
Allocated zp[2]:2 [ main::getScreen1_return#0 ]
Allocated zp[2]:4 [ main::spritePtr1_return#0 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] main::getScreen1_return#0 = *screens [ main::getScreen1_return#0 ] (  [ main::getScreen1_return#0 ] { }  ) always clobbers reg byte a 
Statement [2] main::spritePtr1_return#0 = main::getScreen1_return#0 + $378 [ main::spritePtr1_return#0 ] (  [ main::spritePtr1_return#0 ] { }  ) always clobbers reg byte a 
Statement [3] *main::spritePtr1_return#0 = $22 [ ] (  [ ] { }  ) always clobbers reg byte a reg byte y 
Potential registers zp[2]:2 [ main::getScreen1_return#0 ] : zp[2]:2 , 
Potential registers zp[2]:4 [ main::spritePtr1_return#0 ] : zp[2]:4 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp[2]:2 [ main::getScreen1_return#0 ] 4: zp[2]:4 [ main::spritePtr1_return#0 ] 
Uplift Scope [] 

Uplifting [main] best 87 combination zp[2]:2 [ main::getScreen1_return#0 ] zp[2]:4 [ main::spritePtr1_return#0 ] 
Uplifting [] best 87 combination 
Coalescing zero page register [ zp[2]:2 [ main::getScreen1_return#0 ] ] with [ zp[2]:4 [ main::spritePtr1_return#0 ] ] - score: 1

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests a cast that is not needed
  // Upstart
  // Commodore 64 PRG executable file
.file [name="cast-not-needed-2.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(main)
  // Global Constants & labels
.segment Code
  // main
main: {
    .label getScreen1_return = 2
    .label spritePtr1_return = 2
    jmp getScreen1
    // main::getScreen1
  getScreen1:
    // [1] main::getScreen1_return#0 = *screens -- pbuz1=_deref_qbuc1 
    lda screens
    sta.z getScreen1_return
    lda screens+1
    sta.z getScreen1_return+1
    jmp spritePtr1
    // main::spritePtr1
  spritePtr1:
    // [2] main::spritePtr1_return#0 = main::getScreen1_return#0 + $378 -- pbuz1=pbuz1_plus_vwuc1 
    lda.z spritePtr1_return
    clc
    adc #<$378
    sta.z spritePtr1_return
    lda.z spritePtr1_return+1
    adc #>$378
    sta.z spritePtr1_return+1
    jmp __b1
    // main::@1
  __b1:
    // [3] *main::spritePtr1_return#0 = $22 -- _deref_pbuz1=vbuc1 
    lda #$22
    ldy #0
    sta (spritePtr1_return),y
    jmp __breturn
    // main::@return
  __breturn:
    // [4] return 
    rts
}
  // File Data
.segment Data
  screens: .word $400, $1400

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp getScreen1
Removing instruction jmp spritePtr1
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction getScreen1:
Removing instruction spritePtr1:
Removing instruction __b1:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
void main()
char main::getScreen1_id
char *main::getScreen1_return
char *main::getScreen1_return#0 // getScreen1_return zp[2]:2 4.0
char *main::screen
char *main::spritePtr1_return
char *main::spritePtr1_return#0 // spritePtr1_return zp[2]:2 4.0
char *main::spritePtr1_screen
__constant char *screens[] = { (char *) 1024, (char *) 5120 }

zp[2]:2 [ main::getScreen1_return#0 main::spritePtr1_return#0 ]


FINAL ASSEMBLER
Score: 48

  // File Comments
// Tests a cast that is not needed
  // Upstart
  // Commodore 64 PRG executable file
.file [name="cast-not-needed-2.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(main)
  // Global Constants & labels
.segment Code
  // main
main: {
    .label getScreen1_return = 2
    .label spritePtr1_return = 2
    // main::getScreen1
    // return screens[id];
    // [1] main::getScreen1_return#0 = *screens -- pbuz1=_deref_qbuc1 
    lda screens
    sta.z getScreen1_return
    lda screens+1
    sta.z getScreen1_return+1
    // main::spritePtr1
    // screen+$378
    // [2] main::spritePtr1_return#0 = main::getScreen1_return#0 + $378 -- pbuz1=pbuz1_plus_vwuc1 
    lda.z spritePtr1_return
    clc
    adc #<$378
    sta.z spritePtr1_return
    lda.z spritePtr1_return+1
    adc #>$378
    sta.z spritePtr1_return+1
    // main::@1
    // *spritePtr(screen) = $22
    // [3] *main::spritePtr1_return#0 = $22 -- _deref_pbuz1=vbuc1 
    lda #$22
    ldy #0
    sta (spritePtr1_return),y
    // main::@return
    // }
    // [4] return 
    rts
}
  // File Data
.segment Data
  screens: .word $400, $1400

