
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  to:main::@1
main::@1: scope:[main]  from main main::@3
  if(true) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  main::key#0 = *RASTER
  main::$0 = main::key#0 > $20
  main::$1 = main::key#0 < $40
  main::$2 = main::$0 || main::$1
  main::$3 = ! main::$2
  if(main::$3) goto main::@3
  to:main::@4
main::@3: scope:[main]  from main::@2 main::@4
  main::key#2 = phi( main::@2/main::key#0, main::@4/main::key#1 )
  *SCREEN = main::key#2
  to:main::@1
main::@4: scope:[main]  from main::@2
  main::key#1 = 0
  to:main::@3
main::@return: scope:[main]  from main::@1
  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 RASTER = (char *)$d012
__constant char * const SCREEN = (char *)$400
void __start()
void main()
bool main::$0
bool main::$1
bool main::$2
bool main::$3
char main::key
char main::key#0
char main::key#1
char main::key#2

Adding number conversion cast (unumber) $20 in main::$0 = main::key#0 > $20
Adding number conversion cast (unumber) $40 in main::$1 = main::key#0 < $40
Adding number conversion cast (unumber) 0 in main::key#1 = 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast main::key#1 = (unumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 53266
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $20
Simplifying constant integer cast $40
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $20
Finalized unsigned number type (char) $40
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting ! if()-condition to reversed if() [5] main::$3 = ! main::$2
Rewriting || if()-condition to two if()s [4] main::$2 = main::$0 || main::$1
Successful SSA optimization Pass2ConditionalAndOrRewriting
Constant main::key#1 = 0
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [0] 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
Simple Condition main::$0 [3] if(main::key#0>$20) goto main::@4
Simple Condition main::$1 [6] if(main::key#0<$40) goto main::@4
Successful SSA optimization Pass2ConditionalJumpSimplification
Negating conditional jump and destination [6] if(main::key#0>=$40) goto main::@3
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
Rewriting conditional comparison [3] if(main::key#0>$20) goto main::@4
Adding number conversion cast (unumber) $20+1 in if(main::key#0>=$20+1) goto main::@4
Adding number conversion cast (unumber) 1 in if(main::key#0>=(unumber)$20+1) goto main::@4
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $20+(unumber)1
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings main::key#1
Constant inlined main::key#1 = 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@6(between main::@5 and main::@3)
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@4
CALL GRAPH

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

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [1] main::key#0 = *RASTER
  [2] if(main::key#0>=$20+1) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [3] if(main::key#0>=$40) goto main::@4
  to:main::@2
main::@4: scope:[main]  from main::@3
  [4] phi()
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@3 main::@4
  [5] main::key#2 = phi( main::@4/main::key#0, main::@1/0, main::@3/0 )
  [6] *SCREEN = main::key#2
  to:main::@1


VARIABLE REGISTER WEIGHTS
void main()
char main::key
char main::key#0 // 11.0
char main::key#2 // 22.0

Initial phi equivalence classes
[ main::key#2 main::key#0 ]
Complete equivalence classes
[ main::key#2 main::key#0 ]
Allocated zp[1]:2 [ main::key#2 main::key#0 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp[1]:2 [ main::key#2 main::key#0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 33: zp[1]:2 [ main::key#2 main::key#0 ] 
Uplift Scope [] 

Uplifting [main] best 370 combination reg byte a [ main::key#2 main::key#0 ] 
Uplifting [] best 370 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test to provoke Exception when using complex || condition
  // Upstart
  // Commodore 64 PRG executable file
.file [name="complex-conditional-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
  .label RASTER = $d012
  .label SCREEN = $400
.segment Code
  // main
main: {
    jmp __b1
    // main::@1
  __b1:
    // [1] main::key#0 = *RASTER -- vbuaa=_deref_pbuc1 
    lda RASTER
    // [2] if(main::key#0>=$20+1) goto main::@2 -- vbuaa_ge_vbuc1_then_la1 
    cmp #$20+1
    bcs __b2_from___b1
    jmp __b3
    // main::@3
  __b3:
    // [3] if(main::key#0>=$40) goto main::@4 -- vbuaa_ge_vbuc1_then_la1 
    cmp #$40
    bcs __b4_from___b3
    // [5] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
  __b2_from___b1:
  __b2_from___b3:
    // [5] phi main::key#2 = 0 [phi:main::@1/main::@3->main::@2#0] -- vbuaa=vbuc1 
    lda #0
    jmp __b2
    // [4] phi from main::@3 to main::@4 [phi:main::@3->main::@4]
  __b4_from___b3:
    jmp __b4
    // main::@4
  __b4:
    // [5] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
  __b2_from___b4:
    // [5] phi main::key#2 = main::key#0 [phi:main::@4->main::@2#0] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [6] *SCREEN = main::key#2 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    jmp __b1
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b3
Removing instruction jmp __b4
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b2_from___b1 with __b2_from___b3
Replacing label __b4_from___b3 with __b2
Removing instruction __b2_from___b1:
Removing instruction __b4_from___b3:
Removing instruction __b4:
Removing instruction __b2_from___b4:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b3:
Succesful ASM optimization Pass5UnusedLabelElimination
Relabelling long label __b2_from___b3 to __b3
Succesful ASM optimization Pass5RelabelLongLabels
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
__constant char * const RASTER = (char *) 53266
__constant char * const SCREEN = (char *) 1024
void main()
char main::key
char main::key#0 // reg byte a 11.0
char main::key#2 // reg byte a 22.0

reg byte a [ main::key#2 main::key#0 ]


FINAL ASSEMBLER
Score: 220

  // File Comments
// Test to provoke Exception when using complex || condition
  // Upstart
  // Commodore 64 PRG executable file
.file [name="complex-conditional-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
  .label RASTER = $d012
  .label SCREEN = $400
.segment Code
  // main
main: {
    // main::@1
  __b1:
    // byte key = *RASTER
    // [1] main::key#0 = *RASTER -- vbuaa=_deref_pbuc1 
    lda RASTER
    // if (key > $20 || key < $40)
    // [2] if(main::key#0>=$20+1) goto main::@2 -- vbuaa_ge_vbuc1_then_la1 
    cmp #$20+1
    bcs __b3
    // main::@3
    // [3] if(main::key#0>=$40) goto main::@4 -- vbuaa_ge_vbuc1_then_la1 
    cmp #$40
    bcs __b2
    // [5] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
  __b3:
    // [5] phi main::key#2 = 0 [phi:main::@1/main::@3->main::@2#0] -- vbuaa=vbuc1 
    lda #0
    // [4] phi from main::@3 to main::@4 [phi:main::@3->main::@4]
    // main::@4
    // [5] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
    // [5] phi main::key#2 = main::key#0 [phi:main::@4->main::@2#0] -- register_copy 
    // main::@2
  __b2:
    // *SCREEN = key
    // [6] *SCREEN = main::key#2 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    jmp __b1
}
  // File Data

