Culled Empty Block (label) main::@2
Culled Empty Block (label) @1
Culled Empty Block (label) sub1::@1

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

(void()) main()
main: scope:[main]  from @2
  (byte) main::i ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@3
  (byte) sub1::i#0 ← (byte) main::i
  call sub1 
  (byte) sub1::return#0 ← (byte) sub1::return#2
  to:main::@3
main::@3: scope:[main]  from main::@1
  (byte) sub1::return#3 ← phi( main::@1/(byte) sub1::return#0 )
  (byte~) main::$0 ← (byte) sub1::return#3
  *((const byte*) main::SCREEN + (byte) main::i) ← (byte~) main::$0
  (byte) main::i ← (byte) main::i + rangenext(0,2)
  (bool~) main::$1 ← (byte) main::i != rangelast(0,2)
  if((bool~) main::$1) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return

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

SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(void()) main()
(byte~) main::$0
(bool~) main::$1
(label) main::@1
(label) main::@3
(label) main::@return
(const byte*) main::SCREEN = (byte*)(number) $400
(byte) main::i loadstore
(byte()) sub1((byte) sub1::i)
(byte~) sub1::$0
(label) sub1::@return
(byte) sub1::i
(byte) sub1::i#0
(byte) sub1::i#1
(byte) sub1::return
(byte) sub1::return#0
(byte) sub1::return#1
(byte) sub1::return#2
(byte) sub1::return#3
(byte) sub1::return#4

Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Alias (byte) sub1::return#0 = (byte) sub1::return#3 
Alias (byte) sub1::return#1 = (byte~) sub1::$0 (byte) sub1::return#4 (byte) sub1::return#2 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) sub1::i#1 (byte) sub1::i#0
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$1 [8] if((byte) main::i!=rangelast(0,2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Resolved ranged next value [6] main::i ← ++ main::i to ++
Resolved ranged comparison value [8] if(main::i!=rangelast(0,2)) goto main::@1 to (number) 3
Adding number conversion cast (unumber) 3 in if((byte) main::i!=(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
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to sub1:7 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @3
Renumbering block @2 to @1
Renumbering block main::@3 to main::@2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end

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] (byte) main::i ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [5] (byte) sub1::i#0 ← (byte) main::i
  [6] call sub1 
  [7] (byte) sub1::return#0 ← (byte) sub1::return#1
  to:main::@2
main::@2: scope:[main]  from main::@1
  [8] (byte~) main::$0 ← (byte) sub1::return#0
  [9] *((const byte*) main::SCREEN + (byte) main::i) ← (byte~) main::$0
  [10] (byte) main::i ← ++ (byte) main::i
  [11] if((byte) main::i!=(byte) 3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@2
  [12] return 
  to:@return

(byte()) sub1((byte) sub1::i)
sub1: scope:[sub1]  from main::@1
  [13] (byte) sub1::return#1 ← (byte) sub1::i#0 + (byte) sub1::i#0
  to:sub1::@return
sub1::@return: scope:[sub1]  from sub1
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$0 22.0
(byte) main::i loadstore 7.125
(byte()) sub1((byte) sub1::i)
(byte) sub1::i
(byte) sub1::i#0 15.0
(byte) sub1::return
(byte) sub1::return#0 22.0
(byte) sub1::return#1 4.333333333333333

Initial phi equivalence classes
Added variable main::i to live range equivalence class [ main::i ]
Added variable sub1::i#0 to live range equivalence class [ sub1::i#0 ]
Added variable sub1::return#0 to live range equivalence class [ sub1::return#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable sub1::return#1 to live range equivalence class [ sub1::return#1 ]
Complete equivalence classes
[ main::i ]
[ sub1::i#0 ]
[ sub1::return#0 ]
[ main::$0 ]
[ sub1::return#1 ]
Allocated zp[1]:5 [ main::i ]
Allocated zp[1]:6 [ sub1::i#0 ]
Allocated zp[1]:7 [ sub1::return#0 ]
Allocated zp[1]:8 [ main::$0 ]
Allocated zp[1]:9 [ sub1::return#1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Demonstrates a procedure reserving addresses on zeropage
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label SCREEN = $400
    .label i = 5
    .label __0 = 8
    // [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // main::@1
  __b1:
    // [5] (byte) sub1::i#0 ← (byte) main::i -- vbuz1=vbuz2 
    lda.z i
    sta.z sub1.i
    // [6] call sub1 
    jsr sub1
    // [7] (byte) sub1::return#0 ← (byte) sub1::return#1 -- vbuz1=vbuz2 
    lda.z sub1.return_1
    sta.z sub1.return
    jmp __b2
    // main::@2
  __b2:
    // [8] (byte~) main::$0 ← (byte) sub1::return#0 -- vbuz1=vbuz2 
    lda.z sub1.return
    sta.z __0
    // [9] *((const byte*) main::SCREEN + (byte) main::i) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuz2 
    lda.z __0
    ldy.z i
    sta SCREEN,y
    // [10] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1 
    inc.z i
    // [11] if((byte) main::i!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp.z i
    bne __b1
    jmp __breturn
    // main::@return
  __breturn:
    // [12] return 
    rts
}
  // sub1
// sub1(byte zp(6) i)
sub1: {
    .label i = 6
    .label return = 7
    .label return_1 = 9
    // [13] (byte) sub1::return#1 ← (byte) sub1::i#0 + (byte) sub1::i#0 -- vbuz1=vbuz2_plus_vbuz2 
    lda.z i
    asl
    sta.z return_1
    jmp __breturn
    // sub1::@return
  __breturn:
    // [14] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] (byte) main::i ← (byte) 0 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a 
Statement [9] *((const byte*) main::SCREEN + (byte) main::i) ← (byte~) main::$0 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte y 
Statement [11] if((byte) main::i!=(byte) 3) goto main::@1 [ main::i ] ( main:2 [ main::i ] ) always clobbers reg byte a 
Statement [13] (byte) sub1::return#1 ← (byte) sub1::i#0 + (byte) sub1::i#0 [ sub1::return#1 ] ( main:2::sub1:6 [ main::i sub1::return#1 ] ) always clobbers reg byte a 
Potential registers zp[1]:5 [ main::i ] : zp[1]:5 , 
Potential registers zp[1]:6 [ sub1::i#0 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:7 [ sub1::return#0 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:8 [ main::$0 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:9 [ sub1::return#1 ] : zp[1]:9 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [sub1] 22: zp[1]:7 [ sub1::return#0 ] 15: zp[1]:6 [ sub1::i#0 ] 4.33: zp[1]:9 [ sub1::return#1 ] 
Uplift Scope [main] 22: zp[1]:8 [ main::$0 ] 7.12: zp[1]:5 [ main::i ] 
Uplift Scope [] 

Uplifting [sub1] best 452 combination reg byte a [ sub1::return#0 ] reg byte a [ sub1::i#0 ] reg byte a [ sub1::return#1 ] 
Uplifting [main] best 392 combination reg byte a [ main::$0 ] zp[1]:5 [ main::i ] 
Uplifting [] best 392 combination 
Attempting to uplift remaining variables inzp[1]:5 [ main::i ]
Uplifting [main] best 392 combination zp[1]:5 [ main::i ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Demonstrates a procedure reserving addresses on zeropage
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label SCREEN = $400
    .label i = 5
    // [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // main::@1
  __b1:
    // [5] (byte) sub1::i#0 ← (byte) main::i -- vbuaa=vbuz1 
    lda.z i
    // [6] call sub1 
    jsr sub1
    // [7] (byte) sub1::return#0 ← (byte) sub1::return#1
    jmp __b2
    // main::@2
  __b2:
    // [8] (byte~) main::$0 ← (byte) sub1::return#0
    // [9] *((const byte*) main::SCREEN + (byte) main::i) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z i
    sta SCREEN,y
    // [10] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1 
    inc.z i
    // [11] if((byte) main::i!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp.z i
    bne __b1
    jmp __breturn
    // main::@return
  __breturn:
    // [12] return 
    rts
}
  // sub1
// sub1(byte register(A) i)
sub1: {
    // [13] (byte) sub1::return#1 ← (byte) sub1::i#0 + (byte) sub1::i#0 -- vbuaa=vbuaa_plus_vbuaa 
    asl
    jmp __breturn
    // sub1::@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 __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b2:
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 __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(byte~) main::$0 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@return
(const byte*) main::SCREEN = (byte*) 1024
(byte) main::i loadstore zp[1]:5 7.125
(byte()) sub1((byte) sub1::i)
(label) sub1::@return
(byte) sub1::i
(byte) sub1::i#0 reg byte a 15.0
(byte) sub1::return
(byte) sub1::return#0 reg byte a 22.0
(byte) sub1::return#1 reg byte a 4.333333333333333

zp[1]:5 [ main::i ]
reg byte a [ sub1::i#0 ]
reg byte a [ sub1::return#0 ]
reg byte a [ main::$0 ]
reg byte a [ sub1::return#1 ]


FINAL ASSEMBLER
Score: 314

  // File Comments
// Demonstrates a procedure reserving addresses on zeropage
  // 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 
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label SCREEN = $400
    .label i = 5
    // for( volatile byte i : 0..2)
    // [4] (byte) main::i ← (byte) 0 -- vbuz1=vbuc1 
    lda #0
    sta.z i
    // main::@1
  __b1:
    // sub1(i)
    // [5] (byte) sub1::i#0 ← (byte) main::i -- vbuaa=vbuz1 
    lda.z i
    // [6] call sub1 
    jsr sub1
    // [7] (byte) sub1::return#0 ← (byte) sub1::return#1
    // main::@2
    // [8] (byte~) main::$0 ← (byte) sub1::return#0
    // SCREEN[i] = sub1(i)
    // [9] *((const byte*) main::SCREEN + (byte) main::i) ← (byte~) main::$0 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z i
    sta SCREEN,y
    // for( volatile byte i : 0..2)
    // [10] (byte) main::i ← ++ (byte) main::i -- vbuz1=_inc_vbuz1 
    inc.z i
    // [11] if((byte) main::i!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp.z i
    bne __b1
    // main::@return
    // }
    // [12] return 
    rts
}
  // sub1
// sub1(byte register(A) i)
sub1: {
    // i+i
    // [13] (byte) sub1::return#1 ← (byte) sub1::i#0 + (byte) sub1::i#0 -- vbuaa=vbuaa_plus_vbuaa 
    asl
    // sub1::@return
    // }
    // [14] return 
    rts
}
  // File Data

