Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
Culled Empty Block (label) main::@7
Culled Empty Block (label) @1
Culled Empty Block (label) cond::@1
Culled Empty Block (label) @2
Culled Empty Block (label) m1::@1
Culled Empty Block (label) @3
Culled Empty Block (label) m2::@1

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

(void()) main()
main: scope:[main]  from @4
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@4
  (byte) main::i#2 ← phi( main/(byte) main::i#0 main::@4/(byte) main::i#1 )
  (byte) cond::b#0 ← (byte) main::i#2
  call cond 
  (bool) cond::return#0 ← (bool) cond::return#2
  to:main::@8
main::@8: scope:[main]  from main::@1
  (byte) main::i#6 ← phi( main::@1/(byte) main::i#2 )
  (bool) cond::return#3 ← phi( main::@1/(bool) cond::return#0 )
  (bool~) main::$0 ← (bool) cond::return#3
  if((bool~) main::$0) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@8
  (byte) main::i#3 ← phi( main::@8/(byte) main::i#6 )
  (byte) m1::i#0 ← (byte) main::i#3
  call m1 
  (byte) m1::return#0 ← (byte) m1::return#2
  to:main::@9
main::@9: scope:[main]  from main::@2
  (byte) main::i#8 ← phi( main::@2/(byte) main::i#3 )
  (byte) m1::return#3 ← phi( main::@2/(byte) m1::return#0 )
  (byte~) main::$3 ← (byte) m1::return#3
  (byte~) main::$4 ← (byte~) main::$3
  to:main::@4
main::@3: scope:[main]  from main::@8
  (byte) main::i#4 ← phi( main::@8/(byte) main::i#6 )
  (byte) m2::i#0 ← (byte) main::i#4
  call m2 
  (byte) m2::return#0 ← (byte) m2::return#2
  to:main::@10
main::@10: scope:[main]  from main::@3
  (byte) main::i#7 ← phi( main::@3/(byte) main::i#4 )
  (byte) m2::return#3 ← phi( main::@3/(byte) m2::return#0 )
  (byte~) main::$1 ← (byte) m2::return#3
  (byte~) main::$2 ← (byte~) main::$1
  to:main::@4
main::@4: scope:[main]  from main::@10 main::@9
  (byte) main::i#5 ← phi( main::@10/(byte) main::i#7 main::@9/(byte) main::i#8 )
  (byte~) main::$5 ← phi( main::@9/(byte~) main::$4 main::@10/(byte~) main::$2 )
  *((const byte*) main::SCREEN + (byte) main::i#5) ← (byte~) main::$5
  (byte) main::i#1 ← (byte) main::i#5 + rangenext(0,9)
  (bool~) main::$6 ← (byte) main::i#1 != rangelast(0,9)
  if((bool~) main::$6) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@4
  return 
  to:@return

(bool()) cond((byte) cond::b)
cond: scope:[cond]  from main::@1
  (byte) cond::b#1 ← phi( main::@1/(byte) cond::b#0 )
  (bool~) cond::$0 ← (byte) cond::b#1 < (number) 5
  (bool) cond::return#1 ← (bool~) cond::$0
  to:cond::@return
cond::@return: scope:[cond]  from cond
  (bool) cond::return#4 ← phi( cond/(bool) cond::return#1 )
  (bool) cond::return#2 ← (bool) cond::return#4
  return 
  to:@return

(byte()) m1((byte) m1::i)
m1: scope:[m1]  from main::@2
  (byte) m1::i#1 ← phi( main::@2/(byte) m1::i#0 )
  (number~) m1::$0 ← (number) 5 + (byte) m1::i#1
  (byte) m1::return#1 ← (number~) m1::$0
  to:m1::@return
m1::@return: scope:[m1]  from m1
  (byte) m1::return#4 ← phi( m1/(byte) m1::return#1 )
  (byte) m1::return#2 ← (byte) m1::return#4
  return 
  to:@return

(byte()) m2((byte) m2::i)
m2: scope:[m2]  from main::@3
  (byte) m2::i#1 ← phi( main::@3/(byte) m2::i#0 )
  (number~) m2::$0 ← (number) $a + (byte) m2::i#1
  (byte) m2::return#1 ← (number~) m2::$0
  to:m2::@return
m2::@return: scope:[m2]  from m2
  (byte) m2::return#4 ← phi( m2/(byte) m2::return#1 )
  (byte) m2::return#2 ← (byte) m2::return#4
  return 
  to:@return
@4: scope:[]  from @begin
  call main 
  to:@5
@5: scope:[]  from @4
  to:@end
@end: scope:[]  from @5

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

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

Created 2 initial phi equivalence classes
Coalesced [16] main::$8 ← main::$2
Coalesced [22] main::i#9 ← main::i#1
Coalesced [27] main::$7 ← main::$4
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @5
Culled Empty Block (label) main::@11
Renumbering block @4 to @1
Renumbering block main::@8 to main::@5
Renumbering block main::@9 to main::@6
Renumbering block main::@10 to main::@7
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

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::@4
  [5] (byte) main::i#2 ← phi( main/(byte) 0 main::@4/(byte) main::i#1 )
  [6] (byte) cond::b#0 ← (byte) main::i#2
  [7] call cond 
  [8] (bool) cond::return#0 ← (bool) cond::return#1
  to:main::@5
main::@5: scope:[main]  from main::@1
  [9] (bool~) main::$0 ← (bool) cond::return#0
  [10] if((bool~) main::$0) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@5
  [11] (byte) m2::i#0 ← (byte) main::i#2
  [12] call m2 
  [13] (byte) m2::return#0 ← (byte) m2::return#1
  to:main::@7
main::@7: scope:[main]  from main::@3
  [14] (byte~) main::$2 ← (byte) m2::return#0
  to:main::@4
main::@4: scope:[main]  from main::@6 main::@7
  [15] (byte~) main::$5 ← phi( main::@6/(byte~) main::$4 main::@7/(byte~) main::$2 )
  [16] *((const byte*) main::SCREEN + (byte) main::i#2) ← (byte~) main::$5
  [17] (byte) main::i#1 ← ++ (byte) main::i#2
  [18] if((byte) main::i#1!=(byte) $a) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@4
  [19] return 
  to:@return
main::@2: scope:[main]  from main::@5
  [20] (byte) m1::i#0 ← (byte) main::i#2
  [21] call m1 
  [22] (byte) m1::return#0 ← (byte) m1::return#1
  to:main::@6
main::@6: scope:[main]  from main::@2
  [23] (byte~) main::$4 ← (byte) m1::return#0
  to:main::@4

(byte()) m1((byte) m1::i)
m1: scope:[m1]  from main::@2
  [24] (byte) m1::return#1 ← (byte) 5 + (byte) m1::i#0
  to:m1::@return
m1::@return: scope:[m1]  from m1
  [25] return 
  to:@return

(byte()) m2((byte) m2::i)
m2: scope:[m2]  from main::@3
  [26] (byte) m2::return#1 ← (byte) $a + (byte) m2::i#0
  to:m2::@return
m2::@return: scope:[m2]  from m2
  [27] return 
  to:@return

(bool()) cond((byte) cond::b)
cond: scope:[cond]  from main::@1
  [28] (bool) cond::return#1 ← (byte) cond::b#0 < (byte) 5
  to:cond::@return
cond::@return: scope:[cond]  from cond
  [29] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(bool()) cond((byte) cond::b)
(byte) cond::b
(byte) cond::b#0 13.0
(bool) cond::return
(bool) cond::return#0 22.0
(bool) cond::return#1 4.333333333333333
(byte()) m1((byte) m1::i)
(byte) m1::i
(byte) m1::i#0 13.0
(byte) m1::return
(byte) m1::return#0 22.0
(byte) m1::return#1 4.333333333333333
(byte()) m2((byte) m2::i)
(byte) m2::i
(byte) m2::i#0 13.0
(byte) m2::return
(byte) m2::return#0 22.0
(byte) m2::return#1 4.333333333333333
(void()) main()
(bool~) main::$0 22.0
(byte~) main::$2 22.0
(byte~) main::$4 22.0
(byte~) main::$5 33.0
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 4.125

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::$5 main::$4 main::$2 ]
Added variable cond::b#0 to live range equivalence class [ cond::b#0 ]
Added variable cond::return#0 to live range equivalence class [ cond::return#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable m2::i#0 to live range equivalence class [ m2::i#0 ]
Added variable m2::return#0 to live range equivalence class [ m2::return#0 ]
Added variable m1::i#0 to live range equivalence class [ m1::i#0 ]
Added variable m1::return#0 to live range equivalence class [ m1::return#0 ]
Added variable m1::return#1 to live range equivalence class [ m1::return#1 ]
Added variable m2::return#1 to live range equivalence class [ m2::return#1 ]
Added variable cond::return#1 to live range equivalence class [ cond::return#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::$5 main::$4 main::$2 ]
[ cond::b#0 ]
[ cond::return#0 ]
[ main::$0 ]
[ m2::i#0 ]
[ m2::return#0 ]
[ m1::i#0 ]
[ m1::return#0 ]
[ m1::return#1 ]
[ m2::return#1 ]
[ cond::return#1 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ main::$5 main::$4 main::$2 ]
Allocated zp[1]:4 [ cond::b#0 ]
Allocated zp[1]:5 [ cond::return#0 ]
Allocated zp[1]:6 [ main::$0 ]
Allocated zp[1]:7 [ m2::i#0 ]
Allocated zp[1]:8 [ m2::return#0 ]
Allocated zp[1]:9 [ m1::i#0 ]
Allocated zp[1]:10 [ m1::return#0 ]
Allocated zp[1]:11 [ m1::return#1 ]
Allocated zp[1]:12 [ m2::return#1 ]
Allocated zp[1]:13 [ cond::return#1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Tests the ternary operator - when the condition is constant
  // 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 __0 = 6
    .label __2 = 3
    .label __4 = 3
    .label __5 = 3
    .label i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  __b1_from___b4:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) cond::b#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda.z i
    sta.z cond.b
    // [7] call cond 
    jsr cond
    // [8] (bool) cond::return#0 ← (bool) cond::return#1 -- vboz1=vboz2 
    lda.z cond.return_1
    sta.z cond.return
    jmp __b5
    // main::@5
  __b5:
    // [9] (bool~) main::$0 ← (bool) cond::return#0 -- vboz1=vboz2 
    lda.z cond.return
    sta.z __0
    // [10] if((bool~) main::$0) goto main::@2 -- vboz1_then_la1 
    lda.z __0
    cmp #0
    bne __b2
    jmp __b3
    // main::@3
  __b3:
    // [11] (byte) m2::i#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda.z i
    sta.z m2.i
    // [12] call m2 
    jsr m2
    // [13] (byte) m2::return#0 ← (byte) m2::return#1 -- vbuz1=vbuz2 
    lda.z m2.return_1
    sta.z m2.return
    jmp __b7
    // main::@7
  __b7:
    // [14] (byte~) main::$2 ← (byte) m2::return#0 -- vbuz1=vbuz2 
    lda.z m2.return
    sta.z __2
    // [15] phi from main::@6 main::@7 to main::@4 [phi:main::@6/main::@7->main::@4]
  __b4_from___b6:
  __b4_from___b7:
    // [15] phi (byte~) main::$5 = (byte~) main::$4 [phi:main::@6/main::@7->main::@4#0] -- register_copy 
    jmp __b4
    // main::@4
  __b4:
    // [16] *((const byte*) main::SCREEN + (byte) main::i#2) ← (byte~) main::$5 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z __5
    ldy.z i
    sta SCREEN,y
    // [17] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [18] if((byte) main::i#1!=(byte) $a) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$a
    cmp.z i
    bne __b1_from___b4
    jmp __breturn
    // main::@return
  __breturn:
    // [19] return 
    rts
    // main::@2
  __b2:
    // [20] (byte) m1::i#0 ← (byte) main::i#2 -- vbuz1=vbuz2 
    lda.z i
    sta.z m1.i
    // [21] call m1 
    jsr m1
    // [22] (byte) m1::return#0 ← (byte) m1::return#1 -- vbuz1=vbuz2 
    lda.z m1.return_1
    sta.z m1.return
    jmp __b6
    // main::@6
  __b6:
    // [23] (byte~) main::$4 ← (byte) m1::return#0 -- vbuz1=vbuz2 
    lda.z m1.return
    sta.z __4
    jmp __b4_from___b6
}
  // m1
// m1(byte zp(9) i)
m1: {
    .label i = 9
    .label return = $a
    .label return_1 = $b
    // [24] (byte) m1::return#1 ← (byte) 5 + (byte) m1::i#0 -- vbuz1=vbuc1_plus_vbuz2 
    lax.z i
    axs #-[5]
    stx.z return_1
    jmp __breturn
    // m1::@return
  __breturn:
    // [25] return 
    rts
}
  // m2
// m2(byte zp(7) i)
m2: {
    .label i = 7
    .label return = 8
    .label return_1 = $c
    // [26] (byte) m2::return#1 ← (byte) $a + (byte) m2::i#0 -- vbuz1=vbuc1_plus_vbuz2 
    lax.z i
    axs #-[$a]
    stx.z return_1
    jmp __breturn
    // m2::@return
  __breturn:
    // [27] return 
    rts
}
  // cond
// cond(byte zp(4) b)
cond: {
    .label b = 4
    .label return = 5
    .label return_1 = $d
    // [28] (bool) cond::return#1 ← (byte) cond::b#0 < (byte) 5 -- vboz1=vbuz2_lt_vbuc1 
    lda.z b
    cmp #5
    lda #0
    rol
    eor #1
    sta.z return_1
    jmp __breturn
    // cond::@return
  __breturn:
    // [29] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [28] (bool) cond::return#1 ← (byte) cond::b#0 < (byte) 5 [ cond::return#1 ] ( main:2::cond:7 [ main::i#2 cond::return#1 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [28] (bool) cond::return#1 ← (byte) cond::b#0 < (byte) 5 [ cond::return#1 ] ( main:2::cond:7 [ main::i#2 cond::return#1 ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::$5 main::$4 main::$2 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ cond::b#0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ cond::return#0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:6 [ main::$0 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:7 [ m2::i#0 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:8 [ m2::return#0 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:9 [ m1::i#0 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:10 [ m1::return#0 ] : zp[1]:10 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:11 [ m1::return#1 ] : zp[1]:11 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:12 [ m2::return#1 ] : zp[1]:12 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:13 [ cond::return#1 ] : zp[1]:13 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 77: zp[1]:3 [ main::$5 main::$4 main::$2 ] 22: zp[1]:6 [ main::$0 ] 20.62: zp[1]:2 [ main::i#2 main::i#1 ] 
Uplift Scope [cond] 22: zp[1]:5 [ cond::return#0 ] 13: zp[1]:4 [ cond::b#0 ] 4.33: zp[1]:13 [ cond::return#1 ] 
Uplift Scope [m1] 22: zp[1]:10 [ m1::return#0 ] 13: zp[1]:9 [ m1::i#0 ] 4.33: zp[1]:11 [ m1::return#1 ] 
Uplift Scope [m2] 22: zp[1]:8 [ m2::return#0 ] 13: zp[1]:7 [ m2::i#0 ] 4.33: zp[1]:12 [ m2::return#1 ] 
Uplift Scope [] 

Uplifting [main] best 1065 combination reg byte a [ main::$5 main::$4 main::$2 ] reg byte a [ main::$0 ] reg byte y [ main::i#2 main::i#1 ] 
Uplifting [cond] best 939 combination reg byte a [ cond::return#0 ] reg byte y [ cond::b#0 ] reg byte a [ cond::return#1 ] 
Uplifting [m1] best 817 combination reg byte a [ m1::return#0 ] reg byte y [ m1::i#0 ] reg byte a [ m1::return#1 ] 
Uplifting [m2] best 695 combination reg byte a [ m2::return#0 ] reg byte y [ m2::i#0 ] reg byte a [ m2::return#1 ] 
Uplifting [] best 695 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests the ternary operator - when the condition is constant
  // 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::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    jmp __b1
    // [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  __b1_from___b4:
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) cond::b#0 ← (byte) main::i#2
    // [7] call cond 
    jsr cond
    // [8] (bool) cond::return#0 ← (bool) cond::return#1
    jmp __b5
    // main::@5
  __b5:
    // [9] (bool~) main::$0 ← (bool) cond::return#0
    // [10] if((bool~) main::$0) goto main::@2 -- vboaa_then_la1 
    cmp #0
    bne __b2
    jmp __b3
    // main::@3
  __b3:
    // [11] (byte) m2::i#0 ← (byte) main::i#2
    // [12] call m2 
    jsr m2
    // [13] (byte) m2::return#0 ← (byte) m2::return#1
    jmp __b7
    // main::@7
  __b7:
    // [14] (byte~) main::$2 ← (byte) m2::return#0
    // [15] phi from main::@6 main::@7 to main::@4 [phi:main::@6/main::@7->main::@4]
  __b4_from___b6:
  __b4_from___b7:
    // [15] phi (byte~) main::$5 = (byte~) main::$4 [phi:main::@6/main::@7->main::@4#0] -- register_copy 
    jmp __b4
    // main::@4
  __b4:
    // [16] *((const byte*) main::SCREEN + (byte) main::i#2) ← (byte~) main::$5 -- pbuc1_derefidx_vbuyy=vbuaa 
    sta SCREEN,y
    // [17] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // [18] if((byte) main::i#1!=(byte) $a) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$a
    bne __b1_from___b4
    jmp __breturn
    // main::@return
  __breturn:
    // [19] return 
    rts
    // main::@2
  __b2:
    // [20] (byte) m1::i#0 ← (byte) main::i#2
    // [21] call m1 
    jsr m1
    // [22] (byte) m1::return#0 ← (byte) m1::return#1
    jmp __b6
    // main::@6
  __b6:
    // [23] (byte~) main::$4 ← (byte) m1::return#0
    jmp __b4_from___b6
}
  // m1
// m1(byte register(Y) i)
m1: {
    // [24] (byte) m1::return#1 ← (byte) 5 + (byte) m1::i#0 -- vbuaa=vbuc1_plus_vbuyy 
    tya
    clc
    adc #5
    jmp __breturn
    // m1::@return
  __breturn:
    // [25] return 
    rts
}
  // m2
// m2(byte register(Y) i)
m2: {
    // [26] (byte) m2::return#1 ← (byte) $a + (byte) m2::i#0 -- vbuaa=vbuc1_plus_vbuyy 
    tya
    clc
    adc #$a
    jmp __breturn
    // m2::@return
  __breturn:
    // [27] return 
    rts
}
  // cond
// cond(byte register(Y) b)
cond: {
    // [28] (bool) cond::return#1 ← (byte) cond::b#0 < (byte) 5 -- vboaa=vbuyy_lt_vbuc1 
    cpy #5
    lda #0
    rol
    eor #1
    jmp __breturn
    // cond::@return
  __breturn:
    // [29] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b5
Removing instruction jmp __b3
Removing instruction jmp __b7
Removing instruction jmp __b4
Removing instruction jmp __breturn
Removing instruction jmp __b6
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b4 with __b1
Replacing label __b4_from___b6 with __b4
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b4:
Removing instruction __b7:
Removing instruction __b4_from___b6:
Removing instruction __b4_from___b7:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b5:
Removing instruction __b3:
Removing instruction __breturn:
Removing instruction __b6:
Removing instruction __breturn:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(bool()) cond((byte) cond::b)
(label) cond::@return
(byte) cond::b
(byte) cond::b#0 reg byte y 13.0
(bool) cond::return
(bool) cond::return#0 reg byte a 22.0
(bool) cond::return#1 reg byte a 4.333333333333333
(byte()) m1((byte) m1::i)
(label) m1::@return
(byte) m1::i
(byte) m1::i#0 reg byte y 13.0
(byte) m1::return
(byte) m1::return#0 reg byte a 22.0
(byte) m1::return#1 reg byte a 4.333333333333333
(byte()) m2((byte) m2::i)
(label) m2::@return
(byte) m2::i
(byte) m2::i#0 reg byte y 13.0
(byte) m2::return
(byte) m2::return#0 reg byte a 22.0
(byte) m2::return#1 reg byte a 4.333333333333333
(void()) main()
(bool~) main::$0 reg byte a 22.0
(byte~) main::$2 reg byte a 22.0
(byte~) main::$4 reg byte a 22.0
(byte~) main::$5 reg byte a 33.0
(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*) 1024
(byte) main::i
(byte) main::i#1 reg byte y 16.5
(byte) main::i#2 reg byte y 4.125

reg byte y [ main::i#2 main::i#1 ]
reg byte a [ main::$5 main::$4 main::$2 ]
reg byte y [ cond::b#0 ]
reg byte a [ cond::return#0 ]
reg byte a [ main::$0 ]
reg byte y [ m2::i#0 ]
reg byte a [ m2::return#0 ]
reg byte y [ m1::i#0 ]
reg byte a [ m1::return#0 ]
reg byte a [ m1::return#1 ]
reg byte a [ m2::return#1 ]
reg byte a [ cond::return#1 ]


FINAL ASSEMBLER
Score: 434

  // File Comments
// Tests the ternary operator - when the condition is constant
  // 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::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    // [5] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
    // [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@4->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // cond(i)
    // [6] (byte) cond::b#0 ← (byte) main::i#2
    // [7] call cond 
    jsr cond
    // [8] (bool) cond::return#0 ← (bool) cond::return#1
    // main::@5
    // [9] (bool~) main::$0 ← (bool) cond::return#0
    // cond(i)?m1(i):m2(i)
    // [10] if((bool~) main::$0) goto main::@2 -- vboaa_then_la1 
    cmp #0
    bne __b2
    // main::@3
    // m2(i)
    // [11] (byte) m2::i#0 ← (byte) main::i#2
    // [12] call m2 
    jsr m2
    // [13] (byte) m2::return#0 ← (byte) m2::return#1
    // main::@7
    // cond(i)?m1(i):m2(i)
    // [14] (byte~) main::$2 ← (byte) m2::return#0
    // [15] phi from main::@6 main::@7 to main::@4 [phi:main::@6/main::@7->main::@4]
    // [15] phi (byte~) main::$5 = (byte~) main::$4 [phi:main::@6/main::@7->main::@4#0] -- register_copy 
    // main::@4
  __b4:
    // SCREEN[i] = cond(i)?m1(i):m2(i)
    // [16] *((const byte*) main::SCREEN + (byte) main::i#2) ← (byte~) main::$5 -- pbuc1_derefidx_vbuyy=vbuaa 
    sta SCREEN,y
    // for( byte i: 0..9)
    // [17] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // [18] if((byte) main::i#1!=(byte) $a) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$a
    bne __b1
    // main::@return
    // }
    // [19] return 
    rts
    // main::@2
  __b2:
    // m1(i)
    // [20] (byte) m1::i#0 ← (byte) main::i#2
    // [21] call m1 
    jsr m1
    // [22] (byte) m1::return#0 ← (byte) m1::return#1
    // main::@6
    // cond(i)?m1(i):m2(i)
    // [23] (byte~) main::$4 ← (byte) m1::return#0
    jmp __b4
}
  // m1
// m1(byte register(Y) i)
m1: {
    // 5+i
    // [24] (byte) m1::return#1 ← (byte) 5 + (byte) m1::i#0 -- vbuaa=vbuc1_plus_vbuyy 
    tya
    clc
    adc #5
    // m1::@return
    // }
    // [25] return 
    rts
}
  // m2
// m2(byte register(Y) i)
m2: {
    // 10+i
    // [26] (byte) m2::return#1 ← (byte) $a + (byte) m2::i#0 -- vbuaa=vbuc1_plus_vbuyy 
    tya
    clc
    adc #$a
    // m2::@return
    // }
    // [27] return 
    rts
}
  // cond
// cond(byte register(Y) b)
cond: {
    // b<5
    // [28] (bool) cond::return#1 ← (byte) cond::b#0 < (byte) 5 -- vboaa=vbuyy_lt_vbuc1 
    cpy #5
    lda #0
    rol
    eor #1
    // cond::@return
    // }
    // [29] return 
    rts
}
  // File Data

