Culled Empty Block (label) main::@8
Culled Empty Block (label) main::@9
Culled Empty Block (label) main::@10
Culled Empty Block (label) main::@11
Culled Empty Block (label) main::@12

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1

(void()) main()
main: scope:[main]  from @1
  (byte) main::b#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@4
  (byte) main::b#2 ← phi( main/(byte) main::b#0 main::@4/(byte) main::b#1 )
  (bool~) main::$0 ← (byte) main::b#2 == (number) 0
  if((bool~) main::$0) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  (byte) main::b#5 ← phi( main::@1/(byte) main::b#2 )
  (byte~) main::$6 ← (byte) 'a'
  to:main::@4
main::@3: scope:[main]  from main::@1
  (byte) main::b#3 ← phi( main::@1/(byte) main::b#2 )
  (bool~) main::$1 ← (byte) main::b#3 == (number) 1
  if((bool~) main::$1) goto main::@5
  to:main::@6
main::@5: scope:[main]  from main::@3
  (byte) main::b#7 ← phi( main::@3/(byte) main::b#3 )
  (byte~) main::$3 ← (byte) 'b'
  to:main::@7
main::@6: scope:[main]  from main::@3
  (byte) main::b#8 ← phi( main::@3/(byte) main::b#3 )
  (byte~) main::$2 ← (byte) 'c'
  to:main::@7
main::@7: scope:[main]  from main::@5 main::@6
  (byte) main::b#6 ← phi( main::@5/(byte) main::b#7 main::@6/(byte) main::b#8 )
  (byte~) main::$4 ← phi( main::@5/(byte~) main::$3 main::@6/(byte~) main::$2 )
  (byte~) main::$5 ← (byte~) main::$4
  to:main::@4
main::@4: scope:[main]  from main::@2 main::@7
  (byte) main::b#4 ← phi( main::@2/(byte) main::b#5 main::@7/(byte) main::b#6 )
  (byte~) main::$7 ← phi( main::@2/(byte~) main::$6 main::@7/(byte~) main::$5 )
  *((const byte*) main::SCREEN) ← (byte~) main::$7
  (byte) main::b#1 ← (byte) main::b#4 + rangenext(0,2)
  (bool~) main::$8 ← (byte) main::b#1 != rangelast(0,2)
  if((bool~) main::$8) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@4
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(void()) main()
(bool~) main::$0
(bool~) main::$1
(byte~) main::$2
(byte~) main::$3
(byte~) main::$4
(byte~) main::$5
(byte~) main::$6
(byte~) main::$7
(bool~) main::$8
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@7
(label) main::@return
(const byte*) main::SCREEN = (byte*)(number) $400
(byte) main::b
(byte) main::b#0
(byte) main::b#1
(byte) main::b#2
(byte) main::b#3
(byte) main::b#4
(byte) main::b#5
(byte) main::b#6
(byte) main::b#7
(byte) main::b#8

Adding number conversion cast (unumber) 0 in (bool~) main::$0 ← (byte) main::b#2 == (number) 0
Adding number conversion cast (unumber) 1 in (bool~) main::$1 ← (byte) main::b#3 == (number) 1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) main::b#2 = (byte) main::b#5 (byte) main::b#3 (byte) main::b#7 (byte) main::b#8 
Alias (byte~) main::$5 = (byte~) main::$4 
Successful SSA optimization Pass2AliasElimination
Alias (byte) main::b#2 = (byte) main::b#6 
Successful SSA optimization Pass2AliasElimination
Alias (byte) main::b#2 = (byte) main::b#4 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$0 [3] if((byte) main::b#2==(byte) 0) goto main::@2
Simple Condition (bool~) main::$1 [6] if((byte) main::b#2==(byte) 1) goto main::@5
Simple Condition (bool~) main::$8 [14] if((byte) main::b#1!=rangelast(0,2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) main::b#0 = 0
Constant (const byte) main::$6 = 'a'
Constant (const byte) main::$3 = 'b'
Constant (const byte) main::$2 = 'c'
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [12] main::b#1 ← ++ main::b#2 to ++
Resolved ranged comparison value [14] if(main::b#1!=rangelast(0,2)) goto main::@1 to (number) 3
Adding number conversion cast (unumber) 3 in if((byte) main::b#1!=(number) 3) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) main::b#0
Constant inlined main::$6 = (byte) 'a'
Constant inlined main::$3 = (byte) 'b'
Constant inlined main::b#0 = (byte) 0
Constant inlined main::$2 = (byte) 'c'
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@13(between main::@4 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@6
Adding NOP phi() at start of main::@5
Adding NOP phi() at start of main::@2
CALL GRAPH
Calls in [] to main:2 

Created 3 initial phi equivalence classes
Coalesced [11] main::$9 ← main::$5
Coalesced [17] main::b#9 ← main::b#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@6
Culled Empty Block (label) main::@13
Culled Empty Block (label) main::@2
Renumbering block main::@3 to main::@2
Renumbering block main::@4 to main::@3
Renumbering block main::@5 to main::@4
Renumbering block main::@7 to main::@5
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@4

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()

(void()) main()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@3
  [5] (byte) main::b#2 ← phi( main/(byte) 0 main::@3/(byte) main::b#1 )
  [6] if((byte) main::b#2==(byte) 0) goto main::@3
  to:main::@2
main::@2: scope:[main]  from main::@1
  [7] if((byte) main::b#2==(byte) 1) goto main::@4
  to:main::@5
main::@4: scope:[main]  from main::@2
  [8] phi()
  to:main::@5
main::@5: scope:[main]  from main::@2 main::@4
  [9] (byte~) main::$5 ← phi( main::@4/(byte) 'b' main::@2/(byte) 'c' )
  to:main::@3
main::@3: scope:[main]  from main::@1 main::@5
  [10] (byte~) main::$7 ← phi( main::@1/(byte) 'a' main::@5/(byte~) main::$5 )
  [11] *((const byte*) main::SCREEN) ← (byte~) main::$7
  [12] (byte) main::b#1 ← ++ (byte) main::b#2
  [13] if((byte) main::b#1!=(byte) 3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$5 11.0
(byte~) main::$7 22.0
(byte) main::b
(byte) main::b#1 16.5
(byte) main::b#2 6.285714285714286

Initial phi equivalence classes
[ main::b#2 main::b#1 ]
[ main::$7 main::$5 ]
Complete equivalence classes
[ main::b#2 main::b#1 ]
[ main::$7 main::$5 ]
Allocated zp[1]:2 [ main::b#2 main::b#1 ]
Allocated zp[1]:3 [ main::$7 main::$5 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Demonstrates error with nested ternary operator
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label SCREEN = $400
    .label __5 = 3
    .label __7 = 3
    .label b = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::b#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z b
    jmp __b1
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] if((byte) main::b#2==(byte) 0) goto main::@3 -- vbuz1_eq_0_then_la1 
    lda.z b
    cmp #0
    beq __b3_from___b1
    jmp __b2
    // main::@2
  __b2:
    // [7] if((byte) main::b#2==(byte) 1) goto main::@4 -- vbuz1_eq_vbuc1_then_la1 
    lda #1
    cmp.z b
    beq __b4_from___b2
    // [9] phi from main::@2 to main::@5 [phi:main::@2->main::@5]
  __b5_from___b2:
    // [9] phi (byte~) main::$5 = (byte) 'c' [phi:main::@2->main::@5#0] -- vbuz1=vbuc1 
    lda #'c'
    sta.z __5
    jmp __b5
    // [8] phi from main::@2 to main::@4 [phi:main::@2->main::@4]
  __b4_from___b2:
    jmp __b4
    // main::@4
  __b4:
    // [9] phi from main::@4 to main::@5 [phi:main::@4->main::@5]
  __b5_from___b4:
    // [9] phi (byte~) main::$5 = (byte) 'b' [phi:main::@4->main::@5#0] -- vbuz1=vbuc1 
    lda #'b'
    sta.z __5
    jmp __b5
    // main::@5
  __b5:
    // [10] phi from main::@5 to main::@3 [phi:main::@5->main::@3]
  __b3_from___b5:
    // [10] phi (byte~) main::$7 = (byte~) main::$5 [phi:main::@5->main::@3#0] -- register_copy 
    jmp __b3
    // [10] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
  __b3_from___b1:
    // [10] phi (byte~) main::$7 = (byte) 'a' [phi:main::@1->main::@3#0] -- vbuz1=vbuc1 
    lda #'a'
    sta.z __7
    jmp __b3
    // main::@3
  __b3:
    // [11] *((const byte*) main::SCREEN) ← (byte~) main::$7 -- _deref_pbuc1=vbuz1 
    lda.z __7
    sta SCREEN
    // [12] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuz1=_inc_vbuz1 
    inc.z b
    // [13] if((byte) main::b#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp.z b
    bne __b1_from___b3
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp[1]:2 [ main::b#2 main::b#1 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::$7 main::$5 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 33: zp[1]:3 [ main::$7 main::$5 ] 22.79: zp[1]:2 [ main::b#2 main::b#1 ] 
Uplift Scope [] 

Uplifting [main] best 563 combination reg byte a [ main::$7 main::$5 ] reg byte x [ main::b#2 main::b#1 ] 
Uplifting [] best 563 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Demonstrates error with nested ternary operator
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @begin
__bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
__b1_from___bbegin:
  jmp __b1
  // @1
__b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from___b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label SCREEN = $400
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::b#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] if((byte) main::b#2==(byte) 0) goto main::@3 -- vbuxx_eq_0_then_la1 
    cpx #0
    beq __b3_from___b1
    jmp __b2
    // main::@2
  __b2:
    // [7] if((byte) main::b#2==(byte) 1) goto main::@4 -- vbuxx_eq_vbuc1_then_la1 
    cpx #1
    beq __b4_from___b2
    // [9] phi from main::@2 to main::@5 [phi:main::@2->main::@5]
  __b5_from___b2:
    // [9] phi (byte~) main::$5 = (byte) 'c' [phi:main::@2->main::@5#0] -- vbuaa=vbuc1 
    lda #'c'
    jmp __b5
    // [8] phi from main::@2 to main::@4 [phi:main::@2->main::@4]
  __b4_from___b2:
    jmp __b4
    // main::@4
  __b4:
    // [9] phi from main::@4 to main::@5 [phi:main::@4->main::@5]
  __b5_from___b4:
    // [9] phi (byte~) main::$5 = (byte) 'b' [phi:main::@4->main::@5#0] -- vbuaa=vbuc1 
    lda #'b'
    jmp __b5
    // main::@5
  __b5:
    // [10] phi from main::@5 to main::@3 [phi:main::@5->main::@3]
  __b3_from___b5:
    // [10] phi (byte~) main::$7 = (byte~) main::$5 [phi:main::@5->main::@3#0] -- register_copy 
    jmp __b3
    // [10] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
  __b3_from___b1:
    // [10] phi (byte~) main::$7 = (byte) 'a' [phi:main::@1->main::@3#0] -- vbuaa=vbuc1 
    lda #'a'
    jmp __b3
    // main::@3
  __b3:
    // [11] *((const byte*) main::SCREEN) ← (byte~) main::$7 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // [12] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if((byte) main::b#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne __b1_from___b3
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b4
Removing instruction jmp __b5
Removing instruction jmp __b3
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b4_from___b2 with __b4
Replacing label __b1_from___b3 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b3:
Removing instruction __b4_from___b2:
Removing instruction __b5_from___b4:
Removing instruction __b3_from___b5:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b2:
Removing instruction __b5_from___b2:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Skipping double jump to __b3 in jmp __b5
Succesful ASM optimization Pass5DoubleJumpElimination
Relabelling long label __b3_from___b1 to b1
Succesful ASM optimization Pass5RelabelLongLabels
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Removing instruction __b5:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(byte~) main::$5 reg byte a 11.0
(byte~) main::$7 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@return
(const byte*) main::SCREEN = (byte*) 1024
(byte) main::b
(byte) main::b#1 reg byte x 16.5
(byte) main::b#2 reg byte x 6.285714285714286

reg byte x [ main::b#2 main::b#1 ]
reg byte a [ main::$7 main::$5 ]


FINAL ASSEMBLER
Score: 341

  // File Comments
// Demonstrates error with nested ternary operator
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label SCREEN = $400
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::b#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
    // [5] phi (byte) main::b#2 = (byte) main::b#1 [phi:main::@3->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // (b == 0) ? 'a' : ((b == 1) ? 'b' : 'c')
    // [6] if((byte) main::b#2==(byte) 0) goto main::@3 -- vbuxx_eq_0_then_la1 
    cpx #0
    beq b1
    // main::@2
    // (b == 1) ? 'b' : 'c'
    // [7] if((byte) main::b#2==(byte) 1) goto main::@4 -- vbuxx_eq_vbuc1_then_la1 
    cpx #1
    beq __b4
    // [9] phi from main::@2 to main::@5 [phi:main::@2->main::@5]
    // [9] phi (byte~) main::$5 = (byte) 'c' [phi:main::@2->main::@5#0] -- vbuaa=vbuc1 
    lda #'c'
    jmp __b3
    // [8] phi from main::@2 to main::@4 [phi:main::@2->main::@4]
    // main::@4
  __b4:
    // [9] phi from main::@4 to main::@5 [phi:main::@4->main::@5]
    // [9] phi (byte~) main::$5 = (byte) 'b' [phi:main::@4->main::@5#0] -- vbuaa=vbuc1 
    lda #'b'
    // main::@5
    // [10] phi from main::@5 to main::@3 [phi:main::@5->main::@3]
    // [10] phi (byte~) main::$7 = (byte~) main::$5 [phi:main::@5->main::@3#0] -- register_copy 
    jmp __b3
    // [10] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
  b1:
    // [10] phi (byte~) main::$7 = (byte) 'a' [phi:main::@1->main::@3#0] -- vbuaa=vbuc1 
    lda #'a'
    // main::@3
  __b3:
    // *SCREEN = (b == 0) ? 'a' : ((b == 1) ? 'b' : 'c')
    // [11] *((const byte*) main::SCREEN) ← (byte~) main::$7 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // for ( byte b: 0..2 )
    // [12] (byte) main::b#1 ← ++ (byte) main::b#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if((byte) main::b#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #3
    bne __b1
    // main::@return
    // }
    // [14] return 
    rts
}
  // File Data

