Inlined call call __init

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start::@1
  *SCREEN = '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
  b::i#0 = 0
  to:b::@1
b::@1: scope:[b]  from b b::@2
  b::i#3 = phi( b/b::i#0, b::@2/b::i#1 )
  call d
  to:b::@2
b::@2: scope:[b]  from b::@1
  b::i#2 = phi( b::@1/b::i#3 )
  b::i#1 = b::i#2 + rangenext(0,3)
  b::$1 = b::i#1 != rangelast(0,3)
  if(b::$1) goto b::@1
  to:b::@return
b::@return: scope:[b]  from b::@2
  return 
  to:@return

void d()
d: scope:[d]  from b::@1 main
  *SCREEN = ++ *SCREEN
  to:d::@return
d::@return: scope:[d]  from d
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  to:__start::__init1
__start::__init1: scope:[__start]  from __start
  to:__start::@1
__start::@1: scope:[__start]  from __start::__init1
  call main
  to:__start::@2
__start::@2: scope:[__start]  from __start::@1
  to:__start::@return
__start::@return: scope:[__start]  from __start::@2
  return 
  to:@return

SYMBOL TABLE SSA
__constant char *SCREEN = (char *)$400
void __start()
void b()
bool b::$1
char b::i
char b::i#0
char b::i#1
char b::i#2
char b::i#3
void d()
void main()

Simplifying constant pointer cast (char *) 1024
Successful SSA optimization PassNCastSimplification
Alias b::i#2 = b::i#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition b::$1 [9] if(b::i#1!=rangelast(0,3)) goto b::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant b::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [7] b::i#1 = ++ b::i#2 to ++
Resolved ranged comparison value [9] if(b::i#1!=rangelast(0,3)) goto b::@1 to 4
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::__init1
Removing unused procedure block __start::@1
Removing unused procedure block __start::@2
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Adding number conversion cast (unumber) 4 in [7] if(b::i#1!=4) goto b::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 4
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 4
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings b::i#0
Constant inlined b::i#0 = 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting b::@3(between b::@2 and b::@1)
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 [main] to d:1 b:3 
Calls in [b] to d:10 

Created 1 initial phi equivalence classes
Coalesced [14] b::i#4 = b::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block label main::@2
Culled Empty Block label b::@3
Adding NOP phi() at start of main::@1
Adding NOP phi() at start of b

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] *SCREEN = '0'
  [1] call d
  to:main::@1
main::@1: scope:[main]  from main
  [2] phi()
  [3] call b
  to:main::@return
main::@return: scope:[main]  from main::@1
  [4] return 
  to:@return

void d()
d: scope:[d]  from b::@1 main
  [5] *SCREEN = ++ *SCREEN
  to:d::@return
d::@return: scope:[d]  from d
  [6] return 
  to:@return

void b()
b: scope:[b]  from main::@1
  [7] phi()
  to:b::@1
b::@1: scope:[b]  from b b::@2
  [8] b::i#2 = phi( b/0, b::@2/b::i#1 )
  [9] call d
  to:b::@2
b::@2: scope:[b]  from b::@1
  [10] b::i#1 = ++ b::i#2
  [11] if(b::i#1!=4) goto b::@1
  to:b::@return
b::@return: scope:[b]  from b::@2
  [12] 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()
char b::i
char b::i#1 // 151.5
char b::i#2 // 101.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 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [0] *SCREEN = '0' [ ] (  [ ] { }  ) 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] 252.5: zp[1]:2 [ b::i#2 b::i#1 ] 
Uplift Scope [main] 
Uplift Scope [d] 
Uplift Scope [] 

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

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// A simple loop results in NullPointerException during loop analysis
  // Upstart
  // Commodore 64 PRG executable file
.file [name="loop-problem.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .label SCREEN = $400
.segment Code
  // main
main: {
    // [0] *SCREEN = '0' -- _deref_pbuc1=vbuc2 
    lda #'0'
    sta SCREEN
    // [1] call d
    jsr d
    // [2] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    jmp __b1
    // main::@1
  __b1:
    // [3] call b
    // [7] phi from main::@1 to b [phi:main::@1->b]
  b_from___b1:
    jsr b
    jmp __breturn
    // main::@return
  __breturn:
    // [4] return 
    rts
}
  // d
d: {
    // [5] *SCREEN = ++ *SCREEN -- _deref_pbuc1=_inc__deref_pbuc1 
    inc SCREEN
    jmp __breturn
    // d::@return
  __breturn:
    // [6] return 
    rts
}
  // b
b: {
    // [8] phi from b to b::@1 [phi:b->b::@1]
  __b1_from_b:
    // [8] phi b::i#2 = 0 [phi:b->b::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [8] phi from b::@2 to b::@1 [phi:b::@2->b::@1]
  __b1_from___b2:
    // [8] phi b::i#2 = b::i#1 [phi:b::@2->b::@1#0] -- register_copy 
    jmp __b1
    // b::@1
  __b1:
    // [9] call d
    jsr d
    jmp __b2
    // b::@2
  __b2:
    // [10] b::i#1 = ++ b::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [11] if(b::i#1!=4) goto b::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #4
    bne __b1_from___b2
    jmp __breturn
    // b::@return
  __breturn:
    // [12] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Removing instruction jmp __breturn
Removing instruction jmp __b1
Removing instruction jmp __b2
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b1_from___b2 with __b1
Removing instruction __b1_from_main:
Removing instruction b_from___b1:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1:
Removing instruction __breturn:
Removing instruction __breturn:
Removing instruction __b1_from_b:
Removing instruction __b2:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
__constant char *SCREEN = (char *) 1024
void b()
char b::i
char b::i#1 // reg byte x 151.5
char b::i#2 // reg byte x 101.0
void d()
void main()

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
  // Commodore 64 PRG executable file
.file [name="loop-problem.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
  .label SCREEN = $400
.segment Code
  // main
main: {
    // *SCREEN = '0'
    // [0] *SCREEN = '0' -- _deref_pbuc1=vbuc2 
    lda #'0'
    sta SCREEN
    // d()
    // [1] call d
    jsr d
    // [2] phi from main to main::@1 [phi:main->main::@1]
    // main::@1
    // b()
    // [3] call b
    // [7] phi from main::@1 to b [phi:main::@1->b]
    jsr b
    // main::@return
    // }
    // [4] return 
    rts
}
  // d
d: {
    // (*SCREEN)++;
    // [5] *SCREEN = ++ *SCREEN -- _deref_pbuc1=_inc__deref_pbuc1 
    inc SCREEN
    // d::@return
    // }
    // [6] return 
    rts
}
  // b
b: {
    // [8] phi from b to b::@1 [phi:b->b::@1]
    // [8] phi b::i#2 = 0 [phi:b->b::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [8] phi from b::@2 to b::@1 [phi:b::@2->b::@1]
    // [8] phi b::i#2 = b::i#1 [phi:b::@2->b::@1#0] -- register_copy 
    // b::@1
  __b1:
    // d()
    // [9] call d
    jsr d
    // b::@2
    // for( byte i: 0..3)
    // [10] b::i#1 = ++ b::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [11] if(b::i#1!=4) goto b::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #4
    bne __b1
    // b::@return
    // }
    // [12] return 
    rts
}
  // File Data

