Fixing pointer array-indexing *((const word*) SCREEN + (byte) idx)
Identified constant variable (word) main::w

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

(void()) main()
main: scope:[main]  from @2
  (byte) idx#15 ← phi( @2/(byte) idx#16 )
  (word) print::w#0 ← (number) $1234
  call print 
  to:main::@1
main::@1: scope:[main]  from main
  (byte) idx#8 ← phi( main/(byte) idx#6 )
  (byte) idx#0 ← (byte) idx#8
  (word) print::w#1 ← (const word) main::w
  call print 
  to:main::@2
main::@2: scope:[main]  from main::@1
  (byte) idx#9 ← phi( main::@1/(byte) idx#6 )
  (byte) idx#1 ← (byte) idx#9
  (word) print::w#2 ← (word){ (number) $12, (number) $34 }
  call print 
  to:main::@3
main::@3: scope:[main]  from main::@2
  (byte) idx#10 ← phi( main::@2/(byte) idx#6 )
  (byte) idx#2 ← (byte) idx#10
  to:main::@return
main::@return: scope:[main]  from main::@3
  (byte) idx#11 ← phi( main::@3/(byte) idx#2 )
  (byte) idx#3 ← (byte) idx#11
  return 
  to:@return
@1: scope:[]  from @begin
  (byte) idx#4 ← (byte) 0
  to:@2

(void()) print((word) print::w)
print: scope:[print]  from main main::@1 main::@2
  (word) print::w#3 ← phi( main/(word) print::w#0 main::@1/(word) print::w#1 main::@2/(word) print::w#2 )
  (byte) idx#12 ← phi( main/(byte) idx#15 main::@1/(byte) idx#0 main::@2/(byte) idx#1 )
  (byte~) print::$0 ← (byte) idx#12 * (const byte) SIZEOF_WORD
  *((const word*) SCREEN + (byte~) print::$0) ← (word) print::w#3
  (byte) idx#5 ← ++ (byte) idx#12
  to:print::@return
print::@return: scope:[print]  from print
  (byte) idx#13 ← phi( print/(byte) idx#5 )
  (byte) idx#6 ← (byte) idx#13
  return 
  to:@return
@2: scope:[]  from @1
  (byte) idx#16 ← phi( @1/(byte) idx#4 )
  call main 
  to:@3
@3: scope:[]  from @2
  (byte) idx#14 ← phi( @2/(byte) idx#3 )
  (byte) idx#7 ← (byte) idx#14
  to:@end
@end: scope:[]  from @3

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @3
(label) @begin
(label) @end
(const word*) SCREEN = (word*)(number) $400
(const byte) SIZEOF_WORD = (byte) 2
(byte) idx
(byte) idx#0
(byte) idx#1
(byte) idx#10
(byte) idx#11
(byte) idx#12
(byte) idx#13
(byte) idx#14
(byte) idx#15
(byte) idx#16
(byte) idx#2
(byte) idx#3
(byte) idx#4
(byte) idx#5
(byte) idx#6
(byte) idx#7
(byte) idx#8
(byte) idx#9
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(const word) main::w = (word) $1234
(void()) print((word) print::w)
(byte~) print::$0
(label) print::@return
(word) print::w
(word) print::w#0
(word) print::w#1
(word) print::w#2
(word) print::w#3

Fixing inline constructor with main::$3 ← (byte)$12 w= (byte)$34
Successful SSA optimization Pass2FixInlineConstructors
Adding number conversion cast (unumber) $1234 in (word) print::w#0 ← (number) $1234
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (word) print::w#0 ← (unumber)(number) $1234
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (word*) 1024
Simplifying constant integer cast $1234
Simplifying constant integer cast $12
Simplifying constant integer cast $34
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $1234
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) idx#0 = (byte) idx#8 
Alias (byte) idx#1 = (byte) idx#9 
Alias (word) print::w#2 = (word~) main::$3 
Alias (byte) idx#10 = (byte) idx#2 (byte) idx#11 (byte) idx#3 
Alias (byte) idx#13 = (byte) idx#5 (byte) idx#6 
Alias (byte) idx#16 = (byte) idx#4 
Alias (byte) idx#14 = (byte) idx#7 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) idx#15 (byte) idx#16
Identical Phi Values (byte) idx#0 (byte) idx#13
Identical Phi Values (byte) idx#1 (byte) idx#13
Identical Phi Values (byte) idx#10 (byte) idx#13
Identical Phi Values (byte) idx#14 (byte) idx#10
Successful SSA optimization Pass2IdenticalPhiElimination
Constant right-side identified [7] (word) print::w#2 ← (byte) $12 w= (byte) $34
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const word) print::w#0 = $1234
Constant (const word) print::w#1 = main::w
Constant (const byte) idx#16 = 0
Successful SSA optimization Pass2ConstantIdentification
Adding number conversion cast (unumber) $12*$100+$34 in (word) print::w#2 ← (byte) $12*(number) $100+(byte) $34
Adding number conversion cast (unumber) $12*$100 in (word) print::w#2 ← ((unumber)) (byte) $12*(number) $100+(byte) $34
Adding number conversion cast (unumber) $100 in (word) print::w#2 ← ((unumber)) (unumber)(byte) $12*(number) $100+(byte) $34
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (word) print::w#2 ← (unumber)(unumber)(byte) $12*(unumber)(number) $100+(byte) $34
Successful SSA optimization Pass2InlineCast
Simplifying constant integer cast (unumber)(byte) $12*(unumber)(number) $100+(byte) $34
Simplifying constant integer cast (byte) $12*(unumber)(number) $100
Simplifying constant integer cast $100
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $100
Successful SSA optimization PassNFinalizeNumberTypeConversions
Constant (const word) print::w#2 = $12*$100+$34
Successful SSA optimization Pass2ConstantIdentification
Rewriting multiplication to use shift [5] (byte~) print::$0 ← (byte) idx#12 * (const byte) SIZEOF_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const word) print::w#0
Inlining constant with var siblings (const word) print::w#1
Inlining constant with var siblings (const word) print::w#2
Inlining constant with var siblings (const byte) idx#16
Constant inlined print::w#2 = (byte) $12*(word) $100+(byte) $34
Constant inlined print::w#1 = (const word) main::w
Constant inlined print::w#0 = (word) $1234
Constant inlined idx#16 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant (const byte) SIZEOF_WORD
Successful SSA optimization PassNEliminateUnusedVars
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
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
Adding NOP phi() at start of main::@3
CALL GRAPH
Calls in [] to main:3 
Calls in [main] to print:7 print:9 print:11 

Created 2 initial phi equivalence classes
Coalesced [8] idx#17 ← idx#13
Coalesced (already) [10] idx#18 ← idx#13
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @1
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
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@2

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] call print 
  to:main::@1
main::@1: scope:[main]  from main
  [6] phi()
  [7] call print 
  to:main::@2
main::@2: scope:[main]  from main::@1
  [8] phi()
  [9] call print 
  to:main::@return
main::@return: scope:[main]  from main::@2
  [10] return 
  to:@return

(void()) print((word) print::w)
print: scope:[print]  from main main::@1 main::@2
  [11] (word) print::w#3 ← phi( main/(word) $1234 main::@1/(const word) main::w main::@2/(byte) $12*(word) $100+(byte) $34 )
  [11] (byte) idx#12 ← phi( main/(byte) 0 main::@1/(byte) idx#13 main::@2/(byte) idx#13 )
  [12] (byte~) print::$0 ← (byte) idx#12 << (byte) 1
  [13] *((const word*) SCREEN + (byte~) print::$0) ← (word) print::w#3
  [14] (byte) idx#13 ← ++ (byte) idx#12
  to:print::@return
print::@return: scope:[print]  from print
  [15] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) idx
(byte) idx#12 2.6666666666666665
(byte) idx#13 1.0
(void()) main()
(void()) print((word) print::w)
(byte~) print::$0 4.0
(word) print::w
(word) print::w#3 1.0

Initial phi equivalence classes
[ idx#12 idx#13 ]
[ print::w#3 ]
Added variable print::$0 to live range equivalence class [ print::$0 ]
Complete equivalence classes
[ idx#12 idx#13 ]
[ print::w#3 ]
[ print::$0 ]
Allocated zp[1]:2 [ idx#12 idx#13 ]
Allocated zp[2]:3 [ print::w#3 ]
Allocated zp[1]:5 [ print::$0 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test auto-casting of call-parameters
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  .label idx = 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: {
    .const w = $1234
    // [5] call print 
    // [11] phi from main to print [phi:main->print]
  print_from_main:
    // [11] phi (word) print::w#3 = (word) $1234 [phi:main->print#0] -- vwuz1=vwuc1 
    lda #<$1234
    sta.z print.w
    lda #>$1234
    sta.z print.w+1
    // [11] phi (byte) idx#12 = (byte) 0 [phi:main->print#1] -- vbuz1=vbuc1 
    lda #0
    sta.z idx
    jsr print
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call print 
    // [11] phi from main::@1 to print [phi:main::@1->print]
  print_from___b1:
    // [11] phi (word) print::w#3 = (const word) main::w [phi:main::@1->print#0] -- vwuz1=vwuc1 
    lda #<w
    sta.z print.w
    lda #>w
    sta.z print.w+1
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@1->print#1] -- register_copy 
    jsr print
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [9] call print 
    // [11] phi from main::@2 to print [phi:main::@2->print]
  print_from___b2:
    // [11] phi (word) print::w#3 = (byte) $12*(word) $100+(byte) $34 [phi:main::@2->print#0] -- vwuz1=vwuc1 
    lda #<$12*$100+$34
    sta.z print.w
    lda #>$12*$100+$34
    sta.z print.w+1
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@2->print#1] -- register_copy 
    jsr print
    jmp __breturn
    // main::@return
  __breturn:
    // [10] return 
    rts
}
  // print
// print(word zp(3) w)
print: {
    .label __0 = 5
    .label w = 3
    // [12] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 -- vbuz1=vbuz2_rol_1 
    lda.z idx
    asl
    sta.z __0
    // [13] *((const word*) SCREEN + (byte~) print::$0) ← (word) print::w#3 -- pwuc1_derefidx_vbuz1=vwuz2 
    ldy.z __0
    lda.z w
    sta SCREEN,y
    lda.z w+1
    sta SCREEN+1,y
    // [14] (byte) idx#13 ← ++ (byte) idx#12 -- vbuz1=_inc_vbuz1 
    inc.z idx
    jmp __breturn
    // print::@return
  __breturn:
    // [15] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [12] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 [ idx#12 print::w#3 print::$0 ] ( main:2::print:5 [ idx#12 print::w#3 print::$0 ] main:2::print:7 [ idx#12 print::w#3 print::$0 ] main:2::print:9 [ idx#12 print::w#3 print::$0 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ idx#12 idx#13 ]
Statement [13] *((const word*) SCREEN + (byte~) print::$0) ← (word) print::w#3 [ idx#12 ] ( main:2::print:5 [ idx#12 ] main:2::print:7 [ idx#12 ] main:2::print:9 [ idx#12 ] ) always clobbers reg byte a 
Statement [12] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 [ idx#12 print::w#3 print::$0 ] ( main:2::print:5 [ idx#12 print::w#3 print::$0 ] main:2::print:7 [ idx#12 print::w#3 print::$0 ] main:2::print:9 [ idx#12 print::w#3 print::$0 ] ) always clobbers reg byte a 
Statement [13] *((const word*) SCREEN + (byte~) print::$0) ← (word) print::w#3 [ idx#12 ] ( main:2::print:5 [ idx#12 ] main:2::print:7 [ idx#12 ] main:2::print:9 [ idx#12 ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ idx#12 idx#13 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[2]:3 [ print::w#3 ] : zp[2]:3 , 
Potential registers zp[1]:5 [ print::$0 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [print] 4: zp[1]:5 [ print::$0 ] 1: zp[2]:3 [ print::w#3 ] 
Uplift Scope [] 3.67: zp[1]:2 [ idx#12 idx#13 ] 
Uplift Scope [main] 

Uplifting [print] best 117 combination reg byte a [ print::$0 ] zp[2]:3 [ print::w#3 ] 
Uplifting [] best 110 combination reg byte x [ idx#12 idx#13 ] 
Uplifting [main] best 110 combination 
Allocated (was zp[2]:3) zp[2]:2 [ print::w#3 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test auto-casting of call-parameters
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(__bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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: {
    .const w = $1234
    // [5] call print 
    // [11] phi from main to print [phi:main->print]
  print_from_main:
    // [11] phi (word) print::w#3 = (word) $1234 [phi:main->print#0] -- vwuz1=vwuc1 
    lda #<$1234
    sta.z print.w
    lda #>$1234
    sta.z print.w+1
    // [11] phi (byte) idx#12 = (byte) 0 [phi:main->print#1] -- vbuxx=vbuc1 
    ldx #0
    jsr print
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call print 
    // [11] phi from main::@1 to print [phi:main::@1->print]
  print_from___b1:
    // [11] phi (word) print::w#3 = (const word) main::w [phi:main::@1->print#0] -- vwuz1=vwuc1 
    lda #<w
    sta.z print.w
    lda #>w
    sta.z print.w+1
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@1->print#1] -- register_copy 
    jsr print
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    jmp __b2
    // main::@2
  __b2:
    // [9] call print 
    // [11] phi from main::@2 to print [phi:main::@2->print]
  print_from___b2:
    // [11] phi (word) print::w#3 = (byte) $12*(word) $100+(byte) $34 [phi:main::@2->print#0] -- vwuz1=vwuc1 
    lda #<$12*$100+$34
    sta.z print.w
    lda #>$12*$100+$34
    sta.z print.w+1
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@2->print#1] -- register_copy 
    jsr print
    jmp __breturn
    // main::@return
  __breturn:
    // [10] return 
    rts
}
  // print
// print(word zp(2) w)
print: {
    .label w = 2
    // [12] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [13] *((const word*) SCREEN + (byte~) print::$0) ← (word) print::w#3 -- pwuc1_derefidx_vbuaa=vwuz1 
    tay
    lda.z w
    sta SCREEN,y
    lda.z w+1
    sta SCREEN+1,y
    // [14] (byte) idx#13 ← ++ (byte) idx#12 -- vbuxx=_inc_vbuxx 
    inx
    jmp __breturn
    // print::@return
  __breturn:
    // [15] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
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:
Removing instruction __b1_from_main:
Removing instruction print_from___b1:
Removing instruction __b2_from___b1:
Removing instruction print_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction print_from_main:
Removing instruction __b1:
Removing instruction __b2:
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 word*) SCREEN = (word*) 1024
(byte) idx
(byte) idx#12 reg byte x 2.6666666666666665
(byte) idx#13 reg byte x 1.0
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(const word) main::w = (word) $1234
(void()) print((word) print::w)
(byte~) print::$0 reg byte a 4.0
(label) print::@return
(word) print::w
(word) print::w#3 w zp[2]:2 1.0

reg byte x [ idx#12 idx#13 ]
zp[2]:2 [ print::w#3 ]
reg byte a [ print::$0 ]


FINAL ASSEMBLER
Score: 86

  // File Comments
// Test auto-casting of call-parameters
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label SCREEN = $400
  // @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: {
    .const w = $1234
    // print(0x1234)
    // [5] call print 
    // [11] phi from main to print [phi:main->print]
    // [11] phi (word) print::w#3 = (word) $1234 [phi:main->print#0] -- vwuz1=vwuc1 
    lda #<$1234
    sta.z print.w
    lda #>$1234
    sta.z print.w+1
    // [11] phi (byte) idx#12 = (byte) 0 [phi:main->print#1] -- vbuxx=vbuc1 
    ldx #0
    jsr print
    // [6] phi from main to main::@1 [phi:main->main::@1]
    // main::@1
    // print(w)
    // [7] call print 
    // [11] phi from main::@1 to print [phi:main::@1->print]
    // [11] phi (word) print::w#3 = (const word) main::w [phi:main::@1->print#0] -- vwuz1=vwuc1 
    lda #<w
    sta.z print.w
    lda #>w
    sta.z print.w+1
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@1->print#1] -- register_copy 
    jsr print
    // [8] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // main::@2
    // print( {0x12,0x34} )
    // [9] call print 
    // [11] phi from main::@2 to print [phi:main::@2->print]
    // [11] phi (word) print::w#3 = (byte) $12*(word) $100+(byte) $34 [phi:main::@2->print#0] -- vwuz1=vwuc1 
    lda #<$12*$100+$34
    sta.z print.w
    lda #>$12*$100+$34
    sta.z print.w+1
    // [11] phi (byte) idx#12 = (byte) idx#13 [phi:main::@2->print#1] -- register_copy 
    jsr print
    // main::@return
    // }
    // [10] return 
    rts
}
  // print
// print(word zp(2) w)
print: {
    .label w = 2
    // SCREEN[idx++] = w
    // [12] (byte~) print::$0 ← (byte) idx#12 << (byte) 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [13] *((const word*) SCREEN + (byte~) print::$0) ← (word) print::w#3 -- pwuc1_derefidx_vbuaa=vwuz1 
    tay
    lda.z w
    sta SCREEN,y
    lda.z w+1
    sta SCREEN+1,y
    // SCREEN[idx++] = w;
    // [14] (byte) idx#13 ← ++ (byte) idx#12 -- vbuxx=_inc_vbuxx 
    inx
    // print::@return
    // }
    // [15] return 
    rts
}
  // File Data

