Fixing constant pointer addition seq+0
Fixing constant pointer addition settings+0

CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::i#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@2
  main::i#2 = phi( main/main::i#0, main::@2/main::i#1 )
  main::$4 = (char *)main::setting
  main::$2 = main::$4 + OFFSET_STRUCT_SETTING_LEN
  main::$0 = main::i#2 < *main::$2
  if(main::$0) goto main::@2
  to:main::@return
main::@2: scope:[main]  from main::@1
  main::i#3 = phi( main::@1/main::i#2 )
  main::$1 = main::i#3 * SIZEOF_UNSIGNED_INT
  main::$5 = (unsigned int **)main::setting
  main::$3 = main::$5 + OFFSET_STRUCT_SETTING_BUF
  SCREEN[main::$1] = (*main::$3)[main::$1]
  main::i#1 = ++ main::i#3
  to:main::@1
main::@return: scope:[main]  from main::@1
  return 
  to:@return

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

SYMBOL TABLE SSA
__constant char OFFSET_STRUCT_SETTING_BUF = 1
__constant char OFFSET_STRUCT_SETTING_LEN = 0
__constant unsigned int * const SCREEN = (char *)$400
__constant char SIZEOF_STRUCT_SETTING = 3
__constant char SIZEOF_UNSIGNED_INT = 2
void __start()
void main()
bool main::$0
char main::$1
char *main::$2
unsigned int **main::$3
char *main::$4
unsigned int **main::$5
char main::i
char main::i#0
char main::i#1
char main::i#2
char main::i#3
__constant struct Setting *main::setting = settings+0*SIZEOF_STRUCT_SETTING
__constant unsigned int seq[] = { 1, 2, 3 }
__constant struct Setting settings[] = { { len: 3, buf: seq+0*SIZEOF_UNSIGNED_INT } }

Adding number conversion cast (unumber) 0*SIZEOF_UNSIGNED_INT in 
Adding number conversion cast (unumber) 0 in 
Adding number conversion cast (unumber) 0*SIZEOF_STRUCT_SETTING in 
Adding number conversion cast (unumber) 0 in 
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast (unumber)0*SIZEOF_UNSIGNED_INT
Simplifying constant integer cast 0
Simplifying constant integer cast (unumber)0*SIZEOF_STRUCT_SETTING
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 0
Finalized unsigned number type (char) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias main::i#2 = main::i#3 
Successful SSA optimization Pass2AliasElimination
Simple Condition main::$0 [5] if(main::i#2<*main::$2) goto main::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [2] main::$4 = (char *)main::setting
Constant right-side identified [7] main::$5 = (unsigned int **)main::setting
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::i#0 = 0
Constant main::$4 = (char *)main::setting
Constant main::$5 = (unsigned int **)main::setting
Successful SSA optimization Pass2ConstantIdentification
Converting *(pointer+n) to pointer[n] [5] if(main::i#2<*main::$2) goto main::@2  -- main::$4[OFFSET_STRUCT_SETTING_LEN]
Converting *(pointer+n) to pointer[n] [9] SCREEN[main::$1] = (*main::$3)[main::$1]  -- main::$5[OFFSET_STRUCT_SETTING_BUF]
Successful SSA optimization Pass2InlineDerefIdx
Simplifying constant evaluating to zero 0*SIZEOF_UNSIGNED_INT in 
Simplifying constant evaluating to zero 0*SIZEOF_STRUCT_SETTING in 
Successful SSA optimization PassNSimplifyConstantZero
Simplifying expression containing zero seq in 
Simplifying expression containing zero settings in 
Simplifying expression containing zero main::$4 in [3] main::$2 = main::$4 + OFFSET_STRUCT_SETTING_LEN
Simplifying expression containing zero main::$4 in [5] if(main::i#2<main::$4[OFFSET_STRUCT_SETTING_LEN]) goto main::@2
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused variable main::$2 and assignment [1] main::$2 = main::$4
Eliminating unused variable main::$3 and assignment [4] main::$3 = main::$5 + OFFSET_STRUCT_SETTING_BUF
Eliminating unused constant SIZEOF_STRUCT_SETTING
Eliminating unused constant OFFSET_STRUCT_SETTING_LEN
Successful SSA optimization PassNEliminateUnusedVars
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Rewriting multiplication to use shift [2] main::$1 = main::i#2 * SIZEOF_UNSIGNED_INT
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings main::i#0
Constant inlined main::$5 = (unsigned int **)settings
Constant inlined main::i#0 = 0
Constant inlined main::$4 = (char *)settings
Constant inlined main::setting = settings
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *((unsigned int **)settings+OFFSET_STRUCT_SETTING_BUF)
Successful SSA optimization Pass2ConstantAdditionElimination
Eliminating unused constant SIZEOF_UNSIGNED_INT
Successful SSA optimization PassNEliminateUnusedVars
Adding NOP phi() at start of main
CALL GRAPH

Created 1 initial phi equivalence classes
Coalesced [7] main::i#4 = main::i#1
Coalesced down to 1 phi equivalence classes
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@2
  [1] main::i#2 = phi( main/0, main::@2/main::i#1 )
  [2] if(main::i#2<*((char *)settings)) goto main::@2
  to:main::@return
main::@return: scope:[main]  from main::@1
  [3] return 
  to:@return
main::@2: scope:[main]  from main::@1
  [4] main::$1 = main::i#2 << 1
  [5] SCREEN[main::$1] = (*((unsigned int **)settings+OFFSET_STRUCT_SETTING_BUF))[main::$1]
  [6] main::i#1 = ++ main::i#2
  to:main::@1


VARIABLE REGISTER WEIGHTS
void main()
char main::$1 // 33.0
char main::i
char main::i#1 // 22.0
char main::i#2 // 11.0

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::$1 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ main::$1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] main::$1 = main::i#2 << 1 [ main::i#2 main::$1 ] (  [ main::i#2 main::$1 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [5] SCREEN[main::$1] = (*((unsigned int **)settings+OFFSET_STRUCT_SETTING_BUF))[main::$1] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a reg byte y 
Removing always clobbered register reg byte y as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [4] main::$1 = main::i#2 << 1 [ main::i#2 main::$1 ] (  [ main::i#2 main::$1 ] { }  ) always clobbers reg byte a 
Statement [5] SCREEN[main::$1] = (*((unsigned int **)settings+OFFSET_STRUCT_SETTING_BUF))[main::$1] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a reg byte y 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , 
Potential registers zp[1]:3 [ main::$1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 33: zp[1]:2 [ main::i#2 main::i#1 ] 33: zp[1]:3 [ main::$1 ] 
Uplift Scope [Setting] 
Uplift Scope [] 

Uplifting [main] best 631 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$1 ] 
Uplifting [Setting] best 631 combination 
Uplifting [] best 631 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Demonstrates problem with conditions using negated struct references
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-ptr-21.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
  .const OFFSET_STRUCT_SETTING_BUF = 1
  .label SCREEN = $400
.segment Code
  // main
main: {
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // main::@1
  __b1:
    // [2] if(main::i#2<*((char *)settings)) goto main::@2 -- vbuxx_lt__deref_pbuc1_then_la1 
    cpx settings
    bcc __b2
    jmp __breturn
    // main::@return
  __breturn:
    // [3] return 
    rts
    // main::@2
  __b2:
    // [4] main::$1 = main::i#2 << 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [5] SCREEN[main::$1] = (*((unsigned int **)settings+OFFSET_STRUCT_SETTING_BUF))[main::$1] -- pwuc1_derefidx_vbuaa=(_deref_qwuc2)_derefidx_vbuaa 
    tay
    lda settings+OFFSET_STRUCT_SETTING_BUF
    sta.z $fe
    lda settings+OFFSET_STRUCT_SETTING_BUF+1
    sta.z $ff
    lda ($fe),y
    sta SCREEN,y
    iny
    lda ($fe),y
    sta SCREEN,y
    // [6] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
  __b1_from___b2:
    // [1] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  seq: .word 1, 2, 3
  settings: .byte 3
  .word seq

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction __b1_from_main:
Removing instruction __breturn:
Removing instruction __b1_from___b2:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
__constant char OFFSET_STRUCT_SETTING_BUF = 1
__constant unsigned int * const SCREEN = (char *) 1024
void main()
char main::$1 // reg byte a 33.0
char main::i
char main::i#1 // reg byte x 22.0
char main::i#2 // reg byte x 11.0
__constant unsigned int seq[] = { 1, 2, 3 }
__constant struct Setting settings[] = { { len: 3, buf: seq } }

reg byte x [ main::i#2 main::i#1 ]
reg byte a [ main::$1 ]


FINAL ASSEMBLER
Score: 571

  // File Comments
// Demonstrates problem with conditions using negated struct references
  // Upstart
  // Commodore 64 PRG executable file
.file [name="struct-ptr-21.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
  .const OFFSET_STRUCT_SETTING_BUF = 1
  .label SCREEN = $400
.segment Code
  // main
main: {
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // main::@1
  __b1:
    // for( char i=0;i<setting->len;i++)
    // [2] if(main::i#2<*((char *)settings)) goto main::@2 -- vbuxx_lt__deref_pbuc1_then_la1 
    cpx settings
    bcc __b2
    // main::@return
    // }
    // [3] return 
    rts
    // main::@2
  __b2:
    // SCREEN[i] = setting->buf[i]
    // [4] main::$1 = main::i#2 << 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [5] SCREEN[main::$1] = (*((unsigned int **)settings+OFFSET_STRUCT_SETTING_BUF))[main::$1] -- pwuc1_derefidx_vbuaa=(_deref_qwuc2)_derefidx_vbuaa 
    tay
    lda settings+OFFSET_STRUCT_SETTING_BUF
    sta.z $fe
    lda settings+OFFSET_STRUCT_SETTING_BUF+1
    sta.z $ff
    lda ($fe),y
    sta SCREEN,y
    iny
    lda ($fe),y
    sta SCREEN,y
    // for( char i=0;i<setting->len;i++)
    // [6] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
    // [1] phi main::i#2 = main::i#1 [phi:main::@2->main::@1#0] -- register_copy 
    jmp __b1
}
  // File Data
.segment Data
  seq: .word 1, 2, 3
  settings: .byte 3
  .word seq

