
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::pos#0 = 1
  main::vacant#0 = 1
  to:main::@1
main::@1: scope:[main]  from main main::@2
  main::vacant#3 = phi( main/main::vacant#0, main::@2/main::vacant#2 )
  main::pos#2 = phi( main/main::pos#0, main::@2/main::pos#3 )
  main::pos#1 = main::pos#2 + main::move
  main::$2 = 0 != main::pos#1
  main::$0 = ! main::$2
  if(main::$0) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1 main::@3
  main::vacant#2 = phi( main::@1/main::vacant#3, main::@3/main::vacant#1 )
  main::pos#3 = phi( main::@1/main::pos#1, main::@3/main::pos#4 )
  main::$1 = main::pos#3 && main::vacant#2
  if(main::$1) goto main::@1
  to:main::@return
main::@3: scope:[main]  from main::@1
  main::pos#4 = phi( main::@1/main::pos#1 )
  main::vacant#1 = 0
  to:main::@2
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
void __start()
void main()
bool main::$0
bool main::$1
bool main::$2
__constant char main::move = 1
char main::pos
char main::pos#0
char main::pos#1
char main::pos#2
char main::pos#3
char main::pos#4
char main::vacant
char main::vacant#0
char main::vacant#1
char main::vacant#2
char main::vacant#3

Adding number conversion cast (unumber) 0 in main::$2 = 0 != main::pos#1
Adding number conversion cast (unumber) 0 in main::vacant#1 = 0
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast main::vacant#1 = (unumber)0
Successful SSA optimization Pass2InlineCast
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inversing boolean not [5] main::$0 = 0 == main::pos#1 from [4] main::$2 = 0 != main::pos#1
Successful SSA optimization Pass2UnaryNotSimplification
Alias main::pos#1 = main::pos#4 
Successful SSA optimization Pass2AliasElimination
Alias main::pos#1 = main::pos#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition main::$0 [5] if(0==main::pos#1) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Rewriting && if()-condition to two if()s [7] main::$1 = main::pos#1 && main::vacant#2
Successful SSA optimization Pass2ConditionalAndOrRewriting
Warning! Adding boolean cast to non-boolean condition main::pos#1
Warning! Adding boolean cast to non-boolean condition main::vacant#2
Constant main::pos#0 = 1
Constant main::vacant#0 = 1
Constant main::vacant#1 = 0
Successful SSA optimization Pass2ConstantIdentification
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 number conversion cast (unumber) 0 in [4] main::$3 = 0 != main::pos#1
Adding number conversion cast (unumber) 0 in [9] main::$4 = 0 != main::vacant#2
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition main::$3 [5] if(0!=main::pos#1) goto main::@4
Simple Condition main::$4 [8] if(0!=main::vacant#2) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Negating conditional jump and destination [5] if(0==main::pos#1) goto main::@return
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
Inlining constant with var siblings main::pos#0
Inlining constant with var siblings main::vacant#0
Inlining constant with var siblings main::vacant#1
Constant inlined main::vacant#0 = 1
Constant inlined main::vacant#1 = 0
Constant inlined main::pos#0 = 1
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@5(between main::@4 and main::@1)
Added new block during phi lifting main::@6(between main::@1 and main::@2)
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@3
CALL GRAPH

Created 3 initial phi equivalence classes
Coalesced [9] main::pos#5 = main::pos#1
Coalesced [10] main::vacant#4 = main::vacant#2
Coalesced (already) [11] main::vacant#5 = main::vacant#3
Coalesced down to 2 phi equivalence classes
Culled Empty Block label main::@3
Culled Empty Block label main::@5
Renumbering block main::@4 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::@3
  [1] main::vacant#3 = phi( main/1, main::@3/main::vacant#2 )
  [1] main::pos#2 = phi( main/1, main::@3/main::pos#1 )
  [2] main::pos#1 = main::pos#2 + main::move
  [3] if(0==main::pos#1) goto main::@4
  to:main::@2
main::@4: scope:[main]  from main::@1
  [4] phi()
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@4
  [5] main::vacant#2 = phi( main::@4/main::vacant#3, main::@1/0 )
  [6] if(0==main::pos#1) goto main::@return
  to:main::@3
main::@3: scope:[main]  from main::@2
  [7] if(0!=main::vacant#2) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@2 main::@3
  [8] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::pos
char main::pos#1 // 7.333333333333333
char main::pos#2 // 22.0
char main::vacant
char main::vacant#2 // 11.0
char main::vacant#3 // 5.5

Initial phi equivalence classes
[ main::pos#2 main::pos#1 ]
[ main::vacant#3 main::vacant#2 ]
Complete equivalence classes
[ main::pos#2 main::pos#1 ]
[ main::vacant#3 main::vacant#2 ]
Allocated zp[1]:2 [ main::pos#2 main::pos#1 ]
Allocated zp[1]:3 [ main::vacant#3 main::vacant#2 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] main::pos#1 = main::pos#2 + main::move [ main::vacant#3 main::pos#1 ] (  [ main::vacant#3 main::pos#1 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::vacant#3 main::vacant#2 ]
Statement [2] main::pos#1 = main::pos#2 + main::move [ main::vacant#3 main::pos#1 ] (  [ main::vacant#3 main::pos#1 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::pos#2 main::pos#1 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::vacant#3 main::vacant#2 ] : zp[1]:3 , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 29.33: zp[1]:2 [ main::pos#2 main::pos#1 ] 16.5: zp[1]:3 [ main::vacant#3 main::vacant#2 ] 
Uplift Scope [] 

Uplifting [main] best 451 combination reg byte a [ main::pos#2 main::pos#1 ] reg byte x [ main::vacant#3 main::vacant#2 ] 
Uplifting [] best 451 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Demonstrates error "Sequence does not contain all blocks from the program."
  // Upstart
  // Commodore 64 PRG executable file
.file [name="block-error-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: {
    .const move = 1
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::vacant#3 = 1 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #1
    // [1] phi main::pos#2 = 1 [phi:main->main::@1#1] -- vbuaa=vbuc1 
    lda #1
    jmp __b1
    // [1] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [1] phi main::vacant#3 = main::vacant#2 [phi:main::@3->main::@1#0] -- register_copy 
    // [1] phi main::pos#2 = main::pos#1 [phi:main::@3->main::@1#1] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [2] main::pos#1 = main::pos#2 + main::move -- vbuaa=vbuaa_plus_vbuc1 
    clc
    adc #move
    // [3] if(0==main::pos#1) goto main::@4 -- 0_eq_vbuaa_then_la1 
    cmp #0
    beq __b4_from___b1
    // [5] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    // [5] phi main::vacant#2 = 0 [phi:main::@1->main::@2#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b2
    // [4] phi from main::@1 to main::@4 [phi:main::@1->main::@4]
  __b4_from___b1:
    jmp __b4
    // main::@4
  __b4:
    // [5] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
  __b2_from___b4:
    // [5] phi main::vacant#2 = main::vacant#3 [phi:main::@4->main::@2#0] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [6] if(0==main::pos#1) goto main::@return -- 0_eq_vbuaa_then_la1 
    cmp #0
    beq __breturn
    jmp __b3
    // main::@3
  __b3:
    // [7] if(0!=main::vacant#2) goto main::@1 -- 0_neq_vbuxx_then_la1 
    cpx #0
    bne __b1_from___b3
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __b4
Removing instruction jmp __b2
Removing instruction jmp __b3
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing instruction lda #1 with TXA
Replacing label __b4_from___b1 with __b2
Replacing label __b1_from___b3 with __b1
Removing instruction __b1_from___b3:
Removing instruction __b4_from___b1:
Removing instruction __b4:
Removing instruction __b2_from___b4:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __b2_from___b1:
Removing instruction __b3:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
void main()
__constant char main::move = 1
char main::pos
char main::pos#1 // reg byte a 7.333333333333333
char main::pos#2 // reg byte a 22.0
char main::vacant
char main::vacant#2 // reg byte x 11.0
char main::vacant#3 // reg byte x 5.5

reg byte a [ main::pos#2 main::pos#1 ]
reg byte x [ main::vacant#3 main::vacant#2 ]


FINAL ASSEMBLER
Score: 241

  // File Comments
// Demonstrates error "Sequence does not contain all blocks from the program."
  // Upstart
  // Commodore 64 PRG executable file
.file [name="block-error-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: {
    .const move = 1
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::vacant#3 = 1 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #1
    // [1] phi main::pos#2 = 1 [phi:main->main::@1#1] -- vbuaa=vbuc1 
    txa
    // [1] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
    // [1] phi main::vacant#3 = main::vacant#2 [phi:main::@3->main::@1#0] -- register_copy 
    // [1] phi main::pos#2 = main::pos#1 [phi:main::@3->main::@1#1] -- register_copy 
    // main::@1
  __b1:
    // pos += move
    // [2] main::pos#1 = main::pos#2 + main::move -- vbuaa=vbuaa_plus_vbuc1 
    clc
    adc #move
    // if(pos)
    // [3] if(0==main::pos#1) goto main::@4 -- 0_eq_vbuaa_then_la1 
    cmp #0
    beq __b2
    // [5] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // [5] phi main::vacant#2 = 0 [phi:main::@1->main::@2#0] -- vbuxx=vbuc1 
    ldx #0
    // [4] phi from main::@1 to main::@4 [phi:main::@1->main::@4]
    // main::@4
    // [5] phi from main::@4 to main::@2 [phi:main::@4->main::@2]
    // [5] phi main::vacant#2 = main::vacant#3 [phi:main::@4->main::@2#0] -- register_copy 
    // main::@2
  __b2:
    // while(pos && vacant)
    // [6] if(0==main::pos#1) goto main::@return -- 0_eq_vbuaa_then_la1 
    cmp #0
    beq __breturn
    // main::@3
    // [7] if(0!=main::vacant#2) goto main::@1 -- 0_neq_vbuxx_then_la1 
    cpx #0
    bne __b1
    // main::@return
  __breturn:
    // }
    // [8] return 
    rts
}
  // File Data

