#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 */
struct bitfield {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bfdel(struct bitfield *);
struct bitfield *bfnew_quick(unsigned int);
unsigned int bfsize(struct bitfield *);
int /*<<< orphan*/ printf(char *, ...);
unsigned int strlen(char *);
int main() {
  unsigned int i;
  unsigned int len = 80;
  char *msg = "Testing bfsize()";
  char *failed = "[FAIL]";
  char *passed = "[PASS]";
  unsigned int dots = len - strlen(msg) - 6;
  printf("%s", msg);
  for (i = 0; i < dots; i++)
    printf(".");
  for (i = 1; i <= len; i++) {
    struct bitfield *input = bfnew_quick(i);
    if (bfsize(input) != i) {
      printf("%s\n", failed);
      bfdel(input);
      return 1;
    } else
      bfdel(input);
  }
  printf("%s\n", passed);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x50,-0xc(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe95(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
sub    %ecx,%eax
sub    $0x6,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jae    11e4 <main+0x94>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11bc <main+0x6c>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     1258 <main+0x108>
mov    -0x8(%rbp),%edi
call   1030 <bfnew_quick@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1070 <bfsize@plt>
cmp    -0x8(%rbp),%eax
je     123c <main+0xec>
mov    -0x20(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1060 <bfdel@plt>
movl   $0x1,-0x4(%rbp)
jmp    1271 <main+0x121>
mov    -0x38(%rbp),%rdi
call   1060 <bfdel@plt>
jmp    124a <main+0xfa>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11eb <main+0x9b>
mov    -0x28(%rbp),%rsi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xe93(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x4a,%ebx
je     11ae <main+0x3e>
add    $0xffffffb6,%ebx
xchg   %ax,%ax
mov    $0x2e,%edi
call   1030 <putchar@plt>
inc    %ebx
jne    11a0 <main+0x30>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%edi
call   1040 <bfnew_quick@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <bfsize@plt>
cmp    %eax,%ebx
jne    11f6 <main+0x86>
mov    %r14,%rdi
call   1080 <bfdel@plt>
add    $0x1,%ebx
cmp    $0x51,%ebx
jne    11c0 <main+0x50>
lea    0xe2b(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
jmp    120f <main+0x9f>
lea    0xe14(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1080 <bfdel@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.bitfield = type { i32 }
@.str = [17 x i8] c"Testing bfsize()\00"
@.str.1 = [7 x i8] c"[FAIL]\00"
@.str.2 = [7 x i8] c"[PASS]\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.bitfield*
store i32 0, i32* %1
store i32 80, i32* %3
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %6
%9 = load i32, i32* %3
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = sub i32 %9, %11
%13 = sub i32 %12, 6
store i32 %13, i32* %7
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %14)
store i32 0, i32* %2
br label %16
16: ; preds = %22, %0
%17 = load i32, i32* %2
%18 = load i32, i32* %7
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20
%23 = load i32, i32* %2
%24 = add i32 %23, 1
store i32 %24, i32* %2
br label %16
25: ; preds = %16
store i32 1, i32* %2
br label %26
26: ; preds = %46, %25
%27 = load i32, i32* %2
%28 = load i32, i32* %3
%29 = icmp ule i32 %27, %28
br i1 %29, label %30, label %49
30: ; preds = %26
%31 = load i32, i32* %2
%32 = call %struct.bitfield* @bfnew_quick(i32 %31)
store %struct.bitfield* %32, %struct.bitfield** %8
%33 = load %struct.bitfield*, %struct.bitfield** %8
%34 = call i32 @bfsize(%struct.bitfield* %33)
%35 = load i32, i32* %2
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %42
37: ; preds = %30
%38 = load i8*, i8** %5
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = load %struct.bitfield*, %struct.bitfield** %8
%41 = call i32 @bfdel(%struct.bitfield* %40)
store i32 1, i32* %1
br label %52
42: ; preds = %30
%43 = load %struct.bitfield*, %struct.bitfield** %8
%44 = call i32 @bfdel(%struct.bitfield* %43)
br label %45
45: ; preds = %42
br label %46
46: ; preds = %45
%47 = load i32, i32* %2
%48 = add i32 %47, 1
store i32 %48, i32* %2
br label %26
49: ; preds = %26
%50 = load i8*, i8** %6
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %50)
store i32 0, i32* %1
br label %52
52: ; preds = %49, %37
%53 = load i32, i32* %1
ret i32 %53
}

LLVM IR (-O2):
%struct.bitfield = type { i32 }
@.str = [17 x i8] c"Testing bfsize()\00"
@.str.1 = [7 x i8] c"[FAIL]\00"
@.str.2 = [7 x i8] c"[PASS]\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %1, 74
br i1 %3, label %11, label %4
4: ; preds = %0
%5 = sub i32 74, %1
br label %6
6: ; preds = %4, %6
%7 = phi i32 [ %9, %6 ], [ 0, %4 ]
%8 = tail call i32 @putchar(i32 46)
%9 = add nuw i32 %7, 1
%10 = icmp eq i32 %9, %5
br i1 %10, label %11, label %6
11: ; preds = %6, %0
br label %12
12: ; preds = %11, %20
%13 = phi i32 [ %22, %20 ], [ 1, %11 ]
%14 = tail call %struct.bitfield* @bfnew_quick(i32 %13)
%15 = tail call i32 @bfsize(%struct.bitfield* %14)
%16 = icmp eq i32 %15, %13
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @bfdel(%struct.bitfield* %14)
br label %26
20: ; preds = %12
%21 = tail call i32 @bfdel(%struct.bitfield* %14)
%22 = add nuw nsw i32 %13, 1
%23 = icmp eq i32 %22, 81
br i1 %23, label %24, label %12
24: ; preds = %20
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %17, %24
%27 = phi i32 [ 1, %17 ], [ 0, %24 ]
ret i32 %27
}