Identified constant variable (byte*) SCREEN
Culled Empty Block (label) @1
Culled Empty Block (label) b::@2
Culled Empty Block (label) @2

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

(void()) main()
main: scope:[main]  from @3
  *((const byte*) SCREEN) ← (byte) '0'
  call d 
  to:main::@1
main::@1: scope:[main]  from main
  call b 
  to:main::@2
main::@2: scope:[main]  from main::@1
  to:main::@return
main::@return: scope:[main]  from main::@2
  return 
  to:@return

(void()) b()
b: scope:[b]  from main::@1
  (byte) b::i#0 ← (byte) 0
  to:b::@1
b::@1: scope:[b]  from b b::@3
  (byte) b::i#3 ← phi( b/(byte) b::i#0 b::@3/(byte) b::i#1 )
  call d 
  to:b::@3
b::@3: scope:[b]  from b::@1
  (byte) b::i#2 ← phi( b::@1/(byte) b::i#3 )
  (byte) b::i#1 ← (byte) b::i#2 + rangenext(0,3)
  (bool~) b::$1 ← (byte) b::i#1 != rangelast(0,3)
  if((bool~) b::$1) goto b::@1
  to:b::@return
b::@return: scope:[b]  from b::@3
  return 
  to:@return

(void()) d()
d: scope:[d]  from b::@1 main
  *((const byte*) SCREEN) ← ++ *((const byte*) SCREEN)
  to:d::@return
d::@return: scope:[d]  from d
  return 
  to:@return
@3: scope:[]  from @begin
  call main 
  to:@4
@4: scope:[]  from @3
  to:@end
@end: scope:[]  from @4

SYMBOL TABLE SSA
(label) @3
(label) @4
(label) @begin
(label) @end
(const byte*) SCREEN = (byte*)(number) $400
(void()) b()
(bool~) b::$1
(label) b::@1
(label) b::@3
(label) b::@return
(byte) b::i
(byte) b::i#0
(byte) b::i#1
(byte) b::i#2
(byte) b::i#3
(void()) d()
(label) d::@return
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return

Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Alias (byte) b::i#2 = (byte) b::i#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition (bool~) b::$1 [10] if((byte) b::i#1!=rangelast(0,3)) goto b::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte) b::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [8] b::i#1 ← ++ b::i#2 to ++
Resolved ranged comparison value [10] if(b::i#1!=rangelast(0,3)) goto b::@1 to (number) 4
Adding number conversion cast (unumber) 4 in if((byte) b::i#1!=(number) 4) goto b::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 4
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) b::i#0
Constant inlined b::i#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting b::@4(between b::@3 and b::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @3
Adding NOP phi() at start of @4
Adding NOP phi() at start of @end
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of main::@2
Adding NOP phi() at start of b
CALL GRAPH
Calls in [] to main:2 
Calls in [main] to d:6 b:8 
Calls in [b] to d:13 

Created 1 initial phi equivalence classes
Coalesced [17] b::i#4 ← b::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block (label) @4
Culled Empty Block (label) main::@2
Culled Empty Block (label) b::@4
Renumbering block @3 to @1
Renumbering block b::@3 to b::@2
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::@1
Adding NOP phi() at start of b

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] *((const byte*) SCREEN) ← (byte) '0'
  [5] call d 
  to:main::@1
main::@1: scope:[main]  from main
  [6] phi()
  [7] call b 
  to:main::@return
main::@return: scope:[main]  from main::@1
  [8] return 
  to:@return

(void()) b()
b: scope:[b]  from main::@1
  [9] phi()
  to:b::@1
b::@1: scope:[b]  from b b::@2
  [10] (byte) b::i#2 ← phi( b/(byte) 0 b::@2/(byte) b::i#1 )
  [11] call d 
  to:b::@2
b::@2: scope:[b]  from b::@1
  [12] (byte) b::i#1 ← ++ (byte) b::i#2
  [13] if((byte) b::i#1!=(byte) 4) goto b::@1
  to:b::@return
b::@return: scope:[b]  from b::@2
  [14] return 
  to:@return

(void()) d()
d: scope:[d]  from b::@1 main
  [15] *((const byte*) SCREEN) ← ++ *((const byte*) SCREEN)
  to:d::@return
d::@return: scope:[d]  from d
  [16] return 
  to:@return

null depth in calling loop Loop head: b::@1 tails: b::@2 blocks: b::@2 b::@1  in scope d

VARIABLE REGISTER WEIGHTS
(void()) b()
(byte) b::i
(byte) b::i#1 16.5
(byte) b::i#2 11.0
(void()) d()
(void()) main()

Initial phi equivalence classes
[ b::i#2 b::i#1 ]
Complete equivalence classes
[ b::i#2 b::i#1 ]
Allocated zp[1]:2 [ b::i#2 b::i#1 ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// A simple loop results in NullPointerException during loop analysis
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // [4] *((const byte*) SCREEN) ← (byte) '0' -- _deref_pbuc1=vbuc2 
    lda #'0'
    sta SCREEN
    // [5] call d 
    jsr d
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call b 
    // [9] phi from main::@1 to b [phi:main::@1->b]
  b_from___b1:
    jsr b
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // b
b: {
    .label i = 2
    // [10] phi from b to b::@1 [phi:b->b::@1]
  __b1_from_b:
    // [10] phi (byte) b::i#2 = (byte) 0 [phi:b->b::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z i
    jmp __b1
    // [10] phi from b::@2 to b::@1 [phi:b::@2->b::@1]
  __b1_from___b2:
    // [10] phi (byte) b::i#2 = (byte) b::i#1 [phi:b::@2->b::@1#0] -- register_copy 
    jmp __b1
    // b::@1
  __b1:
    // [11] call d 
    jsr d
    jmp __b2
    // b::@2
  __b2:
    // [12] (byte) b::i#1 ← ++ (byte) b::i#2 -- vbuz1=_inc_vbuz1 
    inc.z i
    // [13] if((byte) b::i#1!=(byte) 4) goto b::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #4
    cmp.z i
    bne __b1_from___b2
    jmp __breturn
    // b::@return
  __breturn:
    // [14] return 
    rts
}
  // d
d: {
    // [15] *((const byte*) SCREEN) ← ++ *((const byte*) SCREEN) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc SCREEN
    jmp __breturn
    // d::@return
  __breturn:
    // [16] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) SCREEN) ← (byte) '0' [ ] ( main:2 [ ] ) always clobbers reg byte a 
Potential registers zp[1]:2 [ b::i#2 b::i#1 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [b] 27.5: zp[1]:2 [ b::i#2 b::i#1 ] 
Uplift Scope [main] 
Uplift Scope [d] 
Uplift Scope [] 

Uplifting [b] best 328 combination reg byte x [ b::i#2 b::i#1 ] 
Uplifting [main] best 328 combination 
Uplifting [d] best 328 combination 
Uplifting [] best 328 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// A simple loop results in NullPointerException during loop analysis
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    // [4] *((const byte*) SCREEN) ← (byte) '0' -- _deref_pbuc1=vbuc2 
    lda #'0'
    sta SCREEN
    // [5] call d 
    jsr d
    // [6] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [7] call b 
    // [9] phi from main::@1 to b [phi:main::@1->b]
  b_from___b1:
    jsr b
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // b
b: {
    // [10] phi from b to b::@1 [phi:b->b::@1]
  __b1_from_b:
    // [10] phi (byte) b::i#2 = (byte) 0 [phi:b->b::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [10] phi from b::@2 to b::@1 [phi:b::@2->b::@1]
  __b1_from___b2:
    // [10] phi (byte) b::i#2 = (byte) b::i#1 [phi:b::@2->b::@1#0] -- register_copy 
    jmp __b1
    // b::@1
  __b1:
    // [11] call d 
    jsr d
    jmp __b2
    // b::@2
  __b2:
    // [12] (byte) b::i#1 ← ++ (byte) b::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if((byte) b::i#1!=(byte) 4) goto b::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #4
    bne __b1_from___b2
    jmp __breturn
    // b::@return
  __breturn:
    // [14] return 
    rts
}
  // d
d: {
    // [15] *((const byte*) SCREEN) ← ++ *((const byte*) SCREEN) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc SCREEN
    jmp __breturn
    // d::@return
  __breturn:
    // [16] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b1
Removing instruction jmp __breturn
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
Replacing label __b1_from___b2 with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Removing instruction __b1_from_main:
Removing instruction b_from___b1:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __b1_from_b:
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 jmp __b1
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()) b()
(label) b::@1
(label) b::@2
(label) b::@return
(byte) b::i
(byte) b::i#1 reg byte x 16.5
(byte) b::i#2 reg byte x 11.0
(void()) d()
(label) d::@return
(void()) main()
(label) main::@1
(label) main::@return

reg byte x [ b::i#2 b::i#1 ]


FINAL ASSEMBLER
Score: 187

  // File Comments
// A simple loop results in NullPointerException during loop analysis
  // 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 
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    // *SCREEN = '0'
    // [4] *((const byte*) SCREEN) ← (byte) '0' -- _deref_pbuc1=vbuc2 
    lda #'0'
    sta SCREEN
    // d()
    // [5] call d 
    jsr d
    // [6] phi from main to main::@1 [phi:main->main::@1]
    // main::@1
    // b()
    // [7] call b 
    // [9] phi from main::@1 to b [phi:main::@1->b]
    jsr b
    // main::@return
    // }
    // [8] return 
    rts
}
  // b
b: {
    // [10] phi from b to b::@1 [phi:b->b::@1]
    // [10] phi (byte) b::i#2 = (byte) 0 [phi:b->b::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [10] phi from b::@2 to b::@1 [phi:b::@2->b::@1]
    // [10] phi (byte) b::i#2 = (byte) b::i#1 [phi:b::@2->b::@1#0] -- register_copy 
    // b::@1
  __b1:
    // d()
    // [11] call d 
    jsr d
    // b::@2
    // for( byte i: 0..3)
    // [12] (byte) b::i#1 ← ++ (byte) b::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if((byte) b::i#1!=(byte) 4) goto b::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #4
    bne __b1
    // b::@return
    // }
    // [14] return 
    rts
}
  // d
d: {
    // (*SCREEN)++;
    // [15] *((const byte*) SCREEN) ← ++ *((const byte*) SCREEN) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc SCREEN
    // d::@return
    // }
    // [16] return 
    rts
}
  // File Data

