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

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte) i#0 ← (byte) 0
  to:@2

(void()) main()
main: scope:[main]  from @2
  (byte) i#8 ← phi( @2/(byte) i#9 )
  (byte) main::a#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  (byte) i#4 ← phi( main/(byte) i#8 main::@1/(byte) i#4 )
  (byte) main::a#2 ← phi( main/(byte) main::a#0 main::@1/(byte) main::a#1 )
  (number~) main::$0 ← (byte) main::a#2 + (number) 1
  (byte) main::v#0 ← (number~) main::$0
  (byte~) main::$1 ← call plus (byte) '0' (byte) main::v#0 
  (byte) main::w#0 ← (byte~) main::$1
  (byte~) main::$2 ← (byte) main::w#0 + (byte) main::a#2
  *((const byte*) SCREEN + (byte) i#4) ← (byte~) main::$2
  (byte) main::a#1 ← (byte) main::a#2 + rangenext(0,1)
  (bool~) main::$3 ← (byte) main::a#1 != rangelast(0,1)
  if((bool~) main::$3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  (byte) i#5 ← phi( main::@1/(byte) i#4 )
  (byte) i#1 ← (byte) i#5
  return 
  to:@return

__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
plus: scope:[plus]  from
  (byte) i#6 ← phi( )
  (byte) plus::a#0 ← param((byte) plus::a)
  (byte) plus::b#0 ← param((byte) plus::b)
  (byte) i#2 ← ++ (byte) i#6
  (byte~) plus::$0 ← (byte) plus::a#0 + (byte) plus::b#0
  (byte) plus::return#0 ← (byte~) plus::$0
  to:plus::@return
plus::@return: scope:[plus]  from plus
  (byte) plus::return#1 ← phi( plus/(byte) plus::return#0 )
  return (byte) plus::return#1
  to:@return
@2: scope:[]  from @begin
  (byte) i#9 ← phi( @begin/(byte) i#0 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) i#7 ← phi( @2/(byte) i#1 )
  (byte) i#3 ← (byte) i#7
  to:@end
@end: scope:[]  from @3

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

Adding number conversion cast (unumber) 1 in (number~) main::$0 ← (byte) main::a#2 + (number) 1
Adding number conversion cast (unumber) main::$0 in (number~) main::$0 ← (byte) main::a#2 + (unumber)(number) 1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$0 ← (byte) main::a#2 + (byte) 1
Alias (byte) main::v#0 = (byte~) main::$0 
Alias (byte) main::w#0 = (byte~) main::$1 
Alias (byte) i#1 = (byte) i#5 (byte) i#4 
Alias (byte) plus::return#0 = (byte~) plus::$0 (byte) plus::return#1 
Alias (byte) i#0 = (byte) i#9 
Alias (byte) i#3 = (byte) i#7 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) i#8 (byte) i#0
Identical Phi Values (byte) i#1 (byte) i#8
Identical Phi Values (byte) i#3 (byte) i#1
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$3 [10] if((byte) main::a#1!=rangelast(0,1)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) i#0 = 0
Constant (const byte) main::a#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [8] main::a#1 ← ++ main::a#2 to ++
Resolved ranged comparison value [10] if(main::a#1!=rangelast(0,1)) goto main::@1 to (number) 2
Simplifying expression containing zero SCREEN in [7] *((const byte*) SCREEN + (const byte) i#0) ← (byte~) main::$2
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused variable (byte) i#2 and assignment [11] (byte) i#2 ← ++ (byte) i#6
Eliminating unused constant (const byte) i#0
Successful SSA optimization PassNEliminateUnusedVars
Eliminating unused variable - keeping the phi block (byte) i#6
Successful SSA optimization PassNEliminateUnusedVars
Adding number conversion cast (unumber) 2 in if((byte) main::a#1!=(number) 2) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) main::a#0
Constant inlined main::a#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@3(between main::@1 and main::@1)
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
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to plus:8 

Created 1 initial phi equivalence classes
Coalesced [14] main::a#3 ← main::a#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @3
Culled Empty Block (label) main::@3
Renumbering block @2 to @1
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
Calling convention STACK_CALL adding prepare/execute/finalize for [7] (byte) main::w#0 ← call plus (byte) '0' (byte) main::v#0 
Calling convention STACK_CALL replacing param((byte) plus::a) with stackidx(byte,(const byte) plus::OFFSET_STACK_A)
Calling convention STACK_CALL replacing param((byte) plus::b) with stackidx(byte,(const byte) plus::OFFSET_STACK_B)

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::@1
  [5] (byte) main::a#2 ← phi( main/(byte) 0 main::@1/(byte) main::a#1 )
  [6] (byte) main::v#0 ← (byte) main::a#2 + (byte) 1
  [7] callprepare plus (byte) '0' (byte) main::v#0 
  [8] callexecute plus 
  [9] (byte) main::w#0 ← callfinalize plus 
  [10] (byte~) main::$2 ← (byte) main::w#0 + (byte) main::a#2
  [11] *((const byte*) SCREEN) ← (byte~) main::$2
  [12] (byte) main::a#1 ← ++ (byte) main::a#2
  [13] if((byte) main::a#1!=(byte) 2) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [14] return 
  to:@return

__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
plus: scope:[plus]  from
  [15] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A)
  [16] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B)
  [17] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0
  to:plus::@return
plus::@return: scope:[plus]  from plus
  [18] return (byte) plus::return#0
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) i
(void()) main()
(byte~) main::$2 22.0
(byte) main::a
(byte) main::a#1 16.5
(byte) main::a#2 6.285714285714286
(byte) main::v
(byte) main::v#0 11.0
(byte) main::w
(byte) main::w#0 11.0
__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
(byte) plus::a
(byte) plus::a#0 2.0
(byte) plus::b
(byte) plus::b#0 4.0
(byte) plus::return
(byte) plus::return#0 2.0

Initial phi equivalence classes
[ main::a#2 main::a#1 ]
Added variable main::v#0 to live range equivalence class [ main::v#0 ]
Added variable main::w#0 to live range equivalence class [ main::w#0 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Added variable plus::a#0 to live range equivalence class [ plus::a#0 ]
Added variable plus::b#0 to live range equivalence class [ plus::b#0 ]
Added variable plus::return#0 to live range equivalence class [ plus::return#0 ]
Complete equivalence classes
[ main::a#2 main::a#1 ]
[ main::v#0 ]
[ main::w#0 ]
[ main::$2 ]
[ plus::a#0 ]
[ plus::b#0 ]
[ plus::return#0 ]
Allocated zp[1]:2 [ main::a#2 main::a#1 ]
Allocated zp[1]:3 [ main::v#0 ]
Allocated zp[1]:4 [ main::w#0 ]
Allocated zp[1]:5 [ main::$2 ]
Allocated zp[1]:6 [ plus::a#0 ]
Allocated zp[1]:7 [ plus::b#0 ]
Allocated zp[1]:8 [ plus::return#0 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test a procedure with calling convention stack
// A slightly more complex call
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const STACK_BASE = $103
  // @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 __2 = 5
    .label v = 3
    .label w = 4
    .label a = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::a#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z a
    jmp __b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [5] phi (byte) main::a#2 = (byte) main::a#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) main::v#0 ← (byte) main::a#2 + (byte) 1 -- vbuz1=vbuz2_plus_1 
    ldy.z a
    iny
    sty.z v
    // [7] callprepare plus (byte) '0' (byte) main::v#0 
    // [7] callprepare plus (byte) '0' (byte) main::v#0  -- _stackpushbyte_=vbuc1 
    lda #'0'
    pha
    // [7] callprepare plus (byte) '0' (byte) main::v#0  -- _stackpushbyte_=vbuz1 
    lda.z v
    pha
    // [7] callprepare plus (byte) '0' (byte) main::v#0 
    // [8] callexecute plus  -- jsr 
    jsr plus
    // [9] (byte) main::w#0 ← callfinalize plus 
    // [9] (byte) main::w#0 ← callfinalize plus  -- _stackpullbyte_1 
    pla
    // [9] (byte) main::w#0 ← callfinalize plus  -- vbuz1=_stackpullbyte_ 
    pla
    sta.z w
    // [10] (byte~) main::$2 ← (byte) main::w#0 + (byte) main::a#2 -- vbuz1=vbuz2_plus_vbuz3 
    lda.z w
    clc
    adc.z a
    sta.z __2
    // [11] *((const byte*) SCREEN) ← (byte~) main::$2 -- _deref_pbuc1=vbuz1 
    lda.z __2
    sta SCREEN
    // [12] (byte) main::a#1 ← ++ (byte) main::a#2 -- vbuz1=_inc_vbuz1 
    inc.z a
    // [13] if((byte) main::a#1!=(byte) 2) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #2
    cmp.z a
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // plus
// plus(byte zp(6) a, byte zp(7) b)
plus: {
    .const OFFSET_STACK_A = 0
    .const OFFSET_STACK_B = 1
    .const OFFSET_STACK_RETURN = 1
    .label a = 6
    .label b = 7
    .label return = 8
    // [15] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1 
    tsx
    lda STACK_BASE+OFFSET_STACK_A,x
    sta.z a
    // [16] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B) -- vbuz1=_stackidxbyte_vbuc1 
    tsx
    lda STACK_BASE+OFFSET_STACK_B,x
    sta.z b
    // [17] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0 -- vbuz1=vbuz2_plus_vbuz3 
    lda.z a
    clc
    adc.z b
    sta.z return
    jmp __breturn
    // plus::@return
  __breturn:
    // [18] return (byte) plus::return#0
    // [18] return (byte) plus::return#0 -- _stackidxbyte_vbuc1=vbuz1 
    lda.z return
    tsx
    sta STACK_BASE+OFFSET_STACK_RETURN,x
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] callprepare plus (byte) '0' (byte) main::v#0  [ main::a#2 ] ( main:2 [ main::a#2 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::a#2 main::a#1 ]
Statement [9] (byte) main::w#0 ← callfinalize plus  [ main::a#2 main::w#0 ] ( main:2 [ main::a#2 main::w#0 ] ) always clobbers reg byte a 
Statement [10] (byte~) main::$2 ← (byte) main::w#0 + (byte) main::a#2 [ main::a#2 main::$2 ] ( main:2 [ main::a#2 main::$2 ] ) always clobbers reg byte a 
Statement [15] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) [ plus::a#0 ] ( main:2::plus:8 [ main::a#2 plus::a#0 ] ) always clobbers reg byte a reg byte x 
Removing always clobbered register reg byte x as potential for zp[1]:2 [ main::a#2 main::a#1 ]
Statement [16] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B) [ plus::a#0 plus::b#0 ] ( main:2::plus:8 [ main::a#2 plus::a#0 plus::b#0 ] ) always clobbers reg byte a reg byte x 
Removing always clobbered register reg byte a as potential for zp[1]:6 [ plus::a#0 ]
Removing always clobbered register reg byte x as potential for zp[1]:6 [ plus::a#0 ]
Statement [17] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0 [ plus::return#0 ] ( main:2::plus:8 [ main::a#2 plus::return#0 ] ) always clobbers reg byte a 
Statement [18] return (byte) plus::return#0 [ ] ( main:2::plus:8 [ main::a#2 ] ) always clobbers reg byte x 
Statement [7] callprepare plus (byte) '0' (byte) main::v#0  [ main::a#2 ] ( main:2 [ main::a#2 ] ) always clobbers reg byte a 
Statement [9] (byte) main::w#0 ← callfinalize plus  [ main::a#2 main::w#0 ] ( main:2 [ main::a#2 main::w#0 ] ) always clobbers reg byte a 
Statement [10] (byte~) main::$2 ← (byte) main::w#0 + (byte) main::a#2 [ main::a#2 main::$2 ] ( main:2 [ main::a#2 main::$2 ] ) always clobbers reg byte a 
Statement [15] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) [ plus::a#0 ] ( main:2::plus:8 [ main::a#2 plus::a#0 ] ) always clobbers reg byte a reg byte x 
Statement [16] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B) [ plus::a#0 plus::b#0 ] ( main:2::plus:8 [ main::a#2 plus::a#0 plus::b#0 ] ) always clobbers reg byte a reg byte x 
Statement [17] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0 [ plus::return#0 ] ( main:2::plus:8 [ main::a#2 plus::return#0 ] ) always clobbers reg byte a 
Statement [18] return (byte) plus::return#0 [ ] ( main:2::plus:8 [ main::a#2 ] ) always clobbers reg byte x 
Potential registers zp[1]:2 [ main::a#2 main::a#1 ] : zp[1]:2 , reg byte y , 
Potential registers zp[1]:3 [ main::v#0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ main::w#0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ main::$2 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:6 [ plus::a#0 ] : zp[1]:6 , reg byte y , 
Potential registers zp[1]:7 [ plus::b#0 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:8 [ plus::return#0 ] : zp[1]:8 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 22.79: zp[1]:2 [ main::a#2 main::a#1 ] 22: zp[1]:5 [ main::$2 ] 11: zp[1]:3 [ main::v#0 ] 11: zp[1]:4 [ main::w#0 ] 
Uplift Scope [plus] 4: zp[1]:7 [ plus::b#0 ] 2: zp[1]:6 [ plus::a#0 ] 2: zp[1]:8 [ plus::return#0 ] 
Uplift Scope [] 

Uplifting [main] best 661 combination reg byte y [ main::a#2 main::a#1 ] reg byte a [ main::$2 ] reg byte x [ main::v#0 ] reg byte a [ main::w#0 ] 
Limited combination testing to 100 combinations of 128 possible.
Uplifting [plus] best 649 combination reg byte a [ plus::b#0 ] zp[1]:6 [ plus::a#0 ] reg byte a [ plus::return#0 ] 
Uplifting [] best 649 combination 
Attempting to uplift remaining variables inzp[1]:6 [ plus::a#0 ]
Uplifting [plus] best 649 combination zp[1]:6 [ plus::a#0 ] 
Allocated (was zp[1]:6) zp[1]:2 [ plus::a#0 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test a procedure with calling convention stack
// A slightly more complex call
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const STACK_BASE = $103
  // @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::a#2 = (byte) 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    jmp __b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [5] phi (byte) main::a#2 = (byte) main::a#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] (byte) main::v#0 ← (byte) main::a#2 + (byte) 1 -- vbuxx=vbuyy_plus_1 
    tya
    tax
    inx
    // [7] callprepare plus (byte) '0' (byte) main::v#0 
    // [7] callprepare plus (byte) '0' (byte) main::v#0  -- _stackpushbyte_=vbuc1 
    lda #'0'
    pha
    // [7] callprepare plus (byte) '0' (byte) main::v#0  -- _stackpushbyte_=vbuxx 
    txa
    pha
    // [7] callprepare plus (byte) '0' (byte) main::v#0 
    // [8] callexecute plus  -- jsr 
    jsr plus
    // [9] (byte) main::w#0 ← callfinalize plus 
    // [9] (byte) main::w#0 ← callfinalize plus  -- _stackpullbyte_1 
    pla
    // [9] (byte) main::w#0 ← callfinalize plus  -- vbuaa=_stackpullbyte_ 
    pla
    // [10] (byte~) main::$2 ← (byte) main::w#0 + (byte) main::a#2 -- vbuaa=vbuaa_plus_vbuyy 
    sty.z $ff
    clc
    adc.z $ff
    // [11] *((const byte*) SCREEN) ← (byte~) main::$2 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // [12] (byte) main::a#1 ← ++ (byte) main::a#2 -- vbuyy=_inc_vbuyy 
    iny
    // [13] if((byte) main::a#1!=(byte) 2) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #2
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [14] return 
    rts
}
  // plus
// plus(byte zp(2) a, byte register(A) b)
plus: {
    .const OFFSET_STACK_A = 0
    .const OFFSET_STACK_B = 1
    .const OFFSET_STACK_RETURN = 1
    .label a = 2
    // [15] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1 
    tsx
    lda STACK_BASE+OFFSET_STACK_A,x
    sta.z a
    // [16] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B) -- vbuaa=_stackidxbyte_vbuc1 
    tsx
    lda STACK_BASE+OFFSET_STACK_B,x
    // [17] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0 -- vbuaa=vbuz1_plus_vbuaa 
    clc
    adc.z a
    jmp __breturn
    // plus::@return
  __breturn:
    // [18] return (byte) plus::return#0
    // [18] return (byte) plus::return#0 -- _stackidxbyte_vbuc1=vbuaa 
    tsx
    sta STACK_BASE+OFFSET_STACK_RETURN,x
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b1_from___b1 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
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
(const byte*) SCREEN = (byte*) 1024
(const word) STACK_BASE = (word) $103
(byte) i
(void()) main()
(byte~) main::$2 reg byte a 22.0
(label) main::@1
(label) main::@return
(byte) main::a
(byte) main::a#1 reg byte y 16.5
(byte) main::a#2 reg byte y 6.285714285714286
(byte) main::v
(byte) main::v#0 reg byte x 11.0
(byte) main::w
(byte) main::w#0 reg byte a 11.0
__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
(label) plus::@return
(const byte) plus::OFFSET_STACK_A = (byte) 0
(const byte) plus::OFFSET_STACK_B = (byte) 1
(const byte) plus::OFFSET_STACK_RETURN = (byte) 1
(byte) plus::a
(byte) plus::a#0 a zp[1]:2 2.0
(byte) plus::b
(byte) plus::b#0 reg byte a 4.0
(byte) plus::return
(byte) plus::return#0 reg byte a 2.0

reg byte y [ main::a#2 main::a#1 ]
reg byte x [ main::v#0 ]
reg byte a [ main::w#0 ]
reg byte a [ main::$2 ]
zp[1]:2 [ plus::a#0 ]
reg byte a [ plus::b#0 ]
reg byte a [ plus::return#0 ]


FINAL ASSEMBLER
Score: 544

  // File Comments
// Test a procedure with calling convention stack
// A slightly more complex call
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .const STACK_BASE = $103
  // @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::a#2 = (byte) 0 [phi:main->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [5] phi (byte) main::a#2 = (byte) main::a#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // v = a+1
    // [6] (byte) main::v#0 ← (byte) main::a#2 + (byte) 1 -- vbuxx=vbuyy_plus_1 
    tya
    tax
    inx
    // w = plus('0', v)
    // [7] callprepare plus (byte) '0' (byte) main::v#0 
    // [7] callprepare plus (byte) '0' (byte) main::v#0  -- _stackpushbyte_=vbuc1 
    lda #'0'
    pha
    // [7] callprepare plus (byte) '0' (byte) main::v#0  -- _stackpushbyte_=vbuxx 
    txa
    pha
    // [7] callprepare plus (byte) '0' (byte) main::v#0 
    // [8] callexecute plus  -- jsr 
    jsr plus
    // [9] (byte) main::w#0 ← callfinalize plus 
    // [9] (byte) main::w#0 ← callfinalize plus  -- _stackpullbyte_1 
    pla
    // [9] (byte) main::w#0 ← callfinalize plus  -- vbuaa=_stackpullbyte_ 
    pla
    // w+a
    // [10] (byte~) main::$2 ← (byte) main::w#0 + (byte) main::a#2 -- vbuaa=vbuaa_plus_vbuyy 
    sty.z $ff
    clc
    adc.z $ff
    // SCREEN[i] = w+a
    // [11] *((const byte*) SCREEN) ← (byte~) main::$2 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // for(char a:0..1)
    // [12] (byte) main::a#1 ← ++ (byte) main::a#2 -- vbuyy=_inc_vbuyy 
    iny
    // [13] if((byte) main::a#1!=(byte) 2) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #2
    bne __b1
    // main::@return
    // }
    // [14] return 
    rts
}
  // plus
// plus(byte zp(2) a, byte register(A) b)
plus: {
    .const OFFSET_STACK_A = 0
    .const OFFSET_STACK_B = 1
    .const OFFSET_STACK_RETURN = 1
    .label a = 2
    // [15] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) -- vbuz1=_stackidxbyte_vbuc1 
    tsx
    lda STACK_BASE+OFFSET_STACK_A,x
    sta.z a
    // [16] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B) -- vbuaa=_stackidxbyte_vbuc1 
    tsx
    lda STACK_BASE+OFFSET_STACK_B,x
    // return a+b;
    // [17] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0 -- vbuaa=vbuz1_plus_vbuaa 
    clc
    adc.z a
    // plus::@return
    // }
    // [18] return (byte) plus::return#0
    // [18] return (byte) plus::return#0 -- _stackidxbyte_vbuc1=vbuaa 
    tsx
    sta STACK_BASE+OFFSET_STACK_RETURN,x
    rts
}
  // File Data

