#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ print_binary(int, int);
int /*<<< orphan*/ printf(char *);
void test_union() {
  printf("\n===== test_union\n");
  union {
    struct {
      uint8_t a : 1;
      uint8_t b : 1;
    } bits;
    uint16_t memory_value;
  } bitset;
  printf("bitset.memory_value (initial)    : ");
  print_binary(bitset.memory_value, 16);
  bitset.bits.a = 1;
  bitset.bits.b = 1;
  printf("bitset.memory_value (set)        : ");
  print_binary(bitset.memory_value, 16);
  printf("bitset.bits.a                    : ");
  print_binary(bitset.bits.a, 1);
  printf("bitset.bits.b                    : ");
  print_binary(bitset.bits.b, 1);
  bitset.bits.b = 0;
  printf("bitset.memory_value (clear b)    : ");
  print_binary(bitset.memory_value, 16);
  printf("bitset.bits.a                    : ");
  print_binary(bitset.bits.a, 1);
  printf("bitset.bits.b                    : ");
  print_binary(bitset.bits.b, 1);
  bitset.memory_value = 0xaaaf;
  printf("bitset.memory_value (direct set) : ");
  print_binary(bitset.memory_value, 16);
  printf("bitset.bits.a                    : ");
  print_binary(bitset.bits.a, 1);
  printf("bitset.bits.b                    : ");
  print_binary(bitset.bits.b, 1);
  assert(bitset.bits.a == 1);
  assert(bitset.bits.b == 1);
}


x86 assembly (clang, -O0):
<test_union>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x10,%esi
call   1050 <print_binary@plt>
mov    -0x8(%rbp),%al
and    $0xfe,%al
or     $0x1,%al
mov    %al,-0x8(%rbp)
mov    -0x8(%rbp),%al
and    $0xfd,%al
or     $0x2,%al
mov    %al,-0x8(%rbp)
lea    0xebf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x10,%esi
call   1050 <print_binary@plt>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%al
shl    $0x7,%al
sar    $0x7,%al
movsbl %al,%edi
mov    $0x1,%esi
call   1050 <print_binary@plt>
lea    0xecc(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%al
shl    $0x6,%al
sar    $0x7,%al
movsbl %al,%edi
mov    $0x1,%esi
call   1050 <print_binary@plt>
mov    -0x8(%rbp),%al
and    $0xfd,%al
or     $0x0,%al
mov    %al,-0x8(%rbp)
lea    0xec4(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x10,%esi
call   1050 <print_binary@plt>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%al
shl    $0x7,%al
sar    $0x7,%al
movsbl %al,%edi
mov    $0x1,%esi
call   1050 <print_binary@plt>
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%al
shl    $0x6,%al
sar    $0x7,%al
movsbl %al,%edi
mov    $0x1,%esi
call   1050 <print_binary@plt>
movl   $0xaaaf,-0x8(%rbp)
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x10,%esi
call   1050 <print_binary@plt>
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%al
shl    $0x7,%al
sar    $0x7,%al
movsbl %al,%edi
mov    $0x1,%esi
call   1050 <print_binary@plt>
lea    0xe01(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%al
shl    $0x6,%al
sar    $0x7,%al
movsbl %al,%edi
mov    $0x1,%esi
call   1050 <print_binary@plt>
mov    -0x8(%rbp),%al
shl    $0x7,%al
sar    $0x7,%al
movsbl %al,%eax
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%al
shl    $0x6,%al
sar    $0x7,%al
movsbl %al,%eax
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_union>:
push   %r14
push   %rbx
push   %rax
lea    0xf8d(%rip),%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
call   1040 <printf@plt>
mov    $0xaa00,%edi
mov    $0x10,%esi
call   1060 <print_binary@plt>
lea    0xeb2(%rip),%rdi
call   1040 <printf@plt>
mov    $0xaa03,%edi
mov    $0x10,%esi
call   1060 <print_binary@plt>
lea    0xebb(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1060 <print_binary@plt>
lea    0xec1(%rip),%rbx
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1060 <print_binary@plt>
lea    0xec7(%rip),%rdi
call   1040 <printf@plt>
mov    $0xaa01,%edi
mov    $0x10,%esi
call   1060 <print_binary@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1060 <print_binary@plt>
mov    %rbx,%rdi
call   1040 <printf@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <print_binary@plt>
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
mov    $0xaaaf,%edi
mov    $0x10,%esi
call   1060 <print_binary@plt>
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1060 <print_binary@plt>
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
mov    $0x1,%esi
call   1060 <print_binary@plt>
xor    %edi,%edi
call   1050 <assert@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <assert@plt>

LLVM IR (-O0):
%union.anon = type { i32 }
%struct.anon = type { i8, [3 x i8] }
@.str = [19 x i8] c"\0A===== test_union\0A\00"
@.str.1 = [36 x i8] c"bitset.memory_value (initial) : \00"
@.str.2 = [36 x i8] c"bitset.memory_value (set) : \00"
@.str.3 = [36 x i8] c"bitset.bits.a : \00"
@.str.4 = [36 x i8] c"bitset.bits.b : \00"
@.str.5 = [36 x i8] c"bitset.memory_value (clear b) : \00"
@.str.6 = [36 x i8] c"bitset.memory_value (direct set) : \00"
define void @test_union() {
%1 = alloca %union.anon
%2 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%4 = bitcast %union.anon* %1 to i32*
%5 = load i32, i32* %4
%6 = call i32 @print_binary(i32 %5, i32 16)
%7 = bitcast %union.anon* %1 to %struct.anon*
%8 = bitcast %struct.anon* %7 to i8*
%9 = load i8, i8* %8
%10 = and i8 %9, -2
%11 = or i8 %10, 1
store i8 %11, i8* %8
%12 = bitcast %union.anon* %1 to %struct.anon*
%13 = bitcast %struct.anon* %12 to i8*
%14 = load i8, i8* %13
%15 = and i8 %14, -3
%16 = or i8 %15, 2
store i8 %16, i8* %13
%17 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%18 = bitcast %union.anon* %1 to i32*
%19 = load i32, i32* %18
%20 = call i32 @print_binary(i32 %19, i32 16)
%21 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%22 = bitcast %union.anon* %1 to %struct.anon*
%23 = bitcast %struct.anon* %22 to i8*
%24 = load i8, i8* %23
%25 = shl i8 %24, 7
%26 = ashr i8 %25, 7
%27 = sext i8 %26 to i32
%28 = call i32 @print_binary(i32 %27, i32 1)
%29 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%30 = bitcast %union.anon* %1 to %struct.anon*
%31 = bitcast %struct.anon* %30 to i8*
%32 = load i8, i8* %31
%33 = shl i8 %32, 6
%34 = ashr i8 %33, 7
%35 = sext i8 %34 to i32
%36 = call i32 @print_binary(i32 %35, i32 1)
%37 = bitcast %union.anon* %1 to %struct.anon*
%38 = bitcast %struct.anon* %37 to i8*
%39 = load i8, i8* %38
%40 = and i8 %39, -3
%41 = or i8 %40, 0
store i8 %41, i8* %38
%42 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%43 = bitcast %union.anon* %1 to i32*
%44 = load i32, i32* %43
%45 = call i32 @print_binary(i32 %44, i32 16)
%46 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%47 = bitcast %union.anon* %1 to %struct.anon*
%48 = bitcast %struct.anon* %47 to i8*
%49 = load i8, i8* %48
%50 = shl i8 %49, 7
%51 = ashr i8 %50, 7
%52 = sext i8 %51 to i32
%53 = call i32 @print_binary(i32 %52, i32 1)
%54 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%55 = bitcast %union.anon* %1 to %struct.anon*
%56 = bitcast %struct.anon* %55 to i8*
%57 = load i8, i8* %56
%58 = shl i8 %57, 6
%59 = ashr i8 %58, 7
%60 = sext i8 %59 to i32
%61 = call i32 @print_binary(i32 %60, i32 1)
%62 = bitcast %union.anon* %1 to i32*
store i32 43695, i32* %62
%63 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%64 = bitcast %union.anon* %1 to i32*
%65 = load i32, i32* %64
%66 = call i32 @print_binary(i32 %65, i32 16)
%67 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%68 = bitcast %union.anon* %1 to %struct.anon*
%69 = bitcast %struct.anon* %68 to i8*
%70 = load i8, i8* %69
%71 = shl i8 %70, 7
%72 = ashr i8 %71, 7
%73 = sext i8 %72 to i32
%74 = call i32 @print_binary(i32 %73, i32 1)
%75 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%76 = bitcast %union.anon* %1 to %struct.anon*
%77 = bitcast %struct.anon* %76 to i8*
%78 = load i8, i8* %77
%79 = shl i8 %78, 6
%80 = ashr i8 %79, 7
%81 = sext i8 %80 to i32
%82 = call i32 @print_binary(i32 %81, i32 1)
%83 = bitcast %union.anon* %1 to %struct.anon*
%84 = bitcast %struct.anon* %83 to i8*
%85 = load i8, i8* %84
%86 = shl i8 %85, 7
%87 = ashr i8 %86, 7
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 1
%90 = zext i1 %89 to i32
%91 = call i32 @assert(i32 %90)
%92 = bitcast %union.anon* %1 to %struct.anon*
%93 = bitcast %struct.anon* %92 to i8*
%94 = load i8, i8* %93
%95 = shl i8 %94, 6
%96 = ashr i8 %95, 7
%97 = sext i8 %96 to i32
%98 = icmp eq i32 %97, 1
%99 = zext i1 %98 to i32
%100 = call i32 @assert(i32 %99)
ret void
}

LLVM IR (-O2):
@.str.1 = [36 x i8] c"bitset.memory_value (initial) : \00"
@.str.2 = [36 x i8] c"bitset.memory_value (set) : \00"
@.str.3 = [36 x i8] c"bitset.bits.a : \00"
@.str.4 = [36 x i8] c"bitset.bits.b : \00"
@.str.5 = [36 x i8] c"bitset.memory_value (clear b) : \00"
@.str.6 = [36 x i8] c"bitset.memory_value (direct set) : \00"
@str = [18 x i8] c"\0A===== test_union\00"
define void @test_union() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @print_binary(i32 43520, i32 16)
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @print_binary(i32 43523, i32 16)
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%7 = tail call i32 @print_binary(i32 -1, i32 1)
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%9 = tail call i32 @print_binary(i32 -1, i32 1)
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%11 = tail call i32 @print_binary(i32 43521, i32 16)
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @print_binary(i32 -1, i32 1)
%14 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%15 = tail call i32 @print_binary(i32 0, i32 1)
%16 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%17 = tail call i32 @print_binary(i32 43695, i32 16)
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i32 @print_binary(i32 -1, i32 1)
%20 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @print_binary(i32 -1, i32 1)
%22 = tail call i32 @assert(i32 0)
%23 = tail call i32 @assert(i32 0)
ret void
}