Inlined call call __init

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  main::a#0 = 0
  foo::x#0 = 1
  call foo
  foo::return#0 = foo::return#2
  to:main::@1
main::@1: scope:[main]  from main
  foo::return#3 = phi( main/foo::return#0 )
  main::$0 = foo::return#3
  main::$1 = main::$0 & 3
  main::a#1 = main::$1
  *SCREEN = (char)main::a#1
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return

char foo(char x)
foo: scope:[foo]  from main
  foo::x#1 = phi( main/foo::x#0 )
  foo::return#1 = bar[foo::x#1]
  to:foo::@return
foo::@return: scope:[foo]  from foo
  foo::return#4 = phi( foo/foo::return#1 )
  foo::return#2 = foo::return#4
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  return 
  to:@return

SYMBOL TABLE SSA
__constant char *SCREEN = (char *)$400
void __start()
__constant char bar[$a] = { 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
char foo(char x)
char foo::return
char foo::return#0
char foo::return#1
char foo::return#2
char foo::return#3
char foo::return#4
char foo::x
char foo::x#0
char foo::x#1
void main()
char main::$0
number main::$1
unsigned int main::a
unsigned int main::a#0
unsigned int main::a#1

Adding number conversion cast (unumber) 1 in foo::x#0 = 1
Adding number conversion cast (unumber) 3 in main::$1 = main::$0 & 3
Adding number conversion cast (unumber) main::$1 in main::$1 = main::$0 & (unumber)3
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast foo::x#0 = (unumber)1
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$1 = main::$0 & 3
Alias foo::return#0 = foo::return#3 
Alias main::a#1 = main::$1 
Alias foo::return#1 = foo::return#4 foo::return#2 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values foo::x#1 foo::x#0
Successful SSA optimization Pass2IdenticalPhiElimination
Constant main::a#0 = 0
Constant foo::x#0 = 1
Successful SSA optimization Pass2ConstantIdentification
Eliminating unused constant main::a#0
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::__init1
Removing unused procedure block __start::@1
Removing unused procedure block __start::@2
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Consolidated array index constant in *(bar+foo::x#0)
Successful SSA optimization Pass2ConstantAdditionElimination
Finalized unsigned number type (char) $a
Successful SSA optimization PassNFinalizeNumberTypeConversions
Adding NOP phi() at start of main
CALL GRAPH
Calls in [main] to foo:1 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  [1] call foo
  [2] foo::return#0 = foo::return#1
  to:main::@1
main::@1: scope:[main]  from main
  [3] main::$0 = foo::return#0
  [4] main::a#1 = main::$0 & 3
  [5] *SCREEN = (char)main::a#1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [6] return 
  to:@return

char foo(char x)
foo: scope:[foo]  from main
  [7] foo::return#1 = *(bar+foo::x#0)
  to:foo::@return
foo::@return: scope:[foo]  from foo
  [8] return 
  to:@return


VARIABLE REGISTER WEIGHTS
char foo(char x)
char foo::return
char foo::return#0 // 4.0
char foo::return#1 // 4.333333333333333
char foo::x
void main()
char main::$0 // 4.0
unsigned int main::a
unsigned int main::a#1 // 2.0

Initial phi equivalence classes
Added variable foo::return#0 to live range equivalence class [ foo::return#0 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Added variable main::a#1 to live range equivalence class [ main::a#1 ]
Added variable foo::return#1 to live range equivalence class [ foo::return#1 ]
Complete equivalence classes
[ foo::return#0 ]
[ main::$0 ]
[ main::a#1 ]
[ foo::return#1 ]
Allocated zp[1]:2 [ foo::return#1 ]
Allocated zp[1]:3 [ foo::return#0 ]
Allocated zp[1]:4 [ main::$0 ]
Allocated zp[2]:5 [ main::a#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] main::a#1 = main::$0 & 3 [ main::a#1 ] (  [ main::a#1 ] { }  ) always clobbers reg byte a 
Statement [5] *SCREEN = (char)main::a#1 [ ] (  [ ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:3 [ foo::return#0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ main::$0 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[2]:5 [ main::a#1 ] : zp[2]:5 , 
Potential registers zp[1]:2 [ foo::return#1 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 

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

Uplifting [foo] best 54 combination reg byte a [ foo::return#1 ] reg byte a [ foo::return#0 ] 
Uplifting [main] best 48 combination reg byte a [ main::$0 ] zp[2]:5 [ main::a#1 ] 
Uplifting [] best 48 combination 
Allocated (was zp[2]:5) zp[2]:2 [ main::a#1 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Demonstrates missing fragment
// https://gitlab.com/camelot/kickc/-/issues/293
  // Upstart
  // Commodore 64 PRG executable file
.file [name="missing-band.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label a = 2
    // [1] call foo
    jsr foo
    // [2] foo::return#0 = foo::return#1
    jmp __b1
    // main::@1
  __b1:
    // [3] main::$0 = foo::return#0
    // [4] main::a#1 = main::$0 & 3 -- vwuz1=vbuaa_band_vbuc1 
    and #3
    sta.z a
    lda #0
    sta.z a+1
    // [5] *SCREEN = (char)main::a#1 -- _deref_pbuc1=_byte_vwuz1 
    lda.z a
    sta SCREEN
    jmp __breturn
    // main::@return
  __breturn:
    // [6] return 
    rts
}
  // foo
// __register(A) char foo(char x)
foo: {
    .const x = 1
    // [7] foo::return#1 = *(bar+foo::x#0) -- vbuaa=_deref_pbuc1 
    lda bar+x
    jmp __breturn
    // foo::@return
  __breturn:
    // [8] return 
    rts
}
  // File Data
.segment Data
  bar: .byte 9, 1, 2, 3, 4, 5, 6, 7, 8, 9

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant char *SCREEN = (char *) 1024
__constant char bar[$a] = { 9, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
char foo(char x)
char foo::return
char foo::return#0 // reg byte a 4.0
char foo::return#1 // reg byte a 4.333333333333333
char foo::x
__constant char foo::x#0 = 1 // x
void main()
char main::$0 // reg byte a 4.0
unsigned int main::a
unsigned int main::a#1 // a zp[2]:2 2.0

reg byte a [ foo::return#0 ]
reg byte a [ main::$0 ]
zp[2]:2 [ main::a#1 ]
reg byte a [ foo::return#1 ]


FINAL ASSEMBLER
Score: 39

  // File Comments
// Demonstrates missing fragment
// https://gitlab.com/camelot/kickc/-/issues/293
  // Upstart
  // Commodore 64 PRG executable file
.file [name="missing-band.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .label SCREEN = $400
.segment Code
  // main
main: {
    .label a = 2
    // foo(1)
    // [1] call foo
    jsr foo
    // [2] foo::return#0 = foo::return#1
    // main::@1
    // [3] main::$0 = foo::return#0
    // a=(foo(1) & 3)
    // [4] main::a#1 = main::$0 & 3 -- vwuz1=vbuaa_band_vbuc1 
    and #3
    sta.z a
    lda #0
    sta.z a+1
    // *SCREEN = (byte)a
    // [5] *SCREEN = (char)main::a#1 -- _deref_pbuc1=_byte_vwuz1 
    lda.z a
    sta SCREEN
    // main::@return
    // }
    // [6] return 
    rts
}
  // foo
// __register(A) char foo(char x)
foo: {
    .const x = 1
    // return bar[x];
    // [7] foo::return#1 = *(bar+foo::x#0) -- vbuaa=_deref_pbuc1 
    lda bar+x
    // foo::@return
    // }
    // [8] return 
    rts
}
  // File Data
.segment Data
  bar: .byte 9, 1, 2, 3, 4, 5, 6, 7, 8, 9

