Eliminating unused variable with no statement main::$0
Eliminating unused variable with no statement main::$2
Eliminating unused variable with no statement main::$3
Eliminating unused variable with no statement main::$5

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::sumw#0 = main::min + main::max
  main::$1 = main::sumw#0 >> 1
  main::$7 = (char)main::$1
  main::midw#0 = main::$7 + 1
  main::SCREEN[0] = main::midw#0
  main::sumb#0 = main::min + main::max
  main::$4 = main::sumb#0 >> 1
  main::midb#0 = main::$4 + 1
  main::SCREEN[1] = main::midb#0
  main::$6 = main::SCREEN[0] == main::SCREEN[1]
  if(main::$6) goto main::@1
  to:main::@2
main::@1: scope:[main]  from main
  *main::BG_COLOR = 5
  to:main::@return
main::@2: scope:[main]  from main
  *main::BG_COLOR = 2
  to:main::@return
main::@return: scope:[main]  from main::@1 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
void __start()
void main()
unsigned int main::$1
char main::$4
bool main::$6
char main::$7
__constant char *main::BG_COLOR = (char *)$d021
__constant char *main::SCREEN = (char *)$400
__constant char main::max = $c8
char main::midb
char main::midb#0
char main::midw
char main::midw#0
__constant char main::min = $a
char main::sumb
char main::sumb#0
unsigned int main::sumw
unsigned int main::sumw#0

Adding number conversion cast (unumber) 1 in main::$1 = main::sumw#0 >> 1
Adding number conversion cast (unumber) 1 in main::midw#0 = main::$7 + 1
Adding number conversion cast (unumber) 0 in main::SCREEN[0] = main::midw#0
Adding number conversion cast (unumber) 1 in main::$4 = main::sumb#0 >> 1
Adding number conversion cast (unumber) 1 in main::midb#0 = main::$4 + 1
Adding number conversion cast (unumber) 1 in main::SCREEN[1] = main::midb#0
Adding number conversion cast (unumber) 0 in main::$6 = main::SCREEN[0] == main::SCREEN[1]
Adding number conversion cast (unumber) 1 in main::$6 = main::SCREEN[(unumber)0] == main::SCREEN[1]
Adding number conversion cast (unumber) 5 in *main::BG_COLOR = 5
Adding number conversion cast (unumber) 2 in *main::BG_COLOR = 2
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *main::BG_COLOR = (unumber)5
Inlining cast *main::BG_COLOR = (unumber)2
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant pointer cast (char *) 53281
Simplifying constant integer cast 1
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 1
Simplifying constant integer cast 1
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Simplifying constant integer cast 5
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 5
Finalized unsigned number type (char) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition main::$6 [10] if(main::SCREEN[0]==main::SCREEN[1]) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [0] main::sumw#0 = main::min + main::max
Constant right-side identified [5] main::sumb#0 = main::min + main::max
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::sumw#0 = main::min+main::max
Constant main::sumb#0 = main::min+main::max
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero main::SCREEN in [4] main::SCREEN[0] = main::midw#0
Simplifying expression containing zero main::SCREEN in [10] if(main::SCREEN[0]==main::SCREEN[1]) goto main::@1
Successful SSA optimization PassNSimplifyExpressionWithZero
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::$1 = main::sumw#0 >> 1
Constant right-side identified [4] main::$4 = main::sumb#0 >> 1
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::$1 = main::sumw#0>>1
Constant main::$4 = main::sumb#0>>1
Successful SSA optimization Pass2ConstantIdentification
Constant main::$7 = (char)main::$1
Successful SSA optimization Pass2ConstantIdentification
Constant right-side identified [0] main::midw#0 = main::$7 + 1
Constant right-side identified [2] main::midb#0 = main::$4 + 1
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::midw#0 = main::$7+1
Constant main::midb#0 = main::$4+1
Successful SSA optimization Pass2ConstantIdentification
Constant inlined main::$4 = main::sumb#0>>1
Constant inlined main::$1 = main::sumw#0>>1
Constant inlined main::$7 = (char)main::sumw#0>>1
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::SCREEN+1)
Consolidated array index constant in *(main::SCREEN+1)
Successful SSA optimization Pass2ConstantAdditionElimination
CALL GRAPH

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] *main::SCREEN = main::midw#0
  [1] *(main::SCREEN+1) = main::midb#0
  [2] if(*main::SCREEN==*(main::SCREEN+1)) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main
  [3] *main::BG_COLOR = 2
  to:main::@return
main::@return: scope:[main]  from main::@1 main::@2
  [4] return 
  to:@return
main::@1: scope:[main]  from main
  [5] *main::BG_COLOR = 5
  to:main::@return


VARIABLE REGISTER WEIGHTS
void main()
char main::midb
char main::midw
char main::sumb
unsigned int main::sumw

Initial phi equivalence classes
Complete equivalence classes
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *main::SCREEN = main::midw#0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [1] *(main::SCREEN+1) = main::midb#0 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [2] if(*main::SCREEN==*(main::SCREEN+1)) goto main::@1 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [3] *main::BG_COLOR = 2 [ ] (  [ ] { }  ) always clobbers reg byte a 
Statement [5] *main::BG_COLOR = 5 [ ] (  [ ] { }  ) always clobbers reg byte a 

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

Uplifting [main] best 49 combination 
Uplifting [] best 49 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests that casting inside constants in the output handles precedence between cast and + correctly - should generate the following KA-expression ($ff & sumw>>1)+1
  // Upstart
  // Commodore 64 PRG executable file
.file [name="cast-precedence-problem.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: {
    .const min = $a
    .const max = $c8
    .const sumw = min+max
    .const sumb = min+max
    .const midw = (sumw>>1)+1
    .const midb = (sumb>>1)+1
    .label SCREEN = $400
    .label BG_COLOR = $d021
    // [0] *main::SCREEN = main::midw#0 -- _deref_pbuc1=vbuc2 
    lda #midw
    sta SCREEN
    // [1] *(main::SCREEN+1) = main::midb#0 -- _deref_pbuc1=vbuc2 
    lda #midb
    sta SCREEN+1
    // [2] if(*main::SCREEN==*(main::SCREEN+1)) goto main::@1 -- _deref_pbuc1_eq__deref_pbuc2_then_la1 
    lda SCREEN
    cmp SCREEN+1
    beq __b1
    jmp __b2
    // main::@2
  __b2:
    // [3] *main::BG_COLOR = 2 -- _deref_pbuc1=vbuc2 
    lda #2
    sta BG_COLOR
    jmp __breturn
    // main::@return
  __breturn:
    // [4] return 
    rts
    // main::@1
  __b1:
    // [5] *main::BG_COLOR = 5 -- _deref_pbuc1=vbuc2 
    lda #5
    sta BG_COLOR
    jmp __breturn
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b2
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Replacing jump to rts with rts in jmp __breturn
Succesful ASM optimization Pass5DoubleJumpElimination
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
void main()
__constant char *main::BG_COLOR = (char *) 53281
__constant char *main::SCREEN = (char *) 1024
__constant char main::max = $c8
char main::midb
__constant char main::midb#0 = main::sumb#0>>1+1 // midb
char main::midw
__constant char main::midw#0 = (char)main::sumw#0>>1+1 // midw
__constant char main::min = $a
char main::sumb
__constant char main::sumb#0 = main::min+main::max // sumb
unsigned int main::sumw
__constant unsigned int main::sumw#0 = main::min+main::max // sumw



FINAL ASSEMBLER
Score: 46

  // File Comments
// Tests that casting inside constants in the output handles precedence between cast and + correctly - should generate the following KA-expression ($ff & sumw>>1)+1
  // Upstart
  // Commodore 64 PRG executable file
.file [name="cast-precedence-problem.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: {
    .const min = $a
    .const max = $c8
    .const sumw = min+max
    .const sumb = min+max
    .const midw = (sumw>>1)+1
    .const midb = (sumb>>1)+1
    .label SCREEN = $400
    .label BG_COLOR = $d021
    // SCREEN[0] = midw
    // [0] *main::SCREEN = main::midw#0 -- _deref_pbuc1=vbuc2 
    lda #midw
    sta SCREEN
    // SCREEN[1] = midb
    // [1] *(main::SCREEN+1) = main::midb#0 -- _deref_pbuc1=vbuc2 
    lda #midb
    sta SCREEN+1
    // if(SCREEN[0]==SCREEN[1])
    // [2] if(*main::SCREEN==*(main::SCREEN+1)) goto main::@1 -- _deref_pbuc1_eq__deref_pbuc2_then_la1 
    lda SCREEN
    cmp SCREEN+1
    beq __b1
    // main::@2
    // *BG_COLOR = 2
    // [3] *main::BG_COLOR = 2 -- _deref_pbuc1=vbuc2 
    lda #2
    sta BG_COLOR
    // main::@return
    // }
    // [4] return 
    rts
    // main::@1
  __b1:
    // *BG_COLOR = 5
    // [5] *main::BG_COLOR = 5 -- _deref_pbuc1=vbuc2 
    lda #5
    sta BG_COLOR
    rts
}
  // File Data

