Culled Empty Block (label) main::@1
Culled Empty Block (label) main::@4

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (byte*) DC00#0 ← ((byte*)) (number) $dc00
  (byte) key#0 ← (byte) 0
  to:@1
main: scope:[main]  from @1
  to:main::@2
main::@2: scope:[main]  from main main::@2 main::@3
  (byte) key#1 ← *((byte*) DC00#0)
  (bool~) main::$0 ← (byte) key#1 == (number) 0
  (number~) main::$1 ← (byte) key#1 & (number) $1f
  (bool~) main::$2 ← (number~) main::$1 == (number) $1f
  (bool~) main::$3 ← (bool~) main::$0 && (bool~) main::$2
  if((bool~) main::$3) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@2
  (byte) key#6 ← phi( main::@2/(byte) key#1 )
  if(true) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@3
  (byte) key#4 ← phi( main::@3/(byte) key#6 )
  (byte) key#2 ← (byte) key#4
  return 
  to:@return
@1: scope:[]  from @begin
  (byte) key#7 ← phi( @begin/(byte) key#0 )
  call main 
  to:@2
@2: scope:[]  from @1
  (byte) key#5 ← phi( @1/(byte) key#2 )
  (byte) key#3 ← (byte) key#5
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(byte*) DC00
(byte*) DC00#0
(byte) key
(byte) key#0
(byte) key#1
(byte) key#2
(byte) key#3
(byte) key#4
(byte) key#5
(byte) key#6
(byte) key#7
(void()) main()
(bool~) main::$0
(number~) main::$1
(bool~) main::$2
(bool~) main::$3
(label) main::@2
(label) main::@3
(label) main::@return

Adding number conversion cast (unumber) 0 in (bool~) main::$0 ← (byte) key#1 == (number) 0
Adding number conversion cast (unumber) $1f in (number~) main::$1 ← (byte) key#1 & (number) $1f
Adding number conversion cast (unumber) main::$1 in (number~) main::$1 ← (byte) key#1 & (unumber)(number) $1f
Adding number conversion cast (unumber) $1f in (bool~) main::$2 ← (unumber~) main::$1 == (number) $1f
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) DC00#0 ← (byte*)(number) $dc00
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 56320
Simplifying constant integer cast 0
Simplifying constant integer cast $1f
Simplifying constant integer cast $1f
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) $1f
Finalized unsigned number type (byte) $1f
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$1 ← (byte) key#1 & (byte) $1f
Alias (byte) key#1 = (byte) key#6 (byte) key#4 (byte) key#2 
Alias (byte) key#0 = (byte) key#7 
Alias (byte) key#3 = (byte) key#5 
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) key#3 (byte) key#1
Successful SSA optimization Pass2IdenticalPhiElimination
Rewriting && if()-condition to two if()s [6] (bool~) main::$3 ← (bool~) main::$0 && (bool~) main::$2
Successful SSA optimization Pass2ConditionalAndOrRewriting
Constant (const byte*) DC00#0 = (byte*) 56320
Constant (const byte) key#0 = 0
Successful SSA optimization Pass2ConstantIdentification
if() condition always true - replacing block destination [9] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Eliminating unused constant (const byte) key#0
Successful SSA optimization PassNEliminateUnusedVars
Removing unused block main::@return
Successful SSA optimization Pass2EliminateUnusedBlocks
Simple Condition (bool~) main::$0 [4] if((byte) key#1==(byte) 0) goto main::@5
Simple Condition (bool~) main::$2 [6] if((byte~) main::$1==(byte) $1f) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Negating conditional jump and destination [4] if((byte) key#1!=(byte) 0) goto main::@3
Successful SSA optimization Pass2ConditionalJumpSequenceImprovement
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
Adding NOP phi() at start of main::@3
CALL GRAPH
Calls in [] to main:2 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Renumbering block main::@2 to main::@1
Renumbering block main::@3 to main::@2
Renumbering block main::@5 to 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
Adding NOP phi() at start of main::@2

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::@2 main::@3
  [5] (byte) key#1 ← *((const byte*) DC00#0)
  [6] (byte~) main::$1 ← (byte) key#1 & (byte) $1f
  [7] if((byte) key#1!=(byte) 0) goto main::@2
  to:main::@3
main::@3: scope:[main]  from main::@1
  [8] if((byte~) main::$1==(byte) $1f) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main::@1 main::@3
  [9] phi()
  to:main::@1


VARIABLE REGISTER WEIGHTS
(byte*) DC00
(byte) key
(byte) key#1 151.5
(void()) main()
(byte~) main::$1 101.0

Initial phi equivalence classes
Added variable key#1 to zero page equivalence class [ key#1 ]
Added variable main::$1 to zero page equivalence class [ main::$1 ]
Complete equivalence classes
[ key#1 ]
[ main::$1 ]
Allocated zp ZP_BYTE:2 [ key#1 ]
Allocated zp ZP_BYTE:3 [ main::$1 ]

INITIAL ASM
Target platform is c64basic
  // File Comments
// Duplicate Loop Problem from Richard-William Loerakker
// Resulted in infinite loop in loop depth analysis
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label DC00 = $dc00
  .label key = 2
  // @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 = 3
    jmp b1
    // main::@1
  b1:
    // [5] (byte) key#1 ← *((const byte*) DC00#0) -- vbuz1=_deref_pbuc1 
    lda DC00
    sta.z key
    // [6] (byte~) main::$1 ← (byte) key#1 & (byte) $1f -- vbuz1=vbuz2_band_vbuc1 
    lda #$1f
    and.z key
    sta.z _1
    // [7] if((byte) key#1!=(byte) 0) goto main::@2 -- vbuz1_neq_0_then_la1 
    lda.z key
    cmp #0
    bne b2_from_b1
    jmp b3
    // main::@3
  b3:
    // [8] if((byte~) main::$1==(byte) $1f) goto main::@1 -- vbuz1_eq_vbuc1_then_la1 
    lda #$1f
    cmp.z _1
    beq b1
    // [9] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
  b2_from_b1:
  b2_from_b3:
    jmp b2
    // main::@2
  b2:
    jmp b1
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Potential registers zp ZP_BYTE:2 [ key#1 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y , 
Potential registers zp ZP_BYTE:3 [ main::$1 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [] 151.5: zp ZP_BYTE:2 [ key#1 ] 
Uplift Scope [main] 101: zp ZP_BYTE:3 [ main::$1 ] 

Uplifting [] best 2502 combination reg byte x [ key#1 ] 
Uplifting [main] best 2102 combination reg byte a [ main::$1 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Duplicate Loop Problem from Richard-William Loerakker
// Resulted in infinite loop in loop depth analysis
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  .label DC00 = $dc00
  // @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: {
    jmp b1
    // main::@1
  b1:
    // [5] (byte) key#1 ← *((const byte*) DC00#0) -- vbuxx=_deref_pbuc1 
    ldx DC00
    // [6] (byte~) main::$1 ← (byte) key#1 & (byte) $1f -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #$1f
    // [7] if((byte) key#1!=(byte) 0) goto main::@2 -- vbuxx_neq_0_then_la1 
    cpx #0
    bne b2_from_b1
    jmp b3
    // main::@3
  b3:
    // [8] if((byte~) main::$1==(byte) $1f) goto main::@1 -- vbuaa_eq_vbuc1_then_la1 
    cmp #$1f
    beq b1
    // [9] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
  b2_from_b1:
  b2_from_b3:
    jmp b2
    // main::@2
  b2:
    jmp b1
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b3
Removing instruction jmp b2
Succesful ASM optimization Pass5NextJumpElimination
Replacing label b2_from_b1 with b2
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b2_from_b1:
Removing instruction b2_from_b3:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b3:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Skipping double jump to b1 in bne b2
Succesful ASM optimization Pass5DoubleJumpElimination
Removing instruction bbegin:
Removing instruction b2:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte*) DC00
(const byte*) DC00#0 DC00 = (byte*) 56320
(byte) key
(byte) key#1 reg byte x 151.5
(void()) main()
(byte~) main::$1 reg byte a 101.0
(label) main::@1
(label) main::@2
(label) main::@3

reg byte x [ key#1 ]
reg byte a [ main::$1 ]


FINAL ASSEMBLER
Score: 1730

  // File Comments
// Duplicate Loop Problem from Richard-William Loerakker
// Resulted in infinite loop in loop depth analysis
  // Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  .label DC00 = $dc00
  // @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: {
    // main::@1
  b1:
    // key = *DC00
    // [5] (byte) key#1 ← *((const byte*) DC00#0) -- vbuxx=_deref_pbuc1 
    ldx DC00
    // key & %00011111
    // [6] (byte~) main::$1 ← (byte) key#1 & (byte) $1f -- vbuaa=vbuxx_band_vbuc1 
    txa
    and #$1f
    // while(key == 0 && ((key & %00011111) == %00011111))
    // [7] if((byte) key#1!=(byte) 0) goto main::@2 -- vbuxx_neq_0_then_la1 
    cpx #0
    bne b1
    // main::@3
    // [8] if((byte~) main::$1==(byte) $1f) goto main::@1 -- vbuaa_eq_vbuc1_then_la1 
    cmp #$1f
    beq b1
    // [9] phi from main::@1 main::@3 to main::@2 [phi:main::@1/main::@3->main::@2]
    // main::@2
    jmp b1
}
  // File Data

