Culled Empty Block (label) main::@4

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

(void()) main()
main: scope:[main]  from @1
  (byte) main::h#0 ← (byte) 0
  to:main::@1
main::@1: scope:[main]  from main main::@3
  (byte) main::h#4 ← phi( main/(byte) main::h#0 main::@3/(byte) main::h#1 )
  (byte) main::l#0 ← (byte) 4
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@2
  (byte) main::l#2 ← phi( main::@1/(byte) main::l#0 main::@2/(byte) main::l#1 )
  (byte) main::h#2 ← phi( main::@1/(byte) main::h#4 main::@2/(byte) main::h#2 )
  (word) main::w#0 ← (word){ *((const byte*) main::his + (byte) main::h#2), (byte) main::l#2 }
  (byte*~) main::$0 ← ((byte*)) (word) main::w#0
  (byte*) main::sc#0 ← (byte*~) main::$0
  *((byte*) main::sc#0) ← (byte) '*'
  (byte) main::l#1 ← (byte) main::l#2 + rangenext(4,7)
  (bool~) main::$1 ← (byte) main::l#1 != rangelast(4,7)
  if((bool~) main::$1) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@2
  (byte) main::h#3 ← phi( main::@2/(byte) main::h#2 )
  (byte) main::h#1 ← (byte) main::h#3 + rangenext(0,2)
  (bool~) main::$2 ← (byte) main::h#1 != rangelast(0,2)
  if((bool~) main::$2) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(void()) main()
(byte*~) main::$0
(bool~) main::$1
(bool~) main::$2
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) main::h
(byte) main::h#0
(byte) main::h#1
(byte) main::h#2
(byte) main::h#3
(byte) main::h#4
(const byte*) main::his[]  = { >(const byte*) SCREEN, >(const byte*) SCREEN+(number) $100, >(const byte*) SCREEN+(number) $200 }
(byte) main::l
(byte) main::l#0
(byte) main::l#1
(byte) main::l#2
(byte*) main::sc
(byte*) main::sc#0
(word) main::w
(word) main::w#0

Fixing inline constructor with main::$3 ← (byte)*(main::his + main::h#2) w= (byte)main::l#2
Successful SSA optimization Pass2FixInlineConstructors
Adding number conversion cast (unumber) $100 in 
Adding number conversion cast (unumber) $200 in 
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*~) main::$0 ← (byte*)(word) main::w#0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $100
Simplifying constant integer cast $200
Simplifying constant integer cast *((const byte*) main::his + (byte) main::h#2)
Simplifying constant integer cast (byte) main::l#2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $100
Finalized unsigned number type (word) $200
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (word) main::w#0 = (word~) main::$3 
Alias (byte*) main::sc#0 = (byte*~) main::$0 
Alias (byte) main::h#2 = (byte) main::h#3 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) main::h#2 (byte) main::h#4
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) main::$1 [11] if((byte) main::l#1!=rangelast(4,7)) goto main::@2
Simple Condition (bool~) main::$2 [15] if((byte) main::h#1!=rangelast(0,2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) main::h#0 = 0
Constant (const byte) main::l#0 = 4
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [9] main::l#1 ← ++ main::l#2 to ++
Resolved ranged comparison value [11] if(main::l#1!=rangelast(4,7)) goto main::@2 to (number) 8
Resolved ranged next value [13] main::h#1 ← ++ main::h#4 to ++
Resolved ranged comparison value [15] if(main::h#1!=rangelast(0,2)) goto main::@1 to (number) 3
Adding number conversion cast (unumber) 8 in if((byte) main::l#1!=(number) 8) goto main::@2
Adding number conversion cast (unumber) 3 in if((byte) main::h#1!=(number) 3) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 8
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 8
Finalized unsigned number type (byte) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining Noop Cast [3] (byte*) main::sc#0 ← (byte*)(word) main::w#0 keeping main::w#0
Successful SSA optimization Pass2NopCastInlining
Inlining constant with var siblings (const byte) main::h#0
Inlining constant with var siblings (const byte) main::l#0
Constant inlined main::l#0 = (byte) 4
Constant inlined main::h#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@5(between main::@3 and main::@1)
Added new block during phi lifting main::@6(between main::@2 and main::@2)
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 @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 

Created 2 initial phi equivalence classes
Coalesced [15] main::h#5 ← main::h#1
Coalesced [16] main::l#3 ← main::l#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@5
Culled Empty Block (label) main::@6
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

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()
  to:main::@1
main::@1: scope:[main]  from main main::@3
  [5] (byte) main::h#4 ← phi( main/(byte) 0 main::@3/(byte) main::h#1 )
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@2
  [6] (byte) main::l#2 ← phi( main::@1/(byte) 4 main::@2/(byte) main::l#1 )
  [7] (word) main::w#0 ← *((const byte*) main::his + (byte) main::h#4) w= (byte) main::l#2
  [8] *((byte*)(word) main::w#0) ← (byte) '*'
  [9] (byte) main::l#1 ← ++ (byte) main::l#2
  [10] if((byte) main::l#1!=(byte) 8) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@2
  [11] (byte) main::h#1 ← ++ (byte) main::h#4
  [12] if((byte) main::h#1!=(byte) 3) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@3
  [13] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::h
(byte) main::h#1 16.5
(byte) main::h#4 20.499999999999996
(byte) main::l
(byte) main::l#1 151.5
(byte) main::l#2 101.0
(byte*) main::sc
(word) main::w
(word) main::w#0 101.0

Initial phi equivalence classes
[ main::h#4 main::h#1 ]
[ main::l#2 main::l#1 ]
Added variable main::w#0 to live range equivalence class [ main::w#0 ]
Complete equivalence classes
[ main::h#4 main::h#1 ]
[ main::l#2 main::l#1 ]
[ main::w#0 ]
Allocated zp[1]:2 [ main::h#4 main::h#1 ]
Allocated zp[1]:3 [ main::l#2 main::l#1 ]
Allocated zp[2]:4 [ main::w#0 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
  // 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: {
    .label w = 4
    .label l = 3
    .label h = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::h#4 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z h
    jmp __b1
  // constant array
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [5] phi (byte) main::h#4 = (byte) main::h#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    // [6] phi (byte) main::l#2 = (byte) 4 [phi:main::@1->main::@2#0] -- vbuz1=vbuc1 
    lda #4
    sta.z l
    jmp __b2
    // [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  __b2_from___b2:
    // [6] phi (byte) main::l#2 = (byte) main::l#1 [phi:main::@2->main::@2#0] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [7] (word) main::w#0 ← *((const byte*) main::his + (byte) main::h#4) w= (byte) main::l#2 -- vwuz1=pbuc1_derefidx_vbuz2_word_vbuz3 
    ldy.z h
    lda his,y
    sta.z w+1
    lda.z l
    sta.z w
    // [8] *((byte*)(word) main::w#0) ← (byte) '*' -- _deref_pbuz1=vbuc1 
    lda #'*'
    ldy #0
    sta (w),y
    // [9] (byte) main::l#1 ← ++ (byte) main::l#2 -- vbuz1=_inc_vbuz1 
    inc.z l
    // [10] if((byte) main::l#1!=(byte) 8) goto main::@2 -- vbuz1_neq_vbuc1_then_la1 
    lda #8
    cmp.z l
    bne __b2_from___b2
    jmp __b3
    // main::@3
  __b3:
    // [11] (byte) main::h#1 ← ++ (byte) main::h#4 -- vbuz1=_inc_vbuz1 
    inc.z h
    // [12] if((byte) main::h#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp.z h
    bne __b1_from___b3
    jmp __breturn
    // main::@return
  __breturn:
    // [13] return 
    rts
    his: .byte >SCREEN, >SCREEN+$100, >SCREEN+$200
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [7] (word) main::w#0 ← *((const byte*) main::his + (byte) main::h#4) w= (byte) main::l#2 [ main::h#4 main::l#2 main::w#0 ] ( main:2 [ main::h#4 main::l#2 main::w#0 ] ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::h#4 main::h#1 ]
Removing always clobbered register reg byte a as potential for zp[1]:3 [ main::l#2 main::l#1 ]
Statement [8] *((byte*)(word) main::w#0) ← (byte) '*' [ main::h#4 main::l#2 ] ( main:2 [ main::h#4 main::l#2 ] ) always clobbers reg byte a reg byte y 
Removing always clobbered register reg byte y as potential for zp[1]:2 [ main::h#4 main::h#1 ]
Removing always clobbered register reg byte y as potential for zp[1]:3 [ main::l#2 main::l#1 ]
Statement [7] (word) main::w#0 ← *((const byte*) main::his + (byte) main::h#4) w= (byte) main::l#2 [ main::h#4 main::l#2 main::w#0 ] ( main:2 [ main::h#4 main::l#2 main::w#0 ] ) always clobbers reg byte a 
Statement [8] *((byte*)(word) main::w#0) ← (byte) '*' [ main::h#4 main::l#2 ] ( main:2 [ main::h#4 main::l#2 ] ) always clobbers reg byte a reg byte y 
Potential registers zp[1]:2 [ main::h#4 main::h#1 ] : zp[1]:2 , reg byte x , 
Potential registers zp[1]:3 [ main::l#2 main::l#1 ] : zp[1]:3 , reg byte x , 
Potential registers zp[2]:4 [ main::w#0 ] : zp[2]:4 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 252.5: zp[1]:3 [ main::l#2 main::l#1 ] 101: zp[2]:4 [ main::w#0 ] 37: zp[1]:2 [ main::h#4 main::h#1 ] 
Uplift Scope [] 

Uplifting [main] best 4383 combination reg byte x [ main::l#2 main::l#1 ] zp[2]:4 [ main::w#0 ] zp[1]:2 [ main::h#4 main::h#1 ] 
Uplifting [] best 4383 combination 
Attempting to uplift remaining variables inzp[1]:2 [ main::h#4 main::h#1 ]
Uplifting [main] best 4383 combination zp[1]:2 [ main::h#4 main::h#1 ] 
Allocated (was zp[2]:4) zp[2]:3 [ main::w#0 ]

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
  // 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: {
    .label w = 3
    .label h = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [5] phi (byte) main::h#4 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z h
    jmp __b1
  // constant array
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
  __b1_from___b3:
    // [5] phi (byte) main::h#4 = (byte) main::h#1 [phi:main::@3->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
  __b2_from___b1:
    // [6] phi (byte) main::l#2 = (byte) 4 [phi:main::@1->main::@2#0] -- vbuxx=vbuc1 
    ldx #4
    jmp __b2
    // [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
  __b2_from___b2:
    // [6] phi (byte) main::l#2 = (byte) main::l#1 [phi:main::@2->main::@2#0] -- register_copy 
    jmp __b2
    // main::@2
  __b2:
    // [7] (word) main::w#0 ← *((const byte*) main::his + (byte) main::h#4) w= (byte) main::l#2 -- vwuz1=pbuc1_derefidx_vbuz2_word_vbuxx 
    ldy.z h
    lda his,y
    sta.z w+1
    stx.z w
    // [8] *((byte*)(word) main::w#0) ← (byte) '*' -- _deref_pbuz1=vbuc1 
    lda #'*'
    ldy #0
    sta (w),y
    // [9] (byte) main::l#1 ← ++ (byte) main::l#2 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::l#1!=(byte) 8) goto main::@2 -- vbuxx_neq_vbuc1_then_la1 
    cpx #8
    bne __b2_from___b2
    jmp __b3
    // main::@3
  __b3:
    // [11] (byte) main::h#1 ← ++ (byte) main::h#4 -- vbuz1=_inc_vbuz1 
    inc.z h
    // [12] if((byte) main::h#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp.z h
    bne __b1_from___b3
    jmp __breturn
    // main::@return
  __breturn:
    // [13] return 
    rts
    his: .byte >SCREEN, >SCREEN+$100, >SCREEN+$200
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __b3
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Replacing label __b2_from___b2 with __b2
Replacing label __b1_from___b3 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction main_from___b1:
Removing instruction __bend_from___b1:
Removing instruction __b1_from___b3:
Removing instruction __b2_from___b1:
Removing instruction __b2_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1_from_main:
Removing instruction __b3:
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
Removing instruction jmp __b2
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*) 1024
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@3
(label) main::@return
(byte) main::h
(byte) main::h#1 h zp[1]:2 16.5
(byte) main::h#4 h zp[1]:2 20.499999999999996
(const byte*) main::his[]  = { >(const byte*) SCREEN, >(const byte*) SCREEN+(word) $100, >(const byte*) SCREEN+(word) $200 }
(byte) main::l
(byte) main::l#1 reg byte x 151.5
(byte) main::l#2 reg byte x 101.0
(byte*) main::sc
(word) main::w
(word) main::w#0 w zp[2]:3 101.0

zp[1]:2 [ main::h#4 main::h#1 ]
reg byte x [ main::l#2 main::l#1 ]
zp[2]:3 [ main::w#0 ]


FINAL ASSEMBLER
Score: 3381

  // File Comments
  // 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: {
    .label w = 3
    .label h = 2
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (byte) main::h#4 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z h
  // constant array
    // [5] phi from main::@3 to main::@1 [phi:main::@3->main::@1]
    // [5] phi (byte) main::h#4 = (byte) main::h#1 [phi:main::@3->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // [6] phi from main::@1 to main::@2 [phi:main::@1->main::@2]
    // [6] phi (byte) main::l#2 = (byte) 4 [phi:main::@1->main::@2#0] -- vbuxx=vbuc1 
    ldx #4
    // [6] phi from main::@2 to main::@2 [phi:main::@2->main::@2]
    // [6] phi (byte) main::l#2 = (byte) main::l#1 [phi:main::@2->main::@2#0] -- register_copy 
    // main::@2
  __b2:
    // w = { his[h], l }
    // [7] (word) main::w#0 ← *((const byte*) main::his + (byte) main::h#4) w= (byte) main::l#2 -- vwuz1=pbuc1_derefidx_vbuz2_word_vbuxx 
    ldy.z h
    lda his,y
    sta.z w+1
    stx.z w
    // *sc = '*'
    // [8] *((byte*)(word) main::w#0) ← (byte) '*' -- _deref_pbuz1=vbuc1 
    lda #'*'
    ldy #0
    sta (w),y
    // for (byte l: 4..7)
    // [9] (byte) main::l#1 ← ++ (byte) main::l#2 -- vbuxx=_inc_vbuxx 
    inx
    // [10] if((byte) main::l#1!=(byte) 8) goto main::@2 -- vbuxx_neq_vbuc1_then_la1 
    cpx #8
    bne __b2
    // main::@3
    // for( byte h: 0..2)
    // [11] (byte) main::h#1 ← ++ (byte) main::h#4 -- vbuz1=_inc_vbuz1 
    inc.z h
    // [12] if((byte) main::h#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #3
    cmp.z h
    bne __b1
    // main::@return
    // }
    // [13] return 
    rts
    his: .byte >SCREEN, >SCREEN+$100, >SCREEN+$200
}
  // File Data

