Fixing pointer addition (word*~) bsearch16u::$7 ← (word*) bsearch16u::items + (byte~) bsearch16u::$6
Fixing pointer addition (word*~) bsearch16u::$15 ← (word*) bsearch16u::pivot + (number) 1
Fixing pointer addition (word*~) bsearch16u::$1 ← (word*) bsearch16u::items - (number) 1
Fixing pointer array-indexing *((word*) utoa::digit_values + (byte) utoa::digit)
Fixing pointer array-indexing *((dword*) ultoa::digit_values + (byte) ultoa::digit)
Warning! Adding boolean cast to non-boolean condition *((byte*) strcpy::src)
Identified constant variable (byte*) HEAP_TOP
Identified constant variable (byte*) main::screen
Culled Empty Block (label) @1
Culled Empty Block (label) @2
Culled Empty Block (label) @3
Culled Empty Block (label) malloc::@1
Culled Empty Block (label) @5
Culled Empty Block (label) @6
Culled Empty Block (label) @7
Culled Empty Block (label) @8
Culled Empty Block (label) @9
Culled Empty Block (label) @10
Culled Empty Block (label) @11
Culled Empty Block (label) @12

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@4
@4: scope:[]  from @begin
  (byte*) HEAP_TOP#0 ← ((byte*)) (number) $a000
  (byte*) heap_head#0 ← (byte*) HEAP_TOP#0
  to:@13
malloc: scope:[malloc]  from main main::@3
  (word) malloc::size#2 ← phi( main/(word) malloc::size#0 main::@3/(word) malloc::size#1 )
  (byte*) heap_head#7 ← phi( main/(byte*) heap_head#13 main::@3/(byte*) heap_head#3 )
  (byte*~) malloc::$0 ← (byte*) heap_head#7 - (word) malloc::size#2
  (byte*) malloc::mem#0 ← (byte*~) malloc::$0
  (byte*) heap_head#1 ← (byte*) malloc::mem#0
  (void*) malloc::return#0 ← ((void*)) (byte*) malloc::mem#0
  to:malloc::@return
malloc::@return: scope:[malloc]  from malloc
  (byte*) heap_head#8 ← phi( malloc/(byte*) heap_head#1 )
  (void*) malloc::return#4 ← phi( malloc/(void*) malloc::return#0 )
  (void*) malloc::return#1 ← (void*) malloc::return#4
  (byte*) heap_head#2 ← (byte*) heap_head#8
  return 
  to:@return
free: scope:[free]  from main::@2 main::@5
  to:free::@return
free::@return: scope:[free]  from free
  return 
  to:@return
main: scope:[main]  from @13
  (byte*) heap_head#13 ← phi( @13/(byte*) heap_head#15 )
  (word) malloc::size#0 ← (number) $64
  call malloc 
  (void*) malloc::return#2 ← (void*) malloc::return#1
  to:main::@3
main::@3: scope:[main]  from main
  (byte*) heap_head#9 ← phi( main/(byte*) heap_head#2 )
  (void*) malloc::return#5 ← phi( main/(void*) malloc::return#2 )
  (void*~) main::$0 ← (void*) malloc::return#5
  (byte*) heap_head#3 ← (byte*) heap_head#9
  (byte*) main::buf1#0 ← ((byte*)) (void*~) main::$0
  (word) malloc::size#1 ← (number) $64
  call malloc 
  (void*) malloc::return#3 ← (void*) malloc::return#1
  to:main::@4
main::@4: scope:[main]  from main::@3
  (byte*) main::buf1#4 ← phi( main::@3/(byte*) main::buf1#0 )
  (byte*) heap_head#10 ← phi( main::@3/(byte*) heap_head#2 )
  (void*) malloc::return#6 ← phi( main::@3/(void*) malloc::return#3 )
  (void*~) main::$1 ← (void*) malloc::return#6
  (byte*) heap_head#4 ← (byte*) heap_head#10
  (byte*) main::buf2#0 ← ((byte*)) (void*~) main::$1
  (byte) main::i#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main::@1 main::@4
  (byte*) heap_head#18 ← phi( main::@1/(byte*) heap_head#18 main::@4/(byte*) heap_head#4 )
  (byte*) main::buf2#1 ← phi( main::@1/(byte*) main::buf2#1 main::@4/(byte*) main::buf2#0 )
  (byte*) main::buf1#1 ← phi( main::@1/(byte*) main::buf1#1 main::@4/(byte*) main::buf1#4 )
  (byte) main::i#2 ← phi( main::@1/(byte) main::i#1 main::@4/(byte) main::i#0 )
  *((byte*) main::buf1#1 + (byte) main::i#2) ← (byte) main::i#2
  (number~) main::$4 ← (number) $ff - (byte) main::i#2
  *((byte*) main::buf2#1 + (byte) main::i#2) ← (number~) main::$4
  (byte) main::i#1 ← (byte) main::i#2 + rangenext(0,$63)
  (bool~) main::$5 ← (byte) main::i#1 != rangelast(0,$63)
  if((bool~) main::$5) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte*) heap_head#17 ← phi( main::@1/(byte*) heap_head#18 )
  (byte*) main::buf2#4 ← phi( main::@1/(byte*) main::buf2#1 )
  (byte*) main::buf1#2 ← phi( main::@1/(byte*) main::buf1#1 )
  (void*) free::ptr#0 ← (void*)(byte*) main::buf1#2
  call free 
  to:main::@5
main::@5: scope:[main]  from main::@2
  (byte*) heap_head#16 ← phi( main::@2/(byte*) heap_head#17 )
  (byte*) main::buf1#5 ← phi( main::@2/(byte*) main::buf1#2 )
  (byte*) main::buf2#2 ← phi( main::@2/(byte*) main::buf2#4 )
  (void*) free::ptr#1 ← (void*)(byte*) main::buf2#2
  call free 
  to:main::@6
main::@6: scope:[main]  from main::@5
  (byte*) heap_head#14 ← phi( main::@5/(byte*) heap_head#16 )
  (byte*) main::buf2#3 ← phi( main::@5/(byte*) main::buf2#2 )
  (byte*) main::buf1#3 ← phi( main::@5/(byte*) main::buf1#5 )
  (byte*) main::screen#0 ← ((byte*)) (number) $400
  *((byte*) main::screen#0 + (number) 0) ← *((byte*) main::buf1#3)
  *((byte*) main::screen#0 + (number) 1) ← *((byte*) main::buf2#3)
  to:main::@return
main::@return: scope:[main]  from main::@6
  (byte*) heap_head#11 ← phi( main::@6/(byte*) heap_head#14 )
  (byte*) heap_head#5 ← (byte*) heap_head#11
  return 
  to:@return
@13: scope:[]  from @4
  (byte*) heap_head#15 ← phi( @4/(byte*) heap_head#0 )
  call main 
  to:@14
@14: scope:[]  from @13
  (byte*) heap_head#12 ← phi( @13/(byte*) heap_head#5 )
  (byte*) heap_head#6 ← (byte*) heap_head#12
  to:@end
@end: scope:[]  from @14

SYMBOL TABLE SSA
(label) @13
(label) @14
(label) @4
(label) @begin
(label) @end
(byte*) HEAP_TOP
(byte*) HEAP_TOP#0
(const byte) RADIX::BINARY = (number) 2
(const byte) RADIX::DECIMAL = (number) $a
(const byte) RADIX::HEXADECIMAL = (number) $10
(const byte) RADIX::OCTAL = (number) 8
(void()) free((void*) free::ptr)
(label) free::@return
(void*) free::ptr
(void*) free::ptr#0
(void*) free::ptr#1
(byte*) heap_head
(byte*) heap_head#0
(byte*) heap_head#1
(byte*) heap_head#10
(byte*) heap_head#11
(byte*) heap_head#12
(byte*) heap_head#13
(byte*) heap_head#14
(byte*) heap_head#15
(byte*) heap_head#16
(byte*) heap_head#17
(byte*) heap_head#18
(byte*) heap_head#2
(byte*) heap_head#3
(byte*) heap_head#4
(byte*) heap_head#5
(byte*) heap_head#6
(byte*) heap_head#7
(byte*) heap_head#8
(byte*) heap_head#9
(void()) main()
(void*~) main::$0
(void*~) main::$1
(number~) main::$4
(bool~) main::$5
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@return
(byte*) main::buf1
(byte*) main::buf1#0
(byte*) main::buf1#1
(byte*) main::buf1#2
(byte*) main::buf1#3
(byte*) main::buf1#4
(byte*) main::buf1#5
(byte*) main::buf2
(byte*) main::buf2#0
(byte*) main::buf2#1
(byte*) main::buf2#2
(byte*) main::buf2#3
(byte*) main::buf2#4
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(byte*) main::screen
(byte*) main::screen#0
(void*()) malloc((word) malloc::size)
(byte*~) malloc::$0
(label) malloc::@return
(byte*) malloc::mem
(byte*) malloc::mem#0
(void*) malloc::return
(void*) malloc::return#0
(void*) malloc::return#1
(void*) malloc::return#2
(void*) malloc::return#3
(void*) malloc::return#4
(void*) malloc::return#5
(void*) malloc::return#6
(word) malloc::size
(word) malloc::size#0
(word) malloc::size#1
(word) malloc::size#2

Adding number conversion cast (unumber) $64 in (word) malloc::size#0 ← (number) $64
Adding number conversion cast (unumber) $64 in (word) malloc::size#1 ← (number) $64
Adding number conversion cast (unumber) $ff in (number~) main::$4 ← (number) $ff - (byte) main::i#2
Adding number conversion cast (unumber) main::$4 in (number~) main::$4 ← (unumber)(number) $ff - (byte) main::i#2
Adding number conversion cast (unumber) 0 in *((byte*) main::screen#0 + (number) 0) ← *((byte*) main::buf1#3)
Adding number conversion cast (unumber) 1 in *((byte*) main::screen#0 + (number) 1) ← *((byte*) main::buf2#3)
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) HEAP_TOP#0 ← (byte*)(number) $a000
Inlining cast (void*) malloc::return#0 ← (void*)(byte*) malloc::mem#0
Inlining cast (word) malloc::size#0 ← (unumber)(number) $64
Inlining cast (byte*) main::buf1#0 ← (byte*)(void*~) main::$0
Inlining cast (word) malloc::size#1 ← (unumber)(number) $64
Inlining cast (byte*) main::buf2#0 ← (byte*)(void*~) main::$1
Inlining cast (byte*) main::screen#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 40960
Simplifying constant integer cast $64
Simplifying constant integer cast $64
Simplifying constant integer cast $ff
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $64
Finalized unsigned number type (byte) $64
Finalized unsigned number type (byte) $ff
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$4 ← (byte) $ff - (byte) main::i#2
Alias (byte*) HEAP_TOP#0 = (byte*) heap_head#0 (byte*) heap_head#15 
Alias (byte*) malloc::mem#0 = (byte*~) malloc::$0 
Alias (void*) malloc::return#0 = (void*) malloc::return#4 (void*) malloc::return#1 
Alias (byte*) heap_head#1 = (byte*) heap_head#8 (byte*) heap_head#2 
Alias (void*) malloc::return#2 = (void*) malloc::return#5 
Alias (byte*) heap_head#3 = (byte*) heap_head#9 
Alias (void*) malloc::return#3 = (void*) malloc::return#6 
Alias (byte*) main::buf1#0 = (byte*) main::buf1#4 
Alias (byte*) heap_head#10 = (byte*) heap_head#4 
Alias (byte*) main::buf1#1 = (byte*) main::buf1#2 (byte*) main::buf1#5 (byte*) main::buf1#3 
Alias (byte*) main::buf2#1 = (byte*) main::buf2#4 (byte*) main::buf2#2 (byte*) main::buf2#3 
Alias (byte*) heap_head#11 = (byte*) heap_head#17 (byte*) heap_head#18 (byte*) heap_head#16 (byte*) heap_head#14 (byte*) heap_head#5 
Alias (byte*) heap_head#12 = (byte*) heap_head#6 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte*) heap_head#13 (byte*) HEAP_TOP#0
Identical Phi Values (byte*) heap_head#3 (byte*) heap_head#1
Identical Phi Values (byte*) heap_head#10 (byte*) heap_head#1
Identical Phi Values (byte*) main::buf1#1 (byte*) main::buf1#0
Identical Phi Values (byte*) main::buf2#1 (byte*) main::buf2#0
Identical Phi Values (byte*) heap_head#11 (byte*) heap_head#10
Identical Phi Values (byte*) heap_head#12 (byte*) heap_head#11
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$5 [34] if((byte) main::i#1!=rangelast(0,$63)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) HEAP_TOP#0 = (byte*) 40960
Constant (const word) malloc::size#0 = $64
Constant (const word) malloc::size#1 = $64
Constant (const byte) main::i#0 = 0
Constant (const byte*) main::screen#0 = (byte*) 1024
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [32] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [34] if(main::i#1!=rangelast(0,$63)) goto main::@1 to (number) $64
Simplifying expression containing zero main::screen#0 in [43] *((const byte*) main::screen#0 + (byte) 0) ← *((byte*) main::buf1#0)
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused variable (void*) free::ptr#0 and assignment [20] (void*) free::ptr#0 ← (void*)(byte*) main::buf1#0
Eliminating unused variable (void*) free::ptr#1 and assignment [22] (void*) free::ptr#1 ← (void*)(byte*) main::buf2#0
Successful SSA optimization PassNEliminateUnusedVars
Adding number conversion cast (unumber) $64 in if((byte) main::i#1!=(number) $64) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $64
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $64
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining Noop Cast [3] (void*) malloc::return#0 ← (void*)(byte*) malloc::mem#0 keeping malloc::mem#0
Successful SSA optimization Pass2NopCastInlining
Inlining Noop Cast [7] (void*) malloc::return#2 ← (void*)(byte*) malloc::mem#0 keeping malloc::mem#0
Inlining Noop Cast [11] (void*) malloc::return#3 ← (void*)(byte*) malloc::mem#0 keeping malloc::mem#0
Successful SSA optimization Pass2NopCastInlining
Inlining Noop Cast [9] (byte*) main::buf1#0 ← (byte*)(void*~) main::$0 keeping main::buf1#0
Inlining Noop Cast [13] (byte*) main::buf2#0 ← (byte*)(void*~) main::$1 keeping main::buf2#0
Successful SSA optimization Pass2NopCastInlining
Inlining constant with var siblings (const word) malloc::size#0
Inlining constant with var siblings (const word) malloc::size#1
Inlining constant with var siblings (const byte) main::i#0
Constant inlined main::i#0 = (byte) 0
Constant inlined malloc::size#1 = (byte) $64
Constant inlined malloc::size#0 = (byte) $64
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::screen#0+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Identical Phi Values (word) malloc::size#2 (byte) $64
Successful SSA optimization Pass2IdenticalPhiElimination
Added new block during phi lifting main::@7(between main::@1 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @4
Adding NOP phi() at start of @13
Adding NOP phi() at start of @14
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
Adding NOP phi() at start of main::@2
Adding NOP phi() at start of main::@5
Adding NOP phi() at start of free
CALL GRAPH
Calls in [] to main:3 
Calls in [main] to malloc:7 malloc:10 free:19 free:21 

Created 2 initial phi equivalence classes
Coalesced [9] heap_head#19 ← heap_head#1
Coalesced [25] main::i#3 ← main::i#1
Not coalescing [30] heap_head#1 ← malloc::mem#0
Coalesced down to 3 phi equivalence classes
Culled Empty Block (label) @4
Culled Empty Block (label) @14
Culled Empty Block (label) main::@7
Renumbering block @13 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
Adding NOP phi() at start of main::@2
Adding NOP phi() at start of main::@5
Adding NOP phi() at start of free

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()
main: scope:[main]  from @1
  [4] phi()
  [5] call malloc 
  to:main::@3
main::@3: scope:[main]  from main
  [6] (void*) main::buf1#0 ← (void*)(byte*) malloc::mem#0
  [7] call malloc 
  to:main::@4
main::@4: scope:[main]  from main::@3
  [8] (void*) main::buf2#0 ← (void*)(byte*) malloc::mem#0
  to:main::@1
main::@1: scope:[main]  from main::@1 main::@4
  [9] (byte) main::i#2 ← phi( main::@1/(byte) main::i#1 main::@4/(byte) 0 )
  [10] *((byte*)(void*) main::buf1#0 + (byte) main::i#2) ← (byte) main::i#2
  [11] (byte~) main::$4 ← (byte) $ff - (byte) main::i#2
  [12] *((byte*)(void*) main::buf2#0 + (byte) main::i#2) ← (byte~) main::$4
  [13] (byte) main::i#1 ← ++ (byte) main::i#2
  [14] if((byte) main::i#1!=(byte) $64) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@1
  [15] phi()
  [16] call free 
  to:main::@5
main::@5: scope:[main]  from main::@2
  [17] phi()
  [18] call free 
  to:main::@6
main::@6: scope:[main]  from main::@5
  [19] *((const byte*) main::screen#0) ← *((byte*)(void*) main::buf1#0)
  [20] *((const byte*) main::screen#0+(byte) 1) ← *((byte*)(void*) main::buf2#0)
  to:main::@return
main::@return: scope:[main]  from main::@6
  [21] return 
  to:@return
free: scope:[free]  from main::@2 main::@5
  [22] phi()
  to:free::@return
free::@return: scope:[free]  from free
  [23] return 
  to:@return
malloc: scope:[malloc]  from main main::@3
  [24] (byte*) heap_head#7 ← phi( main/(const byte*) HEAP_TOP#0 main::@3/(byte*) heap_head#1 )
  [25] (byte*) malloc::mem#0 ← (byte*) heap_head#7 - (byte) $64
  [26] (byte*) heap_head#1 ← (byte*) malloc::mem#0
  to:malloc::@return
malloc::@return: scope:[malloc]  from malloc
  [27] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte*) HEAP_TOP
(void()) free((void*) free::ptr)
(void*) free::ptr
(byte*) heap_head
(byte*) heap_head#1 1.0
(byte*) heap_head#7 4.0
(void()) main()
(byte~) main::$4 22.0
(byte*) main::buf1
(void*) main::buf1#0 0.15384615384615385
(byte*) main::buf2
(void*) main::buf2#0 0.16666666666666666
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 16.5
(byte*) main::screen
(void*()) malloc((word) malloc::size)
(byte*) malloc::mem
(byte*) malloc::mem#0 0.8
(void*) malloc::return
(word) malloc::size

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
[ heap_head#7 heap_head#1 ]
Added variable main::buf1#0 to zero page equivalence class [ main::buf1#0 ]
Added variable main::buf2#0 to zero page equivalence class [ main::buf2#0 ]
Added variable main::$4 to zero page equivalence class [ main::$4 ]
Added variable malloc::mem#0 to zero page equivalence class [ malloc::mem#0 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ heap_head#7 heap_head#1 ]
[ main::buf1#0 ]
[ main::buf2#0 ]
[ main::$4 ]
[ malloc::mem#0 ]
Allocated zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_WORD:3 [ heap_head#7 heap_head#1 ]
Allocated zp ZP_WORD:5 [ main::buf1#0 ]
Allocated zp ZP_WORD:7 [ main::buf2#0 ]
Allocated zp ZP_BYTE:9 [ main::$4 ]
Allocated zp ZP_WORD:10 [ malloc::mem#0 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
// Experiments with malloc()
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // Top of the heap used by malloc()
  .label HEAP_TOP = $a000
  .label heap_head = 3
  // @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 screen = $400
    .label _4 = 9
    .label buf1 = 5
    .label buf2 = 7
    .label i = 2
    // [5] call malloc 
    // [24] phi from main to malloc [phi:main->malloc]
  malloc_from_main:
    // [24] phi (byte*) heap_head#7 = (const byte*) HEAP_TOP#0 [phi:main->malloc#0] -- pbuz1=pbuc1 
    lda #<HEAP_TOP
    sta.z heap_head
    lda #>HEAP_TOP
    sta.z heap_head+1
    jsr malloc
    jmp b3
    // main::@3
  b3:
    // [6] (void*) main::buf1#0 ← (void*)(byte*) malloc::mem#0 -- pvoz1=pvoz2 
    lda.z malloc.mem
    sta.z buf1
    lda.z malloc.mem+1
    sta.z buf1+1
    // [7] call malloc 
    // [24] phi from main::@3 to malloc [phi:main::@3->malloc]
  malloc_from_b3:
    // [24] phi (byte*) heap_head#7 = (byte*) heap_head#1 [phi:main::@3->malloc#0] -- register_copy 
    jsr malloc
    jmp b4
    // main::@4
  b4:
    // [8] (void*) main::buf2#0 ← (void*)(byte*) malloc::mem#0 -- pvoz1=pvoz2 
    lda.z malloc.mem
    sta.z buf2
    lda.z malloc.mem+1
    sta.z buf2+1
    // [9] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  b1_from_b4:
    // [9] phi (byte) main::i#2 = (byte) 0 [phi:main::@4->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp b1
    // [9] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [9] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [10] *((byte*)(void*) main::buf1#0 + (byte) main::i#2) ← (byte) main::i#2 -- pbuz1_derefidx_vbuz2=vbuz2 
    lda.z i
    tay
    sta (buf1),y
    // [11] (byte~) main::$4 ← (byte) $ff - (byte) main::i#2 -- vbuz1=vbuc1_minus_vbuz2 
    lda #$ff
    sec
    sbc.z i
    sta.z _4
    // [12] *((byte*)(void*) main::buf2#0 + (byte) main::i#2) ← (byte~) main::$4 -- pbuz1_derefidx_vbuz2=vbuz3 
    lda.z _4
    ldy.z i
    sta (buf2),y
    // [13] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [14] if((byte) main::i#1!=(byte) $64) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #$64
    cmp.z i
    bne b1_from_b1
    // [15] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
    jmp b2
    // main::@2
  b2:
    // [16] call free 
    // [22] phi from main::@2 to free [phi:main::@2->free]
  free_from_b2:
    jsr free
    // [17] phi from main::@2 to main::@5 [phi:main::@2->main::@5]
  b5_from_b2:
    jmp b5
    // main::@5
  b5:
    // [18] call free 
    // [22] phi from main::@5 to free [phi:main::@5->free]
  free_from_b5:
    jsr free
    jmp b6
    // main::@6
  b6:
    // [19] *((const byte*) main::screen#0) ← *((byte*)(void*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (buf1),y
    sta screen
    // [20] *((const byte*) main::screen#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (buf2),y
    sta screen+1
    jmp breturn
    // main::@return
  breturn:
    // [21] return 
    rts
}
  // free
// A block of memory previously allocated by a call to malloc is deallocated, making it available again for further allocations.
// If ptr is a null pointer, the function does nothing.
free: {
    jmp breturn
    // free::@return
  breturn:
    // [23] return 
    rts
}
  // malloc
// Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.
// The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.
malloc: {
    .label mem = $a
    // [25] (byte*) malloc::mem#0 ← (byte*) heap_head#7 - (byte) $64 -- pbuz1=pbuz2_minus_vwuc1 
    lda.z heap_head
    sec
    sbc #<$64
    sta.z mem
    lda.z heap_head+1
    sbc #>$64
    sta.z mem+1
    // [26] (byte*) heap_head#1 ← (byte*) malloc::mem#0 -- pbuz1=pbuz2 
    lda.z mem
    sta.z heap_head
    lda.z mem+1
    sta.z heap_head+1
    jmp breturn
    // malloc::@return
  breturn:
    // [27] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (void*) main::buf1#0 ← (void*)(byte*) malloc::mem#0 [ main::buf1#0 heap_head#1 ] ( main:2 [ main::buf1#0 heap_head#1 ] ) always clobbers reg byte a 
Statement [8] (void*) main::buf2#0 ← (void*)(byte*) malloc::mem#0 [ main::buf1#0 main::buf2#0 ] ( main:2 [ main::buf1#0 main::buf2#0 ] ) always clobbers reg byte a 
Statement [11] (byte~) main::$4 ← (byte) $ff - (byte) main::i#2 [ main::buf1#0 main::buf2#0 main::i#2 main::$4 ] ( main:2 [ main::buf1#0 main::buf2#0 main::i#2 main::$4 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Statement [19] *((const byte*) main::screen#0) ← *((byte*)(void*) main::buf1#0) [ main::buf2#0 ] ( main:2 [ main::buf2#0 ] ) always clobbers reg byte a reg byte y 
Statement [20] *((const byte*) main::screen#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y 
Statement [25] (byte*) malloc::mem#0 ← (byte*) heap_head#7 - (byte) $64 [ malloc::mem#0 ] ( main:2::malloc:5 [ malloc::mem#0 ] main:2::malloc:7 [ main::buf1#0 malloc::mem#0 ] ) always clobbers reg byte a 
Statement [26] (byte*) heap_head#1 ← (byte*) malloc::mem#0 [ malloc::mem#0 heap_head#1 ] ( main:2::malloc:5 [ malloc::mem#0 heap_head#1 ] main:2::malloc:7 [ main::buf1#0 malloc::mem#0 heap_head#1 ] ) always clobbers reg byte a 
Statement [6] (void*) main::buf1#0 ← (void*)(byte*) malloc::mem#0 [ main::buf1#0 heap_head#1 ] ( main:2 [ main::buf1#0 heap_head#1 ] ) always clobbers reg byte a 
Statement [8] (void*) main::buf2#0 ← (void*)(byte*) malloc::mem#0 [ main::buf1#0 main::buf2#0 ] ( main:2 [ main::buf1#0 main::buf2#0 ] ) always clobbers reg byte a 
Statement [10] *((byte*)(void*) main::buf1#0 + (byte) main::i#2) ← (byte) main::i#2 [ main::buf1#0 main::buf2#0 main::i#2 ] ( main:2 [ main::buf1#0 main::buf2#0 main::i#2 ] ) always clobbers reg byte a 
Statement [11] (byte~) main::$4 ← (byte) $ff - (byte) main::i#2 [ main::buf1#0 main::buf2#0 main::i#2 main::$4 ] ( main:2 [ main::buf1#0 main::buf2#0 main::i#2 main::$4 ] ) always clobbers reg byte a 
Statement [19] *((const byte*) main::screen#0) ← *((byte*)(void*) main::buf1#0) [ main::buf2#0 ] ( main:2 [ main::buf2#0 ] ) always clobbers reg byte a reg byte y 
Statement [20] *((const byte*) main::screen#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) [ ] ( main:2 [ ] ) always clobbers reg byte a reg byte y 
Statement [25] (byte*) malloc::mem#0 ← (byte*) heap_head#7 - (byte) $64 [ malloc::mem#0 ] ( main:2::malloc:5 [ malloc::mem#0 ] main:2::malloc:7 [ main::buf1#0 malloc::mem#0 ] ) always clobbers reg byte a 
Statement [26] (byte*) heap_head#1 ← (byte*) malloc::mem#0 [ malloc::mem#0 heap_head#1 ] ( main:2::malloc:5 [ malloc::mem#0 heap_head#1 ] main:2::malloc:7 [ main::buf1#0 malloc::mem#0 heap_head#1 ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y , 
Potential registers zp ZP_WORD:3 [ heap_head#7 heap_head#1 ] : zp ZP_WORD:3 , 
Potential registers zp ZP_WORD:5 [ main::buf1#0 ] : zp ZP_WORD:5 , 
Potential registers zp ZP_WORD:7 [ main::buf2#0 ] : zp ZP_WORD:7 , 
Potential registers zp ZP_BYTE:9 [ main::$4 ] : zp ZP_BYTE:9 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_WORD:10 [ malloc::mem#0 ] : zp ZP_WORD:10 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 33: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 22: zp ZP_BYTE:9 [ main::$4 ] 0.17: zp ZP_WORD:7 [ main::buf2#0 ] 0.15: zp ZP_WORD:5 [ main::buf1#0 ] 
Uplift Scope [] 5: zp ZP_WORD:3 [ heap_head#7 heap_head#1 ] 
Uplift Scope [malloc] 0.8: zp ZP_WORD:10 [ malloc::mem#0 ] 
Uplift Scope [free] 
Uplift Scope [RADIX] 

Uplifting [main] best 556 combination reg byte y [ main::i#2 main::i#1 ] reg byte a [ main::$4 ] zp ZP_WORD:7 [ main::buf2#0 ] zp ZP_WORD:5 [ main::buf1#0 ] 
Uplifting [] best 556 combination zp ZP_WORD:3 [ heap_head#7 heap_head#1 ] 
Uplifting [malloc] best 556 combination zp ZP_WORD:10 [ malloc::mem#0 ] 
Uplifting [free] best 556 combination 
Uplifting [RADIX] best 556 combination 
Coalescing zero page register [ zp ZP_WORD:7 [ main::buf2#0 ] ] with [ zp ZP_WORD:10 [ malloc::mem#0 ] ] - score: 1
Allocated (was zp ZP_WORD:3) zp ZP_WORD:2 [ heap_head#7 heap_head#1 ]
Allocated (was zp ZP_WORD:5) zp ZP_WORD:4 [ main::buf1#0 ]
Allocated (was zp ZP_WORD:7) zp ZP_WORD:6 [ main::buf2#0 malloc::mem#0 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Experiments with malloc()
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // Top of the heap used by malloc()
  .label HEAP_TOP = $a000
  .label heap_head = 2
  // @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 screen = $400
    .label buf1 = 4
    .label buf2 = 6
    // [5] call malloc 
    // [24] phi from main to malloc [phi:main->malloc]
  malloc_from_main:
    // [24] phi (byte*) heap_head#7 = (const byte*) HEAP_TOP#0 [phi:main->malloc#0] -- pbuz1=pbuc1 
    lda #<HEAP_TOP
    sta.z heap_head
    lda #>HEAP_TOP
    sta.z heap_head+1
    jsr malloc
    jmp b3
    // main::@3
  b3:
    // [6] (void*) main::buf1#0 ← (void*)(byte*) malloc::mem#0 -- pvoz1=pvoz2 
    lda.z malloc.mem
    sta.z buf1
    lda.z malloc.mem+1
    sta.z buf1+1
    // [7] call malloc 
    // [24] phi from main::@3 to malloc [phi:main::@3->malloc]
  malloc_from_b3:
    // [24] phi (byte*) heap_head#7 = (byte*) heap_head#1 [phi:main::@3->malloc#0] -- register_copy 
    jsr malloc
    jmp b4
    // main::@4
  b4:
    // [8] (void*) main::buf2#0 ← (void*)(byte*) malloc::mem#0
    // [9] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
  b1_from_b4:
    // [9] phi (byte) main::i#2 = (byte) 0 [phi:main::@4->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    jmp b1
    // [9] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [9] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [10] *((byte*)(void*) main::buf1#0 + (byte) main::i#2) ← (byte) main::i#2 -- pbuz1_derefidx_vbuyy=vbuyy 
    tya
    sta (buf1),y
    // [11] (byte~) main::$4 ← (byte) $ff - (byte) main::i#2 -- vbuaa=vbuc1_minus_vbuyy 
    tya
    eor #$ff
    clc
    adc #$ff+1
    // [12] *((byte*)(void*) main::buf2#0 + (byte) main::i#2) ← (byte~) main::$4 -- pbuz1_derefidx_vbuyy=vbuaa 
    sta (buf2),y
    // [13] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // [14] if((byte) main::i#1!=(byte) $64) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$64
    bne b1_from_b1
    // [15] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  b2_from_b1:
    jmp b2
    // main::@2
  b2:
    // [16] call free 
    // [22] phi from main::@2 to free [phi:main::@2->free]
  free_from_b2:
    jsr free
    // [17] phi from main::@2 to main::@5 [phi:main::@2->main::@5]
  b5_from_b2:
    jmp b5
    // main::@5
  b5:
    // [18] call free 
    // [22] phi from main::@5 to free [phi:main::@5->free]
  free_from_b5:
    jsr free
    jmp b6
    // main::@6
  b6:
    // [19] *((const byte*) main::screen#0) ← *((byte*)(void*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (buf1),y
    sta screen
    // [20] *((const byte*) main::screen#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (buf2),y
    sta screen+1
    jmp breturn
    // main::@return
  breturn:
    // [21] return 
    rts
}
  // free
// A block of memory previously allocated by a call to malloc is deallocated, making it available again for further allocations.
// If ptr is a null pointer, the function does nothing.
free: {
    jmp breturn
    // free::@return
  breturn:
    // [23] return 
    rts
}
  // malloc
// Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.
// The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.
malloc: {
    .label mem = 6
    // [25] (byte*) malloc::mem#0 ← (byte*) heap_head#7 - (byte) $64 -- pbuz1=pbuz2_minus_vwuc1 
    lda.z heap_head
    sec
    sbc #<$64
    sta.z mem
    lda.z heap_head+1
    sbc #>$64
    sta.z mem+1
    // [26] (byte*) heap_head#1 ← (byte*) malloc::mem#0 -- pbuz1=pbuz2 
    lda.z mem
    sta.z heap_head
    lda.z mem+1
    sta.z heap_head+1
    jmp breturn
    // malloc::@return
  breturn:
    // [27] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b3
Removing instruction jmp b4
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp b5
Removing instruction jmp b6
Removing instruction jmp breturn
Removing instruction jmp breturn
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction ldy #0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b4:
Removing instruction b1_from_b1:
Removing instruction b2_from_b1:
Removing instruction free_from_b2:
Removing instruction b5_from_b2:
Removing instruction free_from_b5:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction malloc_from_main:
Removing instruction b3:
Removing instruction malloc_from_b3:
Removing instruction b4:
Removing instruction b2:
Removing instruction b5:
Removing instruction b6:
Removing instruction breturn:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) HEAP_TOP
(const byte*) HEAP_TOP#0 HEAP_TOP = (byte*) 40960
(const byte) RADIX::BINARY BINARY = (number) 2
(const byte) RADIX::DECIMAL DECIMAL = (number) $a
(const byte) RADIX::HEXADECIMAL HEXADECIMAL = (number) $10
(const byte) RADIX::OCTAL OCTAL = (number) 8
(void()) free((void*) free::ptr)
(label) free::@return
(void*) free::ptr
(byte*) heap_head
(byte*) heap_head#1 heap_head zp ZP_WORD:2 1.0
(byte*) heap_head#7 heap_head zp ZP_WORD:2 4.0
(void()) main()
(byte~) main::$4 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@4
(label) main::@5
(label) main::@6
(label) main::@return
(byte*) main::buf1
(void*) main::buf1#0 buf1 zp ZP_WORD:4 0.15384615384615385
(byte*) main::buf2
(void*) main::buf2#0 buf2 zp ZP_WORD:6 0.16666666666666666
(byte) main::i
(byte) main::i#1 reg byte y 16.5
(byte) main::i#2 reg byte y 16.5
(byte*) main::screen
(const byte*) main::screen#0 screen = (byte*) 1024
(void*()) malloc((word) malloc::size)
(label) malloc::@return
(byte*) malloc::mem
(byte*) malloc::mem#0 mem zp ZP_WORD:6 0.8
(void*) malloc::return
(word) malloc::size

reg byte y [ main::i#2 main::i#1 ]
zp ZP_WORD:2 [ heap_head#7 heap_head#1 ]
zp ZP_WORD:4 [ main::buf1#0 ]
zp ZP_WORD:6 [ main::buf2#0 malloc::mem#0 ]
reg byte a [ main::$4 ]


FINAL ASSEMBLER
Score: 419

  // File Comments
// Experiments with malloc()
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // Top of the heap used by malloc()
  .label HEAP_TOP = $a000
  .label heap_head = 2
  // @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: {
    .label screen = $400
    .label buf1 = 4
    .label buf2 = 6
    // malloc(100)
    // [5] call malloc 
    // [24] phi from main to malloc [phi:main->malloc]
    // [24] phi (byte*) heap_head#7 = (const byte*) HEAP_TOP#0 [phi:main->malloc#0] -- pbuz1=pbuc1 
    lda #<HEAP_TOP
    sta.z heap_head
    lda #>HEAP_TOP
    sta.z heap_head+1
    jsr malloc
    // main::@3
    // malloc(100)
    // [6] (void*) main::buf1#0 ← (void*)(byte*) malloc::mem#0 -- pvoz1=pvoz2 
    lda.z malloc.mem
    sta.z buf1
    lda.z malloc.mem+1
    sta.z buf1+1
    // [7] call malloc 
    // [24] phi from main::@3 to malloc [phi:main::@3->malloc]
    // [24] phi (byte*) heap_head#7 = (byte*) heap_head#1 [phi:main::@3->malloc#0] -- register_copy 
    jsr malloc
    // main::@4
    // malloc(100)
    // [8] (void*) main::buf2#0 ← (void*)(byte*) malloc::mem#0
    // [9] phi from main::@4 to main::@1 [phi:main::@4->main::@1]
    // [9] phi (byte) main::i#2 = (byte) 0 [phi:main::@4->main::@1#0] -- vbuyy=vbuc1 
    ldy #0
    // [9] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [9] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  b1:
    // buf1[i] = i
    // [10] *((byte*)(void*) main::buf1#0 + (byte) main::i#2) ← (byte) main::i#2 -- pbuz1_derefidx_vbuyy=vbuyy 
    tya
    sta (buf1),y
    // 255-i
    // [11] (byte~) main::$4 ← (byte) $ff - (byte) main::i#2 -- vbuaa=vbuc1_minus_vbuyy 
    tya
    eor #$ff
    clc
    adc #$ff+1
    // buf2[i] = 255-i
    // [12] *((byte*)(void*) main::buf2#0 + (byte) main::i#2) ← (byte~) main::$4 -- pbuz1_derefidx_vbuyy=vbuaa 
    sta (buf2),y
    // for(unsigned char i:0..99)
    // [13] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuyy=_inc_vbuyy 
    iny
    // [14] if((byte) main::i#1!=(byte) $64) goto main::@1 -- vbuyy_neq_vbuc1_then_la1 
    cpy #$64
    bne b1
    // [15] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // main::@2
    // free(buf1)
    // [16] call free 
    // [22] phi from main::@2 to free [phi:main::@2->free]
    jsr free
    // [17] phi from main::@2 to main::@5 [phi:main::@2->main::@5]
    // main::@5
    // free(buf2)
    // [18] call free 
    // [22] phi from main::@5 to free [phi:main::@5->free]
    jsr free
    // main::@6
    // screen[0] = *buf1
    // [19] *((const byte*) main::screen#0) ← *((byte*)(void*) main::buf1#0) -- _deref_pbuc1=_deref_pbuz1 
    ldy #0
    lda (buf1),y
    sta screen
    // screen[1] = *buf2
    // [20] *((const byte*) main::screen#0+(byte) 1) ← *((byte*)(void*) main::buf2#0) -- _deref_pbuc1=_deref_pbuz1 
    lda (buf2),y
    sta screen+1
    // main::@return
    // }
    // [21] return 
    rts
}
  // free
// A block of memory previously allocated by a call to malloc is deallocated, making it available again for further allocations.
// If ptr is a null pointer, the function does nothing.
free: {
    // free::@return
    // [23] return 
    rts
}
  // malloc
// Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.
// The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.
malloc: {
    .label mem = 6
    // mem = heap_head-size
    // [25] (byte*) malloc::mem#0 ← (byte*) heap_head#7 - (byte) $64 -- pbuz1=pbuz2_minus_vwuc1 
    lda.z heap_head
    sec
    sbc #<$64
    sta.z mem
    lda.z heap_head+1
    sbc #>$64
    sta.z mem+1
    // heap_head = mem
    // [26] (byte*) heap_head#1 ← (byte*) malloc::mem#0 -- pbuz1=pbuz2 
    lda.z mem
    sta.z heap_head
    lda.z mem+1
    sta.z heap_head+1
    // malloc::@return
    // }
    // [27] return 
    rts
}
  // File Data

