#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 /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ bitfield;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ print_binary(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
void test_anonymous_narrow() {
  printf("\n===== test_anonymous_narrow\n");
  struct {
    uint8_t a : 1;
    uint8_t b : 1;
  } bitfield;
  printf("Memory size occupied by bitfield : %lu bits\n", sizeof(bitfield) * 8);
  printf("Memory contents (initial): ");
  print_binary(*(uint32_t *)&bitfield, sizeof(bitfield) * 8);
  bitfield.a = 1;
  bitfield.b = 1;
  assert(bitfield.a == 1);
  assert(bitfield.b == 1);
  printf("Memory contents (set)    : ");
  print_binary(*(uint32_t *)&bitfield, sizeof(bitfield) * 8);
  bitfield.a = 0;
  bitfield.b = 0;
  assert(bitfield.a == 0);
  assert(bitfield.b == 0);
  printf("Memory contents (cleared): ");
  print_binary(*(uint32_t *)&bitfield, sizeof(bitfield) * 8);
}


x86 assembly (clang, -O0):
<test_anonymous_narrow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
mov    $0x20,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x20,%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)
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>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x20,%esi
call   1050 <print_binary@plt>
mov    -0x8(%rbp),%al
and    $0xfe,%al
or     $0x0,%al
mov    %al,-0x8(%rbp)
mov    -0x8(%rbp),%al
and    $0xfd,%al
or     $0x0,%al
mov    %al,-0x8(%rbp)
mov    -0x8(%rbp),%al
shl    $0x7,%al
sar    $0x7,%al
movsbl %al,%eax
cmp    $0x0,%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    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x20,%esi
call   1050 <print_binary@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_anonymous_narrow>:
push   %rax
lea    0xf39(%rip),%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rdi
mov    $0x20,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    $0x20,%esi
call   1060 <print_binary@plt>
xor    %edi,%edi
call   1050 <assert@plt>
xor    %edi,%edi
call   1050 <assert@plt>
lea    0xeba(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3,%edi
mov    $0x20,%esi
call   1060 <print_binary@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
mov    $0x20,%esi
pop    %rax
jmp    1060 <print_binary@plt>

LLVM IR (-O0):
%struct.anon = type { i8, [3 x i8] }
@.str = [30 x i8] c"\0A===== test_anonymous_narrow\0A\00"
@.str.1 = [45 x i8] c"Memory size occupied by bitfield : %lu bits\0A\00"
@.str.2 = [28 x i8] c"Memory contents (initial): \00"
@.str.3 = [28 x i8] c"Memory contents (set) : \00"
@.str.4 = [28 x i8] c"Memory contents (cleared): \00"
define void @test_anonymous_narrow() {
%1 = alloca %struct.anon
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i64 32)
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%5 = bitcast %struct.anon* %1 to i32*
%6 = load i32, i32* %5
%7 = call i32 @print_binary(i32 %6, i32 32)
%8 = bitcast %struct.anon* %1 to i8*
%9 = load i8, i8* %8
%10 = and i8 %9, -2
%11 = or i8 %10, 1
store i8 %11, i8* %8
%12 = bitcast %struct.anon* %1 to i8*
%13 = load i8, i8* %12
%14 = and i8 %13, -3
%15 = or i8 %14, 2
store i8 %15, i8* %12
%16 = bitcast %struct.anon* %1 to i8*
%17 = load i8, i8* %16
%18 = shl i8 %17, 7
%19 = ashr i8 %18, 7
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 1
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = bitcast %struct.anon* %1 to i8*
%25 = load i8, i8* %24
%26 = shl i8 %25, 6
%27 = ashr i8 %26, 7
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 1
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%33 = bitcast %struct.anon* %1 to i32*
%34 = load i32, i32* %33
%35 = call i32 @print_binary(i32 %34, i32 32)
%36 = bitcast %struct.anon* %1 to i8*
%37 = load i8, i8* %36
%38 = and i8 %37, -2
%39 = or i8 %38, 0
store i8 %39, i8* %36
%40 = bitcast %struct.anon* %1 to i8*
%41 = load i8, i8* %40
%42 = and i8 %41, -3
%43 = or i8 %42, 0
store i8 %43, i8* %40
%44 = bitcast %struct.anon* %1 to i8*
%45 = load i8, i8* %44
%46 = shl i8 %45, 7
%47 = ashr i8 %46, 7
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = bitcast %struct.anon* %1 to i8*
%53 = load i8, i8* %52
%54 = shl i8 %53, 6
%55 = ashr i8 %54, 7
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 0
%58 = zext i1 %57 to i32
%59 = call i32 @assert(i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%61 = bitcast %struct.anon* %1 to i32*
%62 = load i32, i32* %61
%63 = call i32 @print_binary(i32 %62, i32 32)
ret void
}

LLVM IR (-O2):
@.str.1 = [45 x i8] c"Memory size occupied by bitfield : %lu bits\0A\00"
@.str.2 = [28 x i8] c"Memory contents (initial): \00"
@.str.3 = [28 x i8] c"Memory contents (set) : \00"
@.str.4 = [28 x i8] c"Memory contents (cleared): \00"
@str = [29 x i8] c"\0A===== test_anonymous_narrow\00"
define void @test_anonymous_narrow() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i64 32)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 @print_binary(i32 0, i32 32)
%5 = tail call i32 @assert(i32 0)
%6 = tail call i32 @assert(i32 0)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @print_binary(i32 3, i32 32)
%9 = tail call i32 @assert(i32 1)
%10 = tail call i32 @assert(i32 1)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i32 @print_binary(i32 0, i32 32)
ret void
}