PARSING src/test/java/dk/camelot64/kickc/test/kc/unused-method.kc
void main() {
    byte* screen = $0400;
    screen[0] = 1;
}

byte sum(byte b1, byte b2) {
    return b1+b2;
}

STATEMENTS
proc (void()) main()
  (byte*) main::screen ← (word/signed word/dword/signed dword) 1024
  *((byte*) main::screen + (byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte/signed byte/word/signed word/dword/signed dword) 1
main::@return:
  return 
endproc // main()
proc (byte()) sum((byte) sum::b1 , (byte) sum::b2)
  (byte/word~) sum::$0 ← (byte) sum::b1 + (byte) sum::b2
  (byte) sum::return ← (byte/word~) sum::$0
  goto sum::@return
sum::@return:
  (byte) sum::return ← (byte) sum::return
  return (byte) sum::return
endproc // sum()
  call main 

SYMBOLS
(void()) main()
(label) main::@return
(byte*) main::screen
(byte()) sum((byte) sum::b1 , (byte) sum::b2)
(byte/word~) sum::$0
(label) sum::@return
(byte) sum::b1
(byte) sum::b2
(byte) sum::return

Promoting word/signed word/dword/signed dword to byte* in main::screen ← ((byte*)) 1024
INITIAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  to:@1
main: scope:[main]  from
  (byte*) main::screen ← ((byte*)) (word/signed word/dword/signed dword) 1024
  *((byte*) main::screen + (byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte/signed byte/word/signed word/dword/signed dword) 1
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
@1: scope:[]  from @begin
  to:@2
sum: scope:[sum]  from
  (byte/word~) sum::$0 ← (byte) sum::b1 + (byte) sum::b2
  (byte) sum::return ← (byte/word~) sum::$0
  to:sum::@return
sum::@return: scope:[sum]  from sum sum::@1
  (byte) sum::return ← (byte) sum::return
  return (byte) sum::return
  to:@return
sum::@1: scope:[sum]  from
  to:sum::@return
@2: scope:[]  from @1
  call main 
  to:@end
@end: scope:[]  from @2

Removing unused procedure sum
Removing empty block @1
PROCEDURE MODIFY VARIABLE ANALYSIS

Completing Phi functions...

CONTROL FLOW GRAPH SSA WITH ASSIGNMENT CALL & RETURN
@begin: scope:[]  from
  to:@2
main: scope:[main]  from @2
  (byte*) main::screen#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  *((byte*) main::screen#0 + (byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte/signed byte/word/signed word/dword/signed dword) 1
  to:main::@return
main::@return: scope:[main]  from main
  return 
  to:@return
@2: scope:[]  from @begin
  call main param-assignment
  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()
(label) main::@return
(byte*) main::screen
(byte*) main::screen#0

OPTIMIZING CONTROL FLOW GRAPH
Culled Empty Block (label) @3
Succesful SSA optimization Pass2CullEmptyBlocks
Constant (const byte*) main::screen#0 = ((byte*))1024
Succesful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(main::screen#0+0)
Succesful SSA optimization Pass2ConstantAdditionElimination
OPTIMIZING CONTROL FLOW GRAPH
Block Sequence Planned @begin @2 @end main main::@return 
Block Sequence Planned @begin @2 @end main main::@return 
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
CALL GRAPH
Calls in [] to main:2 

Propagating live ranges...
Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Block Sequence Planned @begin @2 @end main main::@return 
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Propagating live ranges...

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi() [ ] ( )
  to:@2
@2: scope:[]  from @begin
  [1] phi() [ ] ( )
  [2] call main param-assignment [ ] ( )
  to:@end
@end: scope:[]  from @2
  [3] phi() [ ] ( )
main: scope:[main]  from @2
  [4] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte/signed byte/word/signed word/dword/signed dword) 1 [ ] ( main:2 [ ] )
  to:main::@return
main::@return: scope:[main]  from main
  [5] return  [ ] ( main:2 [ ] )
  to:@return

DOMINATORS
@begin dominated by  @begin 
@2 dominated by  @2 @begin 
@end dominated by  @2 @begin @end 
main dominated by  @2 @begin main 
main::@return dominated by  main::@return @2 @begin main 

NATURAL LOOPS

NATURAL LOOPS WITH DEPTH
Found 0 loops in scope []
Found 0 loops in scope [main]


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte*) main::screen

Initial phi equivalence classes
Complete equivalence classes

INITIAL ASM
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @2 [phi:@begin->@2]
b2_from_bbegin:
  jmp b2
//SEG4 @2
b2:
//SEG5 [2] call main param-assignment [ ] ( )
  jsr main
//SEG6 [3] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
  jmp bend
//SEG7 @end
bend:
//SEG8 main
main: {
    .label screen = $400
  //SEG9 [4] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte/signed byte/word/signed word/dword/signed dword) 1 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 
    lda #1
    sta screen+0
    jmp breturn
  //SEG10 main::@return
  breturn:
  //SEG11 [5] return  [ ] ( main:2 [ ] )
    rts
}

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte/signed byte/word/signed word/dword/signed dword) 1 [ ] ( main:2 [ ] ) always clobbers reg byte a 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 
Uplift Scope [] 

Uplifting [main] best 27 combination 
Uplifting [] best 27 combination 

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
//SEG2 @begin
bbegin:
//SEG3 [1] phi from @begin to @2 [phi:@begin->@2]
b2_from_bbegin:
  jmp b2
//SEG4 @2
b2:
//SEG5 [2] call main param-assignment [ ] ( )
  jsr main
//SEG6 [3] phi from @2 to @end [phi:@2->@end]
bend_from_b2:
  jmp bend
//SEG7 @end
bend:
//SEG8 main
main: {
    .label screen = $400
  //SEG9 [4] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte/signed byte/word/signed word/dword/signed dword) 1 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 
    lda #1
    sta screen+0
    jmp breturn
  //SEG10 main::@return
  breturn:
  //SEG11 [5] return  [ ] ( main:2 [ ] )
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b2
Removing instruction jmp bend
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction bbegin:
Removing instruction b2_from_bbegin:
Removing instruction bend_from_b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction b2:
Removing instruction bend:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @2
(label) @begin
(label) @end
(void()) main()
(label) main::@return
(byte*) main::screen
(const byte*) main::screen#0 screen = ((byte*))(word/signed word/dword/signed dword) 1024



FINAL ASSEMBLER
Score: 18

//SEG0 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG1 Global Constants & labels
//SEG2 @begin
//SEG3 [1] phi from @begin to @2 [phi:@begin->@2]
//SEG4 @2
//SEG5 [2] call main param-assignment [ ] ( )
  jsr main
//SEG6 [3] phi from @2 to @end [phi:@2->@end]
//SEG7 @end
//SEG8 main
main: {
    .label screen = $400
  //SEG9 [4] *((const byte*) main::screen#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte/signed byte/word/signed word/dword/signed dword) 1 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2 
    lda #1
    sta screen+0
  //SEG10 main::@return
  //SEG11 [5] return  [ ] ( main:2 [ ] )
    rts
}

