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
  (byte*) SCREEN#0 ← ((byte*)) (number) $400
  to:@3
main: scope:[main]  from @3
  *((byte*) SCREEN#0) ← (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
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
d: scope:[d]  from b::@1 main
  *((byte*) SCREEN#0) ← ++ *((byte*) SCREEN#0)
  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
(byte*) SCREEN
(byte*) SCREEN#0
(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

Inlining cast (byte*) SCREEN#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
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 [11] if((byte) b::i#1!=rangelast(0,3)) goto b::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) SCREEN#0 = (byte*) 1024
Constant (const byte) b::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [9] b::i#1 ← ++ b::i#2 to ++
Resolved ranged comparison value [11] 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()
main: scope:[main]  from @1
  [4] *((const byte*) SCREEN#0) ← (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
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
d: scope:[d]  from b::@1 main
  [15] *((const byte*) SCREEN#0) ← ++ *((const byte*) SCREEN#0)
  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
(byte*) SCREEN
(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 ZP_BYTE:2 [ b::i#2 b::i#1 ]

INITIAL ASM
Target platform is c64basic
  // 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#0) ← (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#0) ← ++ *((const byte*) SCREEN#0) -- _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#0) ← (byte) '0' [ ] ( main:2 [ ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ b::i#2 b::i#1 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [b] 27.5: zp ZP_BYTE: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#0) ← (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#0) ← ++ *((const byte*) SCREEN#0) -- _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 b1_from_b2 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
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 bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) SCREEN
(const byte*) SCREEN#0 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#0) ← (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#0) ← ++ *((const byte*) SCREEN#0) -- _deref_pbuc1=_inc__deref_pbuc1 
    inc SCREEN
    // d::@return
    // }
    // [16] return 
    rts
}
  // File Data

