
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  asm { sei  }
  to:main::@1
main::@1: scope:[main]  from main main::@4 main::@5
  if(true) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  main::$0 = *RASTER < $1e
  if(main::$0) goto main::@3
  to:main::@4
main::@3: scope:[main]  from main::@2
  call incScreen
  to:main::@5
main::@5: scope:[main]  from main::@3
  to:main::@1
main::@4: scope:[main]  from main::@2
  *BG_COLOR = 0
  to:main::@1
main::@return: scope:[main]  from main::@1
  return 
  to:@return

void incScreen()
incScreen: scope:[incScreen]  from main::@3
  *BG_COLOR = *RASTER
  to:incScreen::@return
incScreen::@return: scope:[incScreen]  from incScreen
  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 * const BG_COLOR = (char *)$d021
__constant char * const RASTER = (char *)$d012
void __start()
void incScreen()
void main()
bool main::$0

Adding number conversion cast (unumber) $1e in main::$0 = *RASTER < $1e
Adding number conversion cast (unumber) 0 in *BG_COLOR = 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *BG_COLOR = (unumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 53281
Simplifying constant pointer cast (char *) 53266
Simplifying constant integer cast $1e
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $1e
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition main::$0 [3] if(*RASTER<$1e) goto main::@3
Successful SSA optimization Pass2ConditionalJumpSimplification
if() condition always true - replacing block destination [1] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
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
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@3
Adding NOP phi() at start of main::@5
CALL GRAPH
Calls in [main] to incScreen:5 

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

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  asm { sei  }
  to:main::@1
main::@1: scope:[main]  from main main::@2 main::@3
  [1] if(*RASTER<$1e) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [2] *BG_COLOR = 0
  to:main::@1
main::@2: scope:[main]  from main::@1
  [3] phi()
  [4] call incScreen
  to:main::@1

void incScreen()
incScreen: scope:[incScreen]  from main::@2
  [5] *BG_COLOR = *RASTER
  to:incScreen::@return
incScreen::@return: scope:[incScreen]  from incScreen
  [6] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void incScreen()
void main()

Initial phi equivalence classes
Complete equivalence classes
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [1] if(*RASTER<$1e) goto main::@2 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [2] *BG_COLOR = 0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [5] *BG_COLOR = *RASTER [ ] ( incScreen:4 [ ] { }  ) always clobbers reg byte a 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 
Uplift Scope [incScreen] 
Uplift Scope [] 

Uplifting [main] best 347 combination 
Uplifting [incScreen] best 347 combination 
Uplifting [] best 347 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test setting the program PC through a #pc directive
  // Upstart
  // Commodore 64 PRG executable file
.file [name="global-pc-multiple.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$2000]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .label BG_COLOR = $d021
  .label RASTER = $d012
.segment Code
  // main
main: {
    // asm { sei  }
    sei
    jmp __b1
    // main::@1
  __b1:
    // [1] if(*RASTER<$1e) goto main::@2 -- _deref_pbuc1_lt_vbuc2_then_la1 
    lda RASTER
    cmp #$1e
    bcc __b2_from___b1
    jmp __b3
    // main::@3
  __b3:
    // [2] *BG_COLOR = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta BG_COLOR
    jmp __b1
    // [3] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [4] call incScreen
    jsr incScreen
    jmp __b1
}
  // incScreen
incScreen: {
    // [5] *BG_COLOR = *RASTER -- _deref_pbuc1=_deref_pbuc2 
    lda RASTER
    sta BG_COLOR
    jmp __breturn
    // incScreen::@return
  __breturn:
    // [6] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __b2
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b2_from___b1 with __b2
Removing instruction __b2_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b3:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant char * const BG_COLOR = (char *) 53281
__constant char * const RASTER = (char *) 53266
void incScreen()
void main()



FINAL ASSEMBLER
Score: 281

  // File Comments
// Test setting the program PC through a #pc directive
  // Upstart
  // Commodore 64 PRG executable file
.file [name="global-pc-multiple.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$2000]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .label BG_COLOR = $d021
  .label RASTER = $d012
.segment Code
  // main
main: {
    // asm
    // asm { sei  }
    sei
    // main::@1
  __b1:
    // if(*RASTER<30)
    // [1] if(*RASTER<$1e) goto main::@2 -- _deref_pbuc1_lt_vbuc2_then_la1 
    lda RASTER
    cmp #$1e
    bcc __b2
    // main::@3
    // *BG_COLOR = 0
    // [2] *BG_COLOR = 0 -- _deref_pbuc1=vbuc2 
    lda #0
    sta BG_COLOR
    jmp __b1
    // [3] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // main::@2
  __b2:
    // incScreen()
    // [4] call incScreen
    jsr incScreen
    jmp __b1
}
  // incScreen
incScreen: {
    // *BG_COLOR = *RASTER
    // [5] *BG_COLOR = *RASTER -- _deref_pbuc1=_deref_pbuc2 
    lda RASTER
    sta BG_COLOR
    // incScreen::@return
    // }
    // [6] return 
    rts
}
  // File Data

