#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 bitarray {
  int dummy;
};

/* Variables and functions */
struct bitarray *cba_alloc(int);
int /*<<< orphan*/ cba_free(struct bitarray *);
int cba_get(struct bitarray *, int);
scalar_t__ cba_set(struct bitarray *, int);
int /*<<< orphan*/ printf(char *, ...);
int test_cba_set(void) {
  struct bitarray *ba = NULL;
  {
    int i;
    ba = cba_alloc(100);
    for (i = 0; i < 100; i++) {
      do {
        if (!(cba_get(ba, i) == 0)) {
          printf("FAILED: !(%s)\n", "cba_get(ba, i) == 0");
          if (ba)
            cba_free(ba);
          return 0;
        }
      } while (0);
      do {
        if (cba_set(ba, i) < 0) {
          printf("FAILED: %s\n", "cba_set(ba, i) < 0");
          if (ba)
            cba_free(ba);
          return 0;
        }
      } while (0);
      do {
        if (!(cba_get(ba, i) == 1)) {
          printf("FAILED: !(%s)\n", "cba_get(ba, i) == 1");
          if (ba)
            cba_free(ba);
          return 0;
        }
      } while (0);
    }
  }
  printf("PASSED\n");
  if (ba)
    cba_free(ba);
  return 1;
}


x86 assembly (clang, -O0):
<test_cba_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
mov    $0x64,%edi
call   1030 <cba_alloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    128f <test_cba_set+0x13f>
jmp    1184 <test_cba_set+0x34>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cba_get@plt>
cmp    $0x0,%eax
je     11ce <test_cba_set+0x7e>
lea    0xe60(%rip),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11c2 <test_cba_set+0x72>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b8 <test_cba_set+0x168>
jmp    11d3 <test_cba_set+0x83>
jmp    11d8 <test_cba_set+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <cba_set@plt>
cmp    $0x0,%rax
jge    1223 <test_cba_set+0xd3>
lea    0xe2e(%rip),%rdi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1217 <test_cba_set+0xc7>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b8 <test_cba_set+0x168>
jmp    1228 <test_cba_set+0xd8>
jmp    122d <test_cba_set+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cba_get@plt>
cmp    $0x1,%eax
je     1277 <test_cba_set+0x127>
lea    0xdb7(%rip),%rdi
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     126b <test_cba_set+0x11b>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b8 <test_cba_set+0x168>
jmp    127c <test_cba_set+0x12c>
jmp    1281 <test_cba_set+0x131>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <test_cba_set+0x25>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     12b1 <test_cba_set+0x161>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_cba_set>:
push   %rbp
push   %rbx
push   %rax
mov    $0x64,%edi
call   1040 <cba_alloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <cba_get@plt>
test   %eax,%eax
jne    11cc <test_cba_set+0x6c>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <cba_set@plt>
test   %rax,%rax
js     11dc <test_cba_set+0x7c>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <cba_get@plt>
cmp    $0x1,%eax
jne    11ec <test_cba_set+0x8c>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1180 <test_cba_set+0x20>
lea    0xe9b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
jne    1208 <test_cba_set+0xa8>
jmp    1210 <test_cba_set+0xb0>
lea    0xe2d(%rip),%rdi
lea    0xe35(%rip),%rsi
jmp    11fa <test_cba_set+0x9a>
lea    0xe40(%rip),%rdi
lea    0xe45(%rip),%rsi
jmp    11fa <test_cba_set+0x9a>
lea    0xe0d(%rip),%rdi
lea    0xe48(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     1210 <test_cba_set+0xb0>
mov    %rbx,%rdi
call   1070 <cba_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitarray = type { i32 }
@.str = [15 x i8] c"FAILED: !(%s)\0A\00"
@.str.1 = [20 x i8] c"cba_get(ba, i) == 0\00"
@.str.2 = [12 x i8] c"FAILED: %s\0A\00"
@.str.3 = [19 x i8] c"cba_set(ba, i) < 0\00"
@.str.4 = [20 x i8] c"cba_get(ba, i) == 1\00"
@.str.5 = [8 x i8] c"PASSED\0A\00"
define i32 @test_cba_set() {
%1 = alloca i32
%2 = alloca %struct.bitarray*
%3 = alloca i32
store %struct.bitarray* null, %struct.bitarray** %2
%4 = call %struct.bitarray* @cba_alloc(i32 100)
store %struct.bitarray* %4, %struct.bitarray** %2
store i32 0, i32* %3
br label %5
5: ; preds = %54, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %57
8: ; preds = %5
br label %9
9: ; preds = %8
%10 = load %struct.bitarray*, %struct.bitarray** %2
%11 = load i32, i32* %3
%12 = call i32 @cba_get(%struct.bitarray* %10, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%16 = load %struct.bitarray*, %struct.bitarray** %2
%17 = icmp ne %struct.bitarray* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load %struct.bitarray*, %struct.bitarray** %2
%20 = call i32 @cba_free(%struct.bitarray* %19)
br label %21
21: ; preds = %18, %14
store i32 0, i32* %1
br label %65
22: ; preds = %9
br label %23
23: ; preds = %22
br label %24
24: ; preds = %23
%25 = load %struct.bitarray*, %struct.bitarray** %2
%26 = load i32, i32* %3
%27 = call i64 @cba_set(%struct.bitarray* %25, i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%31 = load %struct.bitarray*, %struct.bitarray** %2
%32 = icmp ne %struct.bitarray* %31, null
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load %struct.bitarray*, %struct.bitarray** %2
%35 = call i32 @cba_free(%struct.bitarray* %34)
br label %36
36: ; preds = %33, %29
store i32 0, i32* %1
br label %65
37: ; preds = %24
br label %38
38: ; preds = %37
br label %39
39: ; preds = %38
%40 = load %struct.bitarray*, %struct.bitarray** %2
%41 = load i32, i32* %3
%42 = call i32 @cba_get(%struct.bitarray* %40, i32 %41)
%43 = icmp eq i32 %42, 1
br i1 %43, label %52, label %44
44: ; preds = %39
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%46 = load %struct.bitarray*, %struct.bitarray** %2
%47 = icmp ne %struct.bitarray* %46, null
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load %struct.bitarray*, %struct.bitarray** %2
%50 = call i32 @cba_free(%struct.bitarray* %49)
br label %51
51: ; preds = %48, %44
store i32 0, i32* %1
br label %65
52: ; preds = %39
br label %53
53: ; preds = %52
br label %54
54: ; preds = %53
%55 = load i32, i32* %3
%56 = add nsw i32 %55, 1
store i32 %56, i32* %3
br label %5
57: ; preds = %5
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%59 = load %struct.bitarray*, %struct.bitarray** %2
%60 = icmp ne %struct.bitarray* %59, null
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = load %struct.bitarray*, %struct.bitarray** %2
%63 = call i32 @cba_free(%struct.bitarray* %62)
br label %64
64: ; preds = %61, %57
store i32 1, i32* %1
br label %65
65: ; preds = %64, %51, %36, %21
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
%struct.bitarray = type { i32 }
@.str = [15 x i8] c"FAILED: !(%s)\0A\00"
@.str.1 = [20 x i8] c"cba_get(ba, i) == 0\00"
@.str.2 = [12 x i8] c"FAILED: %s\0A\00"
@.str.3 = [19 x i8] c"cba_set(ba, i) < 0\00"
@.str.4 = [20 x i8] c"cba_get(ba, i) == 1\00"
@str = [7 x i8] c"PASSED\00"
define i32 @test_cba_set() {
%1 = tail call %struct.bitarray* @cba_alloc(i32 100)
br label %5
2: ; preds = %18
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 100
br i1 %4, label %24, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call i32 @cba_get(%struct.bitarray* %1, i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %5
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq %struct.bitarray* %1, null
br i1 %11, label %30, label %27
12: ; preds = %5
%13 = tail call i64 @cba_set(%struct.bitarray* %1, i32 %6)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq %struct.bitarray* %1, null
br i1 %17, label %30, label %27
18: ; preds = %12
%19 = tail call i32 @cba_get(%struct.bitarray* %1, i32 %6)
%20 = icmp eq i32 %19, 1
br i1 %20, label %2, label %21
21: ; preds = %18
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq %struct.bitarray* %1, null
br i1 %23, label %30, label %27
24: ; preds = %2
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%26 = icmp eq %struct.bitarray* %1, null
br i1 %26, label %30, label %27
27: ; preds = %24, %21, %15, %9
%28 = phi i32 [ 0, %9 ], [ 0, %15 ], [ 0, %21 ], [ 1, %24 ]
%29 = tail call i32 @cba_free(%struct.bitarray* %1)
br label %30
30: ; preds = %27, %21, %15, %9, %24
%31 = phi i32 [ 1, %24 ], [ 0, %9 ], [ 0, %15 ], [ 0, %21 ], [ %28, %27 ]
ret i32 %31
}