Setting struct to load/store in variable affected by address-of (struct A*) main::a ← &(struct A) aa
Replacing struct member reference *((struct A*) main::a).b with member unwinding reference *((byte*~) main::$2)
Warning! Adding boolean cast to non-boolean sub-expression *((byte*~) main::$2)
Identified constant variable (struct A*) main::a

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1

(void()) main()
main: scope:[main]  from @1
  (byte*~) main::$2 ← (byte*)(const struct A*) main::a + (const byte) OFFSET_STRUCT_A_B
  (bool~) main::$3 ← (number) 0 != *((byte*~) main::$2)
  (bool~) main::$0 ← ! (bool~) main::$3
  (bool~) main::$1 ← ! (bool~) main::$0
  if((bool~) main::$1) goto main::@1
  to:main::@2
main::@1: scope:[main]  from main main::@2
  asm { jmp!a+ !a:  }
  to:main::@return
main::@2: scope:[main]  from main
  *((const byte*) main::SCREEN) ← (byte) 'a'
  to:main::@1
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
(byte) A::b
(const byte) OFFSET_STRUCT_A_B = (byte) 0
(struct A) aa loadstore = { b: (byte) 1 }
(void()) main()
(bool~) main::$0
(bool~) main::$1
(byte*~) main::$2
(bool~) main::$3
(label) main::@1
(label) main::@2
(label) main::@return
(const byte*) main::SCREEN = (byte*)(number) $400
(const struct A*) main::a = &(struct A) aa

Adding number conversion cast (unumber) 0 in (bool~) main::$3 ← (number) 0 != *((byte*~) main::$2)
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inversing boolean not [2] (bool~) main::$0 ← (byte) 0 == *((byte*~) main::$2) from [1] (bool~) main::$3 ← (byte) 0 != *((byte*~) main::$2)
Inversing boolean not [3] (bool~) main::$1 ← (byte) 0 != *((byte*~) main::$2) from [2] (bool~) main::$0 ← (byte) 0 == *((byte*~) main::$2)
Successful SSA optimization Pass2UnaryNotSimplification
Simple Condition (bool~) main::$1 [4] if((byte) 0!=*((byte*~) main::$2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [0] (byte*~) main::$2 ← (byte*)(const struct A*) main::a + (const byte) OFFSET_STRUCT_A_B
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte*) main::$2 = (byte*)main::a+OFFSET_STRUCT_A_B
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero (byte*)main::a in 
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant (const byte) OFFSET_STRUCT_A_B
Successful SSA optimization PassNEliminateUnusedVars
Constant inlined main::$2 = (byte*)(const struct A*) main::a
Successful SSA optimization Pass2ConstantInlining
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
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
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end

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()

(void()) main()
main: scope:[main]  from @1
  [4] if((byte) 0!=*((byte*)(const struct A*) main::a)) goto main::@1
  to:main::@2
main::@2: scope:[main]  from main
  [5] *((const byte*) main::SCREEN) ← (byte) 'a'
  to:main::@1
main::@1: scope:[main]  from main main::@2
  asm { jmp!a+ !a:  }
  to:main::@return
main::@return: scope:[main]  from main::@1
  [7] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(byte) A::b
(struct A) aa loadstore = { b: (byte) 1 }
(void()) main()

Initial phi equivalence classes
Added variable aa to live range equivalence class [ aa ]
Complete equivalence classes
[ aa ]
Allocated mem[1] [ aa ]

INITIAL ASM
Target platform is c64basic / MOS6502X
  // File Comments
// Test parsing a negated struct reference - which causes problems with the ASMREL labels !a++
// https://gitlab.com/camelot/kickc/issues/266
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label SCREEN = $400
    .label a = aa
    // [4] if((byte) 0!=*((byte*)(const struct A*) main::a)) goto main::@1 -- vbuc1_neq__deref_pbuc2_then_la1 
    lda #0
    cmp a
    bne __b1
    jmp __b2
    // main::@2
  __b2:
    // [5] *((const byte*) main::SCREEN) ← (byte) 'a' -- _deref_pbuc1=vbuc2 
    lda #'a'
    sta SCREEN
    jmp __b1
    // main::@1
  __b1:
    // asm { jmp!a+ !a:  }
    // ASMREL labels
    jmp !a+
  !a:
    jmp __breturn
    // main::@return
  __breturn:
    // [7] return 
    rts
}
  // File Data
  aa: .byte 1

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] if((byte) 0!=*((byte*)(const struct A*) main::a)) goto main::@1 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [5] *((const byte*) main::SCREEN) ← (byte) 'a' [ ] ( main:2 [ ] ) always clobbers reg byte a 
Potential registers mem[1] [ aa ] : mem[1] , 

REGISTER UPLIFT SCOPES
Uplift Scope [A] 
Uplift Scope [main] 
Uplift Scope [] 0: mem[1] [ aa ] 

Uplifting [A] best 44 combination 
Uplifting [main] best 44 combination 
Uplifting [] best 44 combination mem[1] [ aa ] 
Attempting to uplift remaining variables inmem[1] [ aa ]
Uplifting [] best 44 combination mem[1] [ aa ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Test parsing a negated struct reference - which causes problems with the ASMREL labels !a++
// https://gitlab.com/camelot/kickc/issues/266
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
__bend_from___b1:
  jmp __bend
  // @end
__bend:
  // main
main: {
    .label SCREEN = $400
    .label a = aa
    // [4] if((byte) 0!=*((byte*)(const struct A*) main::a)) goto main::@1 -- vbuc1_neq__deref_pbuc2_then_la1 
    lda #0
    cmp a
    bne __b1
    jmp __b2
    // main::@2
  __b2:
    // [5] *((const byte*) main::SCREEN) ← (byte) 'a' -- _deref_pbuc1=vbuc2 
    lda #'a'
    sta SCREEN
    jmp __b1
    // main::@1
  __b1:
    // asm { jmp!a+ !a:  }
    // ASMREL labels
    jmp !a+
  !a:
    jmp __breturn
    // main::@return
  __breturn:
    // [7] return 
    rts
}
  // File Data
  aa: .byte 1

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __bend
Removing instruction jmp __b2
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __bbegin with __b1
Removing instruction __bbegin:
Removing instruction __b1_from___bbegin:
Removing instruction __bend_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __bend:
Removing instruction __b2:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Skipping double jump to !a+ in bne __b1
Succesful ASM optimization Pass5DoubleJumpElimination
Removing instruction __b1:
Removing instruction __b1:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(byte) A::b
(struct A) aa loadstore mem[1] = { b: (byte) 1 }
(void()) main()
(label) main::@1
(label) main::@2
(label) main::@return
(const byte*) main::SCREEN = (byte*) 1024
(const struct A*) main::a = &(struct A) aa

mem[1] [ aa ]


FINAL ASSEMBLER
Score: 23

  // File Comments
// Test parsing a negated struct reference - which causes problems with the ASMREL labels !a++
// https://gitlab.com/camelot/kickc/issues/266
  // 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 
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label SCREEN = $400
    .label a = aa
    // if(!a->b)
    // [4] if((byte) 0!=*((byte*)(const struct A*) main::a)) goto main::@1 -- vbuc1_neq__deref_pbuc2_then_la1 
    lda #0
    cmp a
    bne !a+
    // main::@2
    // *SCREEN = 'a'
    // [5] *((const byte*) main::SCREEN) ← (byte) 'a' -- _deref_pbuc1=vbuc2 
    lda #'a'
    sta SCREEN
    // main::@1
    // asm
    // asm { jmp!a+ !a:  }
    // ASMREL labels
    jmp !a+
  !a:
    // main::@return
    // }
    // [7] return 
    rts
}
  // File Data
  aa: .byte 1

