#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 */
struct bitfield *bfclone(struct bitfield *);
int bfcmp(struct bitfield *, struct bitfield *, int /*<<< orphan*/ *);
int bfcpy(struct bitfield *, struct bitfield *);
int /*<<< orphan*/ bfdel(struct bitfield *);
struct bitfield *bfnew_quick(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ srand(unsigned int);
struct bitfield *str2bf(char *);
int strlen(char *);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  srand((unsigned)time(NULL));
  int i, cmp;
  int len = 80;
  char *msg = "Testing bfclone() and bfcpy()";
  char *failed = "[FAIL]";
  char *passed = "[PASS]";
  int dots = len - strlen(msg) - 6;
  printf("%s", msg);
  for (i = 0; i < dots; i++)
    printf(".");
  char *input_char = malloc((len + 1) * sizeof(char));
  for (i = 0; i < len; i++) {
    if (rand() % 2)
      input_char[i] = '1';
    else
      input_char[i] = '0';
  }
  input_char[len] = '\0';
  struct bitfield *input = str2bf(input_char);
  free(input_char);
  struct bitfield *input2 = bfclone(input);
  cmp = bfcmp(input, input2, NULL);
  bfdel(input2);
  if (cmp != 0) {
    printf("zyu1");
    printf("%s\n", failed);
    return 1;
  }
  struct bitfield *input3 = bfnew_quick(len);
  int result = bfcpy(input, input3);
  if (result != 0) {
    printf("zyu2");
    printf("%s\n", failed);
    return 1;
  }
  cmp = bfcmp(input, input3, NULL);
  bfdel(input);
  bfdel(input3);
  if (cmp != 0) {
    printf("zyu3");
    printf("%s\n", failed);
    return 1;
  }
  printf("%s\n", passed);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
movl   $0x50,-0x10(%rbp)
lea    0xe03(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe16(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe12(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
sub    %ecx,%eax
sub    $0x6,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1274 <main+0xa4>
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    124c <main+0x7c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12e6 <main+0x116>
mov    $0x0,%al
call   10f0 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12c7 <main+0xf7>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    12d3 <main+0x103>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    12d8 <main+0x108>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1292 <main+0xc2>
mov    -0x38(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
call   10d0 <str2bf@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1080 <bfclone@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <bfcmp@plt>
mov    %eax,-0xc(%rbp)
mov    -0x48(%rbp),%rdi
call   10e0 <bfdel@plt>
cmpl   $0x0,-0xc(%rbp)
je     1368 <main+0x198>
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    142f <main+0x25f>
mov    -0x10(%rbp),%edi
call   1040 <bfnew_quick@plt>
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1050 <bfcpy@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     13ba <main+0x1ea>
lea    0xca5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xc8f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    142f <main+0x25f>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10a0 <bfcmp@plt>
mov    %eax,-0xc(%rbp)
mov    -0x40(%rbp),%rdi
call   10e0 <bfdel@plt>
mov    -0x50(%rbp),%rdi
call   10e0 <bfdel@plt>
cmpl   $0x0,-0xc(%rbp)
je     1416 <main+0x246>
lea    0xc4e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xc33(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    142f <main+0x25f>
mov    -0x28(%rbp),%rsi
lea    0xc15(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   10d0 <time@plt>
mov    %eax,%edi
call   10b0 <srand@plt>
lea    0xdf4(%rip),%r14
mov    %r14,%rdi
call   1080 <strlen@plt>
mov    %eax,%ebx
mov    $0x4a,%ebp
sub    %eax,%ebp
lea    0xe08(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
test   %ebp,%ebp
jle    124e <main+0x5e>
add    $0xffffffb6,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2e,%edi
call   1040 <putchar@plt>
inc    %ebx
jne    1240 <main+0x50>
mov    $0x51,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
nopl   (%rax)
xor    %eax,%eax
call   1110 <rand@plt>
and    $0x1,%al
or     $0x30,%al
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    $0x50,%rbp
jne    1260 <main+0x70>
movb   $0x0,0x50(%rbx)
mov    %rbx,%rdi
call   10f0 <str2bf@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   10a0 <bfclone@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
xor    %edx,%edx
call   10c0 <bfcmp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1100 <bfdel@plt>
test   %ebp,%ebp
je     12be <main+0xce>
lea    0xd73(%rip),%rdi
jmp    1310 <main+0x120>
mov    $0x50,%edi
call   1050 <bfnew_quick@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1070 <bfcpy@plt>
test   %eax,%eax
je     12e3 <main+0xf3>
lea    0xd53(%rip),%rdi
jmp    1310 <main+0x120>
xor    %r14d,%r14d
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   10c0 <bfcmp@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1100 <bfdel@plt>
mov    %rbx,%rdi
call   1100 <bfdel@plt>
test   %ebp,%ebp
je     1337 <main+0x147>
lea    0xd29(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%r14d
lea    0xcfa(%rip),%rdi
call   1060 <puts@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce7(%rip),%rdi
jmp    1324 <main+0x134>

LLVM IR (-O0):
%struct.bitfield = type { i32 }
@.str = [30 x i8] c"Testing bfclone() and bfcpy()\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 = [5 x i8] c"zyu1\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [5 x i8] c"zyu2\00"
@.str.8 = [5 x i8] c"zyu3\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.bitfield*
%11 = alloca %struct.bitfield*
%12 = alloca %struct.bitfield*
%13 = alloca i32
store i32 0, i32* %1
%14 = call i64 @time(i32* null)
%15 = trunc i64 %14 to i32
%16 = call i32 @srand(i32 %15)
store i32 80, i32* %4
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %7
%17 = load i32, i32* %4
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %17, %19
%21 = sub nsw i32 %20, 6
store i32 %21, i32* %8
%22 = load i8*, i8** %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %22)
store i32 0, i32* %2
br label %24
24: ; preds = %30, %0
%25 = load i32, i32* %2
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
br label %24
33: ; preds = %24
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = mul i64 %36, 1
%38 = trunc i64 %37 to i32
%39 = call i8* @malloc(i32 %38)
store i8* %39, i8** %9
store i32 0, i32* %2
br label %40
40: ; preds = %59, %33
%41 = load i32, i32* %2
%42 = load i32, i32* %4
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %62
44: ; preds = %40
%45 = call i32 (...) @rand()
%46 = srem i32 %45, 2
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i8*, i8** %9
%50 = load i32, i32* %2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 49, i8* %52
br label %58
53: ; preds = %44
%54 = load i8*, i8** %9
%55 = load i32, i32* %2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 48, i8* %57
br label %58
58: ; preds = %53, %48
br label %59
59: ; preds = %58
%60 = load i32, i32* %2
%61 = add nsw i32 %60, 1
store i32 %61, i32* %2
br label %40
62: ; preds = %40
%63 = load i8*, i8** %9
%64 = load i32, i32* %4
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
%67 = load i8*, i8** %9
%68 = call %struct.bitfield* @str2bf(i8* %67)
store %struct.bitfield* %68, %struct.bitfield** %10
%69 = load i8*, i8** %9
%70 = call i32 @free(i8* %69)
%71 = load %struct.bitfield*, %struct.bitfield** %10
%72 = call %struct.bitfield* @bfclone(%struct.bitfield* %71)
store %struct.bitfield* %72, %struct.bitfield** %11
%73 = load %struct.bitfield*, %struct.bitfield** %10
%74 = load %struct.bitfield*, %struct.bitfield** %11
%75 = call i32 @bfcmp(%struct.bitfield* %73, %struct.bitfield* %74, i32* null)
store i32 %75, i32* %3
%76 = load %struct.bitfield*, %struct.bitfield** %11
%77 = call i32 @bfdel(%struct.bitfield* %76)
%78 = load i32, i32* %3
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %62
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%82 = load i8*, i8** %6
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %82)
store i32 1, i32* %1
br label %113
84: ; preds = %62
%85 = load i32, i32* %4
%86 = call %struct.bitfield* @bfnew_quick(i32 %85)
store %struct.bitfield* %86, %struct.bitfield** %12
%87 = load %struct.bitfield*, %struct.bitfield** %10
%88 = load %struct.bitfield*, %struct.bitfield** %12
%89 = call i32 @bfcpy(%struct.bitfield* %87, %struct.bitfield* %88)
store i32 %89, i32* %13
%90 = load i32, i32* %13
%91 = icmp ne i32 %90, 0
br i1 %91, label %92, label %96
92: ; preds = %84
%93 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%94 = load i8*, i8** %6
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %94)
store i32 1, i32* %1
br label %113
96: ; preds = %84
%97 = load %struct.bitfield*, %struct.bitfield** %10
%98 = load %struct.bitfield*, %struct.bitfield** %12
%99 = call i32 @bfcmp(%struct.bitfield* %97, %struct.bitfield* %98, i32* null)
store i32 %99, i32* %3
%100 = load %struct.bitfield*, %struct.bitfield** %10
%101 = call i32 @bfdel(%struct.bitfield* %100)
%102 = load %struct.bitfield*, %struct.bitfield** %12
%103 = call i32 @bfdel(%struct.bitfield* %102)
%104 = load i32, i32* %3
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %110
106: ; preds = %96
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%108 = load i8*, i8** %6
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %108)
store i32 1, i32* %1
br label %113
110: ; preds = %96
%111 = load i8*, i8** %7
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %111)
store i32 0, i32* %1
br label %113
113: ; preds = %110, %106, %92, %80
%114 = load i32, i32* %1
ret i32 %114
}

LLVM IR (-O2):
%struct.bitfield = type { i32 }
@.str = [30 x i8] c"Testing bfclone() and bfcpy()\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.5 = [5 x i8] c"zyu1\00"
@.str.7 = [5 x i8] c"zyu2\00"
@.str.8 = [5 x i8] c"zyu3\00"
define i32 @main() {
%1 = tail call i64 @time(i32* null)
%2 = trunc i64 %1 to i32
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%5 = sub i32 74, %4
%6 = 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 ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = icmp sgt i32 %5, 0
br i1 %7, label %8, label %13
8: ; preds = %0, %8
%9 = phi i32 [ %11, %8 ], [ 0, %0 ]
%10 = tail call i32 @putchar(i32 46)
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, %5
br i1 %12, label %13, label %8
13: ; preds = %8, %0
%14 = tail call dereferenceable_or_null(81) i8* @malloc(i32 81)
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %22, %15 ]
%17 = tail call i32 (...) @rand()
%18 = and i32 %17, 1
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8 48, i8 49
%21 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 %20, i8* %21
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, 80
br i1 %23, label %24, label %15
24: ; preds = %15
%25 = getelementptr inbounds i8, i8* %14, i64 80
store i8 0, i8* %25
%26 = tail call %struct.bitfield* @str2bf(i8* %14)
%27 = tail call i32 @free(i8* %14)
%28 = tail call %struct.bitfield* @bfclone(%struct.bitfield* %26)
%29 = tail call i32 @bfcmp(%struct.bitfield* %26, %struct.bitfield* %28, i32* null)
%30 = tail call i32 @bfdel(%struct.bitfield* %28)
%31 = icmp eq i32 %29, 0
br i1 %31, label %32, label %41
32: ; preds = %24
%33 = tail call %struct.bitfield* @bfnew_quick(i32 80)
%34 = tail call i32 @bfcpy(%struct.bitfield* %26, %struct.bitfield* %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = tail call i32 @bfcmp(%struct.bitfield* %26, %struct.bitfield* %33, i32* null)
%38 = tail call i32 @bfdel(%struct.bitfield* %26)
%39 = tail call i32 @bfdel(%struct.bitfield* %33)
%40 = icmp eq i32 %37, 0
br i1 %40, label %44, label %41
41: ; preds = %36, %32, %24
%42 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %24 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), %32 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), %36 ]
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %42)
br label %44
44: ; preds = %41, %36
%45 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %36 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %41 ]
%46 = phi i32 [ 0, %36 ], [ 1, %41 ]
%47 = tail call i32 @puts(i8* dereferenceable(1) %45)
ret i32 %46
}