Warning! Adding boolean cast to non-boolean condition (signed byte) main::i
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
Culled Empty Block (label) main::@7

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) SCREEN#0 ← ((byte*)) (number) $400
  to:@1
main: scope:[main]  from @1
  (byte) main::idx#0 ← (number) 0
  (signed byte) main::i#0 ← (signed byte) -2
  to:main::@1
main::@1: scope:[main]  from main main::@4
  (byte) main::idx#5 ← phi( main/(byte) main::idx#0 main::@4/(byte) main::idx#1 )
  (signed byte) main::i#2 ← phi( main/(signed byte) main::i#0 main::@4/(signed byte) main::i#1 )
  (bool~) main::$4 ← (number) 0 != (signed byte) main::i#2
  if((bool~) main::$4) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  (signed byte) main::i#4 ← phi( main::@1/(signed byte) main::i#2 )
  (byte) main::idx#3 ← phi( main::@1/(byte) main::idx#5 )
  (byte~) main::$1 ← (byte) '+'
  to:main::@4
main::@3: scope:[main]  from main::@1
  (signed byte) main::i#5 ← phi( main::@1/(signed byte) main::i#2 )
  (byte) main::idx#4 ← phi( main::@1/(byte) main::idx#5 )
  (byte~) main::$0 ← (byte) '0'
  to:main::@4
main::@4: scope:[main]  from main::@2 main::@3
  (signed byte) main::i#3 ← phi( main::@2/(signed byte) main::i#4 main::@3/(signed byte) main::i#5 )
  (byte) main::idx#2 ← phi( main::@2/(byte) main::idx#3 main::@3/(byte) main::idx#4 )
  (byte~) main::$2 ← phi( main::@2/(byte~) main::$1 main::@3/(byte~) main::$0 )
  (byte) main::j#0 ← (byte~) main::$2
  *((byte*) SCREEN#0 + (byte) main::idx#2) ← (byte) main::j#0
  (byte) main::idx#1 ← ++ (byte) main::idx#2
  (signed byte) main::i#1 ← (signed byte) main::i#3 + rangenext(-2,2)
  (bool~) main::$3 ← (signed byte) main::i#1 != rangelast(-2,2)
  if((bool~) main::$3) 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
(byte*) SCREEN
(byte*) SCREEN#0
(void()) main()
(byte~) main::$0
(byte~) main::$1
(byte~) main::$2
(bool~) main::$3
(bool~) main::$4
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@return
(signed byte) main::i
(signed byte) main::i#0
(signed byte) main::i#1
(signed byte) main::i#2
(signed byte) main::i#3
(signed byte) main::i#4
(signed byte) main::i#5
(byte) main::idx
(byte) main::idx#0
(byte) main::idx#1
(byte) main::idx#2
(byte) main::idx#3
(byte) main::idx#4
(byte) main::idx#5
(byte) main::j
(byte) main::j#0

Adding number conversion cast (unumber) 0 in (byte) main::idx#0 ← (number) 0
Adding number conversion cast (snumber) 0 in (bool~) main::$4 ← (number) 0 != (signed byte) main::i#2
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Inlining cast (byte) main::idx#0 ← (unumber)(number) 0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized signed number type (signed byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) main::idx#3 = (byte) main::idx#5 (byte) main::idx#4 
Alias (signed byte) main::i#2 = (signed byte) main::i#4 (signed byte) main::i#5 
Alias (byte) main::j#0 = (byte~) main::$2 
Successful SSA optimization Pass2AliasElimination
Alias (byte) main::idx#2 = (byte) main::idx#3 
Alias (signed byte) main::i#2 = (signed byte) main::i#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) main::$4 [5] if((signed byte) 0!=(signed byte) main::i#2) goto main::@2
Simple Condition (bool~) main::$3 [16] if((signed byte) main::i#1!=rangelast(-2,2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) SCREEN#0 = (byte*) 1024
Constant (const byte) main::idx#0 = 0
Constant (const signed byte) main::i#0 = -2
Constant (const byte) main::$1 = '+'
Constant (const byte) main::$0 = '0'
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [14] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [16] if(main::i#1!=rangelast(-2,2)) goto main::@1 to (number) 3
Adding number conversion cast (snumber) 3 in if((signed byte) main::i#1!=(number) 3) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized signed number type (signed byte) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) main::idx#0
Inlining constant with var siblings (const signed byte) main::i#0
Constant inlined main::i#0 = (signed byte) -2
Constant inlined main::idx#0 = (byte) 0
Constant inlined main::$1 = (byte) '+'
Constant inlined main::$0 = (byte) '0'
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@8(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::@3
Adding NOP phi() at start of main::@2
CALL GRAPH
Calls in [] to main:2 

Created 3 initial phi equivalence classes
Coalesced [15] main::i#6 ← main::i#1
Coalesced [16] main::idx#6 ← main::idx#1
Coalesced down to 3 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@3
Culled Empty Block (label) main::@8
Renumbering block main::@4 to main::@3
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::@2

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()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@3
  [5] (byte) main::idx#2 ← phi( main/(byte) 0 main::@3/(byte) main::idx#1 )
  [5] (signed byte) main::i#2 ← phi( main/(signed byte) -2 main::@3/(signed byte) main::i#1 )
  [6] if((signed byte) 0!=(signed byte) main::i#2) goto main::@2
  to:main::@3
main::@2: scope:[main]  from main::@1
  [7] phi()
  to:main::@3
main::@3: scope:[main]  from main::@1 main::@2
  [8] (byte) main::j#0 ← phi( main::@2/(byte) '+' main::@1/(byte) '0' )
  [9] *((const byte*) SCREEN#0 + (byte) main::idx#2) ← (byte) main::j#0
  [10] (byte) main::idx#1 ← ++ (byte) main::idx#2
  [11] (signed byte) main::i#1 ← ++ (signed byte) main::i#2
  [12] if((signed byte) main::i#1!=(signed byte) 3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  [13] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte*) SCREEN
(void()) main()
(signed byte) main::i
(signed byte) main::i#1 16.5
(signed byte) main::i#2 5.5
(byte) main::idx
(byte) main::idx#1 7.333333333333333
(byte) main::idx#2 6.6000000000000005
(byte) main::j
(byte) main::j#0 11.0

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ main::idx#2 main::idx#1 ]
[ main::j#0 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::idx#2 main::idx#1 ]
[ main::j#0 ]
Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_BYTE:3 [ main::idx#2 main::idx#1 ]
Allocated zp ZP_BYTE:4 [ main::j#0 ]

INITIAL ASM
  // File Comments
// Tests using integer conditions in ternary operator
// This should produce '++0++' at the top of the screen
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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 j = 4
    .label idx = 3
    .label i = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte) main::idx#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta idx
    // [5] phi (signed byte) main::i#2 = (signed byte) -2 [phi:main->main::@1#1] -- vbsz1=vbsc1 
    lda #-2
    sta i
    jmp b1
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  b1_from_b3:
    // [5] phi (byte) main::idx#2 = (byte) main::idx#1 [phi:main::@3->main::@1#0] -- register_copy 
    // [5] phi (signed byte) main::i#2 = (signed byte) main::i#1 [phi:main::@3->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] if((signed byte) 0!=(signed byte) main::i#2) goto main::@2 -- vbsc1_neq_vbsz1_then_la1 
    lda #0
    cmp i
    bne b2_from_b1
    // [8] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
  b3_from_b1:
    // [8] phi (byte) main::j#0 = (byte) '0' [phi:main::@1->main::@3#0] -- vbuz1=vbuc1 
    lda #'0'
    sta j
    jmp b3
    // [7] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
    jmp b2
    // main::@2
  b2:
    // [8] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
  b3_from_b2:
    // [8] phi (byte) main::j#0 = (byte) '+' [phi:main::@2->main::@3#0] -- vbuz1=vbuc1 
    lda #'+'
    sta j
    jmp b3
    // main::@3
  b3:
    // [9] *((const byte*) SCREEN#0 + (byte) main::idx#2) ← (byte) main::j#0 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda j
    ldy idx
    sta SCREEN,y
    // [10] (byte) main::idx#1 ← ++ (byte) main::idx#2 -- vbuz1=_inc_vbuz1 
    inc idx
    // [11] (signed byte) main::i#1 ← ++ (signed byte) main::i#2 -- vbsz1=_inc_vbsz1 
    inc i
    // [12] if((signed byte) main::i#1!=(signed byte) 3) goto main::@1 -- vbsz1_neq_vbsc1_then_la1 
    lda #3
    cmp i
    bne b1_from_b3
    jmp breturn
    // main::@return
  breturn:
    // [13] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ main::idx#2 main::idx#1 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:4 [ main::j#0 ] : zp ZP_BYTE:4 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 22: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 13.93: zp ZP_BYTE:3 [ main::idx#2 main::idx#1 ] 11: zp ZP_BYTE:4 [ main::j#0 ] 
Uplift Scope [] 

Uplifting [main] best 458 combination reg byte y [ main::i#2 main::i#1 ] reg byte x [ main::idx#2 main::idx#1 ] reg byte a [ main::j#0 ] 
Uplifting [] best 458 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests using integer conditions in ternary operator
// This should produce '++0++' at the top of the screen
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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: {
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (byte) main::idx#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi (signed byte) main::i#2 = (signed byte) -2 [phi:main->main::@1#1] -- vbsyy=vbsc1 
    ldy #-2
    jmp b1
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  b1_from_b3:
    // [5] phi (byte) main::idx#2 = (byte) main::idx#1 [phi:main::@3->main::@1#0] -- register_copy 
    // [5] phi (signed byte) main::i#2 = (signed byte) main::i#1 [phi:main::@3->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] if((signed byte) 0!=(signed byte) main::i#2) goto main::@2 -- vbsc1_neq_vbsyy_then_la1 
    cpy #0
    bne b2_from_b1
    // [8] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
  b3_from_b1:
    // [8] phi (byte) main::j#0 = (byte) '0' [phi:main::@1->main::@3#0] -- vbuaa=vbuc1 
    lda #'0'
    jmp b3
    // [7] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
    jmp b2
    // main::@2
  b2:
    // [8] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
  b3_from_b2:
    // [8] phi (byte) main::j#0 = (byte) '+' [phi:main::@2->main::@3#0] -- vbuaa=vbuc1 
    lda #'+'
    jmp b3
    // main::@3
  b3:
    // [9] *((const byte*) SCREEN#0 + (byte) main::idx#2) ← (byte) main::j#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
    // [10] (byte) main::idx#1 ← ++ (byte) main::idx#2 -- vbuxx=_inc_vbuxx 
    inx
    // [11] (signed byte) main::i#1 ← ++ (signed byte) main::i#2 -- vbsyy=_inc_vbsyy 
    iny
    // [12] if((signed byte) main::i#1!=(signed byte) 3) goto main::@1 -- vbsyy_neq_vbsc1_then_la1 
    cpy #3
    bne b1_from_b3
    jmp breturn
    // main::@return
  breturn:
    // [13] 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 b3
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b2_from_b1 with b2
Replacing label b1_from_b3 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b3:
Removing instruction b2_from_b1:
Removing instruction b3_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction b3_from_b1:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (byte*) 1024
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(signed byte) main::i
(signed byte) main::i#1 reg byte y 16.5
(signed byte) main::i#2 reg byte y 5.5
(byte) main::idx
(byte) main::idx#1 reg byte x 7.333333333333333
(byte) main::idx#2 reg byte x 6.6000000000000005
(byte) main::j
(byte) main::j#0 reg byte a 11.0

reg byte y [ main::i#2 main::i#1 ]
reg byte x [ main::idx#2 main::idx#1 ]
reg byte a [ main::j#0 ]


FINAL ASSEMBLER
Score: 296

  // File Comments
// Tests using integer conditions in ternary operator
// This should produce '++0++' at the top of the screen
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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: {
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::idx#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [5] phi (signed byte) main::i#2 = (signed byte) -2 [phi:main->main::@1#1] -- vbsyy=vbsc1 
    ldy #-2
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
    // [5] phi (byte) main::idx#2 = (byte) main::idx#1 [phi:main::@3->main::@1#0] -- register_copy 
    // [5] phi (signed byte) main::i#2 = (signed byte) main::i#1 [phi:main::@3->main::@1#1] -- register_copy 
    // main::@1
  b1:
    // i?'+':'0'
    // [6] if((signed byte) 0!=(signed byte) main::i#2) goto main::@2 -- vbsc1_neq_vbsyy_then_la1 
    cpy #0
    bne b2
    // [8] phi from main::@1 to main::@3 [phi:main::@1->main::@3]
    // [8] phi (byte) main::j#0 = (byte) '0' [phi:main::@1->main::@3#0] -- vbuaa=vbuc1 
    lda #'0'
    jmp b3
    // [7] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // main::@2
  b2:
    // [8] phi from main::@2 to main::@3 [phi:main::@2->main::@3]
    // [8] phi (byte) main::j#0 = (byte) '+' [phi:main::@2->main::@3#0] -- vbuaa=vbuc1 
    lda #'+'
    // main::@3
  b3:
    // SCREEN[idx++] = j
    // [9] *((const byte*) SCREEN#0 + (byte) main::idx#2) ← (byte) main::j#0 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN,x
    // SCREEN[idx++] = j;
    // [10] (byte) main::idx#1 ← ++ (byte) main::idx#2 -- vbuxx=_inc_vbuxx 
    inx
    // for( signed byte i: -2..2)
    // [11] (signed byte) main::i#1 ← ++ (signed byte) main::i#2 -- vbsyy=_inc_vbsyy 
    iny
    // [12] if((signed byte) main::i#1!=(signed byte) 3) goto main::@1 -- vbsyy_neq_vbsc1_then_la1 
    cpy #3
    bne b1
    // main::@return
    // }
    // [13] return 
    rts
}
  // File Data

