Fixing pointer array-indexing *((word[$100]) CHAR_COUNTS + *((byte*) main::screen))
Fixing pointer array-indexing *((word[$100]) CHAR_COUNTS + *((byte*) main::screen))
Culled Empty Block (label) main::@2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (word[$100]) CHAR_COUNTS#0 ← { fill( $100, 0) }
  to:@1
main: scope:[main]  from @1
  (byte*) main::screen#0 ← ((byte*)) (number) $400
  (word) main::i#0 ← (word) 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  (word) main::i#2 ← phi( main/(word) main::i#0 main::@1/(word) main::i#1 )
  (byte*) main::screen#2 ← phi( main/(byte*) main::screen#0 main::@1/(byte*) main::screen#1 )
  (byte~) main::$1 ← *((byte*) main::screen#2) * (const byte) SIZEOF_WORD
  *((word[$100]) CHAR_COUNTS#0 + (byte~) main::$1) ← ++ *((word[$100]) CHAR_COUNTS#0 + (byte~) main::$1)
  (byte*) main::screen#1 ← ++ (byte*) main::screen#2
  (word) main::i#1 ← (word) main::i#2 + rangenext(0,$3e7)
  (bool~) main::$0 ← (word) main::i#1 != rangelast(0,$3e7)
  if((bool~) main::$0) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  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
(word[$100]) CHAR_COUNTS
(word[$100]) CHAR_COUNTS#0
(const byte) SIZEOF_WORD = (byte) 2
(void()) main()
(bool~) main::$0
(byte~) main::$1
(label) main::@1
(label) main::@return
(word) main::i
(word) main::i#0
(word) main::i#1
(word) main::i#2
(byte*) main::screen
(byte*) main::screen#0
(byte*) main::screen#1
(byte*) main::screen#2

Inlining cast (byte*) main::screen#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Successful SSA optimization PassNCastSimplification
Simple Condition (bool~) main::$0 [9] if((word) main::i#1!=rangelast(0,$3e7)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [0] (word[$100]) CHAR_COUNTS#0 ← { fill( $100, 0) }
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const word[$100]) CHAR_COUNTS#0 = { fill( $100, 0) }
Constant (const byte*) main::screen#0 = (byte*) 1024
Constant (const word) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [7] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [9] if(main::i#1!=rangelast(0,$3e7)) goto main::@1 to (number) $3e8
Adding number conversion cast (unumber) $3e8 in if((word) main::i#1!=(number) $3e8) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $3e8
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (word) $3e8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting multiplication to use shift [1] (byte~) main::$1 ← *((byte*) main::screen#2) * (const byte) SIZEOF_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const byte*) main::screen#0
Inlining constant with var siblings (const word) main::i#0
Constant inlined main::screen#0 = (byte*) 1024
Constant inlined main::i#0 = (word) 0
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant (const byte) SIZEOF_WORD
Successful SSA optimization PassNEliminateUnusedVars
Added new block during phi lifting main::@3(between main::@1 and main::@1)
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 [13] main::screen#3 ← main::screen#1
Coalesced [14] main::i#3 ← main::i#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @2
Culled Empty Block (label) main::@3
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()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [5] (word) main::i#2 ← phi( main/(word) 0 main::@1/(word) main::i#1 )
  [5] (byte*) main::screen#2 ← phi( main/(byte*) 1024 main::@1/(byte*) main::screen#1 )
  [6] (byte~) main::$1 ← *((byte*) main::screen#2) << (byte) 1
  [7] *((const word[$100]) CHAR_COUNTS#0 + (byte~) main::$1) ← ++ *((const word[$100]) CHAR_COUNTS#0 + (byte~) main::$1)
  [8] (byte*) main::screen#1 ← ++ (byte*) main::screen#2
  [9] (word) main::i#1 ← ++ (word) main::i#2
  [10] if((word) main::i#1!=(word) $3e8) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(word[$100]) CHAR_COUNTS
(void()) main()
(byte~) main::$1 33.0
(word) main::i
(word) main::i#1 16.5
(word) main::i#2 5.5
(byte*) main::screen
(byte*) main::screen#1 7.333333333333333
(byte*) main::screen#2 11.0

Initial phi equivalence classes
[ main::screen#2 main::screen#1 ]
[ main::i#2 main::i#1 ]
Added variable main::$1 to zero page equivalence class [ main::$1 ]
Complete equivalence classes
[ main::screen#2 main::screen#1 ]
[ main::i#2 main::i#1 ]
[ main::$1 ]
Allocated zp ZP_WORD:2 [ main::screen#2 main::screen#1 ]
Allocated zp ZP_WORD:4 [ main::i#2 main::i#1 ]
Allocated zp ZP_BYTE:6 [ main::$1 ]

INITIAL ASM
  // File Comments
// Inner increment is not being done properly (screen++)
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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 _1 = 6
    .label screen = 2
    .label i = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (word) main::i#2 = (word) 0 [phi:main->main::@1#0] -- vwuz1=vwuc1 
    lda #<0
    sta i
    lda #>0
    sta i+1
    // [5] phi (byte*) main::screen#2 = (byte*) 1024 [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    jmp b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (word) main::i#2 = (word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // [5] phi (byte*) main::screen#2 = (byte*) main::screen#1 [phi:main::@1->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte~) main::$1 ← *((byte*) main::screen#2) << (byte) 1 -- vbuz1=_deref_pbuz2_rol_1 
    ldy #0
    lda (screen),y
    asl
    sta _1
    // [7] *((const word[$100]) CHAR_COUNTS#0 + (byte~) main::$1) ← ++ *((const word[$100]) CHAR_COUNTS#0 + (byte~) main::$1) -- pwuc1_derefidx_vbuz1=_inc_pwuc1_derefidx_vbuz1 
    ldx _1
    inc CHAR_COUNTS,x
    bne !+
    inc CHAR_COUNTS+1,x
  !:
    // [8] (byte*) main::screen#1 ← ++ (byte*) main::screen#2 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [9] (word) main::i#1 ← ++ (word) main::i#2 -- vwuz1=_inc_vwuz1 
    inc i
    bne !+
    inc i+1
  !:
    // [10] if((word) main::i#1!=(word) $3e8) goto main::@1 -- vwuz1_neq_vwuc1_then_la1 
    lda i+1
    cmp #>$3e8
    bne b1_from_b1
    lda i
    cmp #<$3e8
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // File Data
  CHAR_COUNTS: .fill 2*$100, 0

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte~) main::$1 ← *((byte*) main::screen#2) << (byte) 1 [ main::screen#2 main::i#2 main::$1 ] ( main:2 [ main::screen#2 main::i#2 main::$1 ] ) always clobbers reg byte a reg byte y 
Statement [10] if((word) main::i#1!=(word) $3e8) goto main::@1 [ main::screen#1 main::i#1 ] ( main:2 [ main::screen#1 main::i#1 ] ) always clobbers reg byte a 
Potential registers zp ZP_WORD:2 [ main::screen#2 main::screen#1 ] : zp ZP_WORD:2 , 
Potential registers zp ZP_WORD:4 [ main::i#2 main::i#1 ] : zp ZP_WORD:4 , 
Potential registers zp ZP_BYTE:6 [ main::$1 ] : zp ZP_BYTE:6 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 33: zp ZP_BYTE:6 [ main::$1 ] 22: zp ZP_WORD:4 [ main::i#2 main::i#1 ] 18.33: zp ZP_WORD:2 [ main::screen#2 main::screen#1 ] 
Uplift Scope [] 

Uplifting [main] best 988 combination reg byte a [ main::$1 ] zp ZP_WORD:4 [ main::i#2 main::i#1 ] zp ZP_WORD:2 [ main::screen#2 main::screen#1 ] 
Uplifting [] best 988 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Inner increment is not being done properly (screen++)
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @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 screen = 2
    .label i = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (word) main::i#2 = (word) 0 [phi:main->main::@1#0] -- vwuz1=vwuc1 
    lda #<0
    sta i
    lda #>0
    sta i+1
    // [5] phi (byte*) main::screen#2 = (byte*) 1024 [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    jmp b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (word) main::i#2 = (word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // [5] phi (byte*) main::screen#2 = (byte*) main::screen#1 [phi:main::@1->main::@1#1] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte~) main::$1 ← *((byte*) main::screen#2) << (byte) 1 -- vbuaa=_deref_pbuz1_rol_1 
    ldy #0
    lda (screen),y
    asl
    // [7] *((const word[$100]) CHAR_COUNTS#0 + (byte~) main::$1) ← ++ *((const word[$100]) CHAR_COUNTS#0 + (byte~) main::$1) -- pwuc1_derefidx_vbuaa=_inc_pwuc1_derefidx_vbuaa 
    tax
    inc CHAR_COUNTS,x
    bne !+
    inc CHAR_COUNTS+1,x
  !:
    // [8] (byte*) main::screen#1 ← ++ (byte*) main::screen#2 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // [9] (word) main::i#1 ← ++ (word) main::i#2 -- vwuz1=_inc_vwuz1 
    inc i
    bne !+
    inc i+1
  !:
    // [10] if((word) main::i#1!=(word) $3e8) goto main::@1 -- vwuz1_neq_vwuc1_then_la1 
    lda i+1
    cmp #>$3e8
    bne b1_from_b1
    lda i
    cmp #<$3e8
    bne b1_from_b1
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // File Data
  CHAR_COUNTS: .fill 2*$100, 0

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #>0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label b1_from_b1 with b1
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
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
(word[$100]) CHAR_COUNTS
(const word[$100]) CHAR_COUNTS#0 CHAR_COUNTS = { fill( $100, 0) }
(void()) main()
(byte~) main::$1 reg byte a 33.0
(label) main::@1
(label) main::@return
(word) main::i
(word) main::i#1 i zp ZP_WORD:4 16.5
(word) main::i#2 i zp ZP_WORD:4 5.5
(byte*) main::screen
(byte*) main::screen#1 screen zp ZP_WORD:2 7.333333333333333
(byte*) main::screen#2 screen zp ZP_WORD:2 11.0

zp ZP_WORD:2 [ main::screen#2 main::screen#1 ]
zp ZP_WORD:4 [ main::i#2 main::i#1 ]
reg byte a [ main::$1 ]


FINAL ASSEMBLER
Score: 866

  // File Comments
// Inner increment is not being done properly (screen++)
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // @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 screen = 2
    .label i = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (word) main::i#2 = (word) 0 [phi:main->main::@1#0] -- vwuz1=vwuc1 
    lda #<0
    sta i
    sta i+1
    // [5] phi (byte*) main::screen#2 = (byte*) 1024 [phi:main->main::@1#1] -- pbuz1=pbuc1 
    lda #<$400
    sta screen
    lda #>$400
    sta screen+1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [5] phi (word) main::i#2 = (word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // [5] phi (byte*) main::screen#2 = (byte*) main::screen#1 [phi:main::@1->main::@1#1] -- register_copy 
    // main::@1
  b1:
    // CHAR_COUNTS[*screen++]++;
    // [6] (byte~) main::$1 ← *((byte*) main::screen#2) << (byte) 1 -- vbuaa=_deref_pbuz1_rol_1 
    ldy #0
    lda (screen),y
    asl
    // [7] *((const word[$100]) CHAR_COUNTS#0 + (byte~) main::$1) ← ++ *((const word[$100]) CHAR_COUNTS#0 + (byte~) main::$1) -- pwuc1_derefidx_vbuaa=_inc_pwuc1_derefidx_vbuaa 
    tax
    inc CHAR_COUNTS,x
    bne !+
    inc CHAR_COUNTS+1,x
  !:
    // [8] (byte*) main::screen#1 ← ++ (byte*) main::screen#2 -- pbuz1=_inc_pbuz1 
    inc screen
    bne !+
    inc screen+1
  !:
    // for( word i:0..999)
    // [9] (word) main::i#1 ← ++ (word) main::i#2 -- vwuz1=_inc_vwuz1 
    inc i
    bne !+
    inc i+1
  !:
    // [10] if((word) main::i#1!=(word) $3e8) goto main::@1 -- vwuz1_neq_vwuc1_then_la1 
    lda i+1
    cmp #>$3e8
    bne b1
    lda i
    cmp #<$3e8
    bne b1
    // main::@return
    // }
    // [11] return 
    rts
}
  // File Data
  CHAR_COUNTS: .fill 2*$100, 0

