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

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

(void()) main()
main: scope:[main]  from @2
  (byte~) main::$0 ← call plus (byte) '0' (number) 7 
  *((const byte*) SCREEN + (number) 0) ← (byte~) main::$0
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return

__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
plus: scope:[plus]  from
  (byte) plus::a#0 ← param((byte) plus::a)
  (byte) plus::b#0 ← param((byte) plus::b)
  (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
  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
(const byte*) SCREEN = (byte*)(number) $400
(void()) main()
(byte~) main::$0
(label) main::@return
__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) 7 in (byte~) main::$0 ← call plus (byte) '0' (number) 7 
Adding number conversion cast (unumber) 0 in *((const byte*) SCREEN + (number) 0) ← (byte~) main::$0
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 7
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 7
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) plus::return#0 = (byte~) plus::$0 (byte) plus::return#1 
Successful SSA optimization Pass2AliasElimination
Simplifying expression containing zero SCREEN in [1] *((const byte*) SCREEN + (byte) 0) ← (byte~) main::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
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:6 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @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 [5] (byte~) main::$0 ← call plus (byte) '0' (byte) 7 
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()
  [5] callprepare plus (byte) '0' (byte) 7 
  [6] callexecute plus 
  [7] (byte~) main::$0 ← callfinalize plus 
  [8] *((const byte*) SCREEN) ← (byte~) main::$0
  to:main::@return
main::@return: scope:[main]  from main
  [9] return 
  to:@return

__stackcall (byte()) plus((byte) plus::a , (byte) plus::b)
plus: scope:[plus]  from
  [10] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A)
  [11] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B)
  [12] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0
  to:plus::@return
plus::@return: scope:[plus]  from plus
  [13] return (byte) plus::return#0
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$0 2.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
Added variable main::$0 to live range equivalence class [ main::$0 ]
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::$0 ]
[ plus::a#0 ]
[ plus::b#0 ]
[ plus::return#0 ]
Allocated zp[1]:2 [ main::$0 ]
Allocated zp[1]:3 [ plus::a#0 ]
Allocated zp[1]:4 [ plus::b#0 ]
Allocated zp[1]:5 [ plus::return#0 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test a procedure with calling convention stack
  // 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 __0 = 2
    // [5] callprepare plus (byte) '0' (byte) 7 
    // [5] callprepare plus (byte) '0' (byte) 7  -- _stackpushbyte_=vbuc1 
    lda #'0'
    pha
    // [5] callprepare plus (byte) '0' (byte) 7  -- _stackpushbyte_=vbuc1 
    lda #7
    pha
    // [5] callprepare plus (byte) '0' (byte) 7 
    // [6] callexecute plus  -- jsr 
    jsr plus
    // [7] (byte~) main::$0 ← callfinalize plus 
    // [7] (byte~) main::$0 ← callfinalize plus  -- _stackpullbyte_1 
    pla
    // [7] (byte~) main::$0 ← callfinalize plus  -- vbuz1=_stackpullbyte_ 
    pla
    sta.z __0
    // [8] *((const byte*) SCREEN) ← (byte~) main::$0 -- _deref_pbuc1=vbuz1 
    lda.z __0
    sta SCREEN
    jmp __breturn
    // main::@return
  __breturn:
    // [9] return 
    rts
}
  // plus
// plus(byte zp(3) a, byte zp(4) b)
plus: {
    .const OFFSET_STACK_A = 0
    .const OFFSET_STACK_B = 1
    .const OFFSET_STACK_RETURN = 1
    .label a = 3
    .label b = 4
    .label return = 5
    // [10] (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
    // [11] (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
    // [12] (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:
    // [13] return (byte) plus::return#0
    // [13] 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 [5] callprepare plus (byte) '0' (byte) 7  [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [7] (byte~) main::$0 ← callfinalize plus  [ main::$0 ] ( main:2 [ main::$0 ] ) always clobbers reg byte a 
Statement [10] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) [ plus::a#0 ] ( main:2::plus:6 [ plus::a#0 ] ) always clobbers reg byte a reg byte x 
Statement [11] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B) [ plus::a#0 plus::b#0 ] ( main:2::plus:6 [ 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]:3 [ plus::a#0 ]
Removing always clobbered register reg byte x as potential for zp[1]:3 [ plus::a#0 ]
Statement [12] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0 [ plus::return#0 ] ( main:2::plus:6 [ plus::return#0 ] ) always clobbers reg byte a 
Statement [13] return (byte) plus::return#0 [ ] ( main:2::plus:6 [ ] ) always clobbers reg byte x 
Statement [5] callprepare plus (byte) '0' (byte) 7  [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [7] (byte~) main::$0 ← callfinalize plus  [ main::$0 ] ( main:2 [ main::$0 ] ) always clobbers reg byte a 
Statement [10] (byte) plus::a#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_A) [ plus::a#0 ] ( main:2::plus:6 [ plus::a#0 ] ) always clobbers reg byte a reg byte x 
Statement [11] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B) [ plus::a#0 plus::b#0 ] ( main:2::plus:6 [ plus::a#0 plus::b#0 ] ) always clobbers reg byte a reg byte x 
Statement [12] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0 [ plus::return#0 ] ( main:2::plus:6 [ plus::return#0 ] ) always clobbers reg byte a 
Statement [13] return (byte) plus::return#0 [ ] ( main:2::plus:6 [ ] ) always clobbers reg byte x 
Potential registers zp[1]:2 [ main::$0 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ plus::a#0 ] : zp[1]:3 , reg byte y , 
Potential registers zp[1]:4 [ plus::b#0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ plus::return#0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [plus] 4: zp[1]:4 [ plus::b#0 ] 2: zp[1]:3 [ plus::a#0 ] 2: zp[1]:5 [ plus::return#0 ] 
Uplift Scope [main] 2: zp[1]:2 [ main::$0 ] 
Uplift Scope [] 

Uplifting [plus] best 91 combination reg byte a [ plus::b#0 ] zp[1]:3 [ plus::a#0 ] reg byte a [ plus::return#0 ] 
Uplifting [main] best 85 combination reg byte a [ main::$0 ] 
Uplifting [] best 85 combination 
Attempting to uplift remaining variables inzp[1]:3 [ plus::a#0 ]
Uplifting [plus] best 85 combination zp[1]:3 [ plus::a#0 ] 
Allocated (was zp[1]:3) zp[1]:2 [ plus::a#0 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test a procedure with calling convention stack
  // 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] callprepare plus (byte) '0' (byte) 7 
    // [5] callprepare plus (byte) '0' (byte) 7  -- _stackpushbyte_=vbuc1 
    lda #'0'
    pha
    // [5] callprepare plus (byte) '0' (byte) 7  -- _stackpushbyte_=vbuc1 
    lda #7
    pha
    // [5] callprepare plus (byte) '0' (byte) 7 
    // [6] callexecute plus  -- jsr 
    jsr plus
    // [7] (byte~) main::$0 ← callfinalize plus 
    // [7] (byte~) main::$0 ← callfinalize plus  -- _stackpullbyte_1 
    pla
    // [7] (byte~) main::$0 ← callfinalize plus  -- vbuaa=_stackpullbyte_ 
    pla
    // [8] *((const byte*) SCREEN) ← (byte~) main::$0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    jmp __breturn
    // main::@return
  __breturn:
    // [9] 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
    // [10] (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
    // [11] (byte) plus::b#0 ← stackidx(byte,(const byte) plus::OFFSET_STACK_B) -- vbuaa=_stackidxbyte_vbuc1 
    tsx
    lda STACK_BASE+OFFSET_STACK_B,x
    // [12] (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:
    // [13] return (byte) plus::return#0
    // [13] 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 __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
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
(const byte*) SCREEN = (byte*) 1024
(const word) STACK_BASE = (word) $103
(void()) main()
(byte~) main::$0 reg byte a 2.0
(label) main::@return
__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 a [ main::$0 ]
zp[1]:2 [ plus::a#0 ]
reg byte a [ plus::b#0 ]
reg byte a [ plus::return#0 ]


FINAL ASSEMBLER
Score: 67

  // File Comments
// Test a procedure with calling convention stack
  // 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: {
    // plus('0', 7)
    // [5] callprepare plus (byte) '0' (byte) 7 
    // [5] callprepare plus (byte) '0' (byte) 7  -- _stackpushbyte_=vbuc1 
    lda #'0'
    pha
    // [5] callprepare plus (byte) '0' (byte) 7  -- _stackpushbyte_=vbuc1 
    lda #7
    pha
    // [5] callprepare plus (byte) '0' (byte) 7 
    // [6] callexecute plus  -- jsr 
    jsr plus
    // [7] (byte~) main::$0 ← callfinalize plus 
    // [7] (byte~) main::$0 ← callfinalize plus  -- _stackpullbyte_1 
    pla
    // [7] (byte~) main::$0 ← callfinalize plus  -- vbuaa=_stackpullbyte_ 
    pla
    // SCREEN[0] = plus('0', 7)
    // [8] *((const byte*) SCREEN) ← (byte~) main::$0 -- _deref_pbuc1=vbuaa 
    sta SCREEN
    // main::@return
    // }
    // [9] 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
    // [10] (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
    // [11] (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;
    // [12] (byte) plus::return#0 ← (byte) plus::a#0 + (byte) plus::b#0 -- vbuaa=vbuz1_plus_vbuaa 
    clc
    adc.z a
    // plus::@return
    // }
    // [13] return (byte) plus::return#0
    // [13] return (byte) plus::return#0 -- _stackidxbyte_vbuc1=vbuaa 
    tsx
    sta STACK_BASE+OFFSET_STACK_RETURN,x
    rts
}
  // File Data

