#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);
scalar_t__ cba_clear(struct bitarray *, 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_set_then_clear(void) {
  struct bitarray *ba = NULL;
  {
    int i;
    ba = cba_alloc(100);
    for (i = 0; i < 100; i++) {
      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);
      do {
        if (cba_clear(ba, i) < 0) {
          printf("FAILED: %s\n", "cba_clear(ba, i) < 0");
          if (ba)
            cba_free(ba);
          return 0;
        }
      } while (0);
      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);
    }
  }
  printf("PASSED\n");
  if (ba)
    cba_free(ba);
  return 1;
}


x86 assembly (clang, -O0):
<test_set_then_clear>:
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    12f4 <test_set_then_clear+0x194>
jmp    1194 <test_set_then_clear+0x34>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1080 <cba_set@plt>
cmp    $0x0,%rax
jge    11df <test_set_then_clear+0x7f>
lea    0xe4f(%rip),%rdi
lea    0xe54(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11d3 <test_set_then_clear+0x73>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    131d <test_set_then_clear+0x1bd>
jmp    11e4 <test_set_then_clear+0x84>
jmp    11e9 <test_set_then_clear+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cba_get@plt>
cmp    $0x1,%eax
je     1233 <test_set_then_clear+0xd3>
lea    0xe1a(%rip),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1227 <test_set_then_clear+0xc7>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    131d <test_set_then_clear+0x1bd>
jmp    1238 <test_set_then_clear+0xd8>
jmp    123d <test_set_then_clear+0xdd>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <cba_clear@plt>
cmp    $0x0,%rax
jge    1288 <test_set_then_clear+0x128>
lea    0xda6(%rip),%rdi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     127c <test_set_then_clear+0x11c>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    131d <test_set_then_clear+0x1bd>
jmp    128d <test_set_then_clear+0x12d>
jmp    1292 <test_set_then_clear+0x132>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cba_get@plt>
cmp    $0x0,%eax
je     12dc <test_set_then_clear+0x17c>
lea    0xd71(%rip),%rdi
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     12d0 <test_set_then_clear+0x170>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    131d <test_set_then_clear+0x1bd>
jmp    12e1 <test_set_then_clear+0x181>
jmp    12e6 <test_set_then_clear+0x186>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1185 <test_set_then_clear+0x25>
lea    0xd70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1316 <test_set_then_clear+0x1b6>
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_set_then_clear>:
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   1090 <cba_set@plt>
test   %rax,%rax
js     11eb <test_set_then_clear+0x7b>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <cba_get@plt>
cmp    $0x1,%eax
jne    11fb <test_set_then_clear+0x8b>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1080 <cba_clear@plt>
test   %rax,%rax
js     120b <test_set_then_clear+0x9b>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <cba_get@plt>
test   %eax,%eax
jne    121b <test_set_then_clear+0xab>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1190 <test_set_then_clear+0x20>
lea    0xe91(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
jne    1237 <test_set_then_clear+0xc7>
jmp    123f <test_set_then_clear+0xcf>
lea    0xe0e(%rip),%rdi
lea    0xe13(%rip),%rsi
jmp    1229 <test_set_then_clear+0xb9>
lea    0xe1d(%rip),%rdi
lea    0xe25(%rip),%rsi
jmp    1229 <test_set_then_clear+0xb9>
lea    0xdee(%rip),%rdi
lea    0xe29(%rip),%rsi
jmp    1229 <test_set_then_clear+0xb9>
lea    0xdfd(%rip),%rdi
lea    0xe2e(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     123f <test_set_then_clear+0xcf>
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 = [12 x i8] c"FAILED: %s\0A\00"
@.str.1 = [19 x i8] c"cba_set(ba, i) < 0\00"
@.str.2 = [15 x i8] c"FAILED: !(%s)\0A\00"
@.str.3 = [20 x i8] c"cba_get(ba, i) == 1\00"
@.str.4 = [21 x i8] c"cba_clear(ba, i) < 0\00"
@.str.5 = [20 x i8] c"cba_get(ba, i) == 0\00"
@.str.6 = [8 x i8] c"PASSED\0A\00"
define i32 @test_set_then_clear() {
%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 = %69, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %72
8: ; preds = %5
br label %9
9: ; preds = %8
%10 = load %struct.bitarray*, %struct.bitarray** %2
%11 = load i32, i32* %3
%12 = call i64 @cba_set(%struct.bitarray* %10, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 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 %80
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 i32 @cba_get(%struct.bitarray* %25, i32 %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %37, label %29
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 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 %80
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 i64 @cba_clear(%struct.bitarray* %40, i32 %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %39
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 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 %80
52: ; preds = %39
br label %53
53: ; preds = %52
br label %54
54: ; preds = %53
%55 = load %struct.bitarray*, %struct.bitarray** %2
%56 = load i32, i32* %3
%57 = call i32 @cba_get(%struct.bitarray* %55, i32 %56)
%58 = icmp eq i32 %57, 0
br i1 %58, label %67, label %59
59: ; preds = %54
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%61 = load %struct.bitarray*, %struct.bitarray** %2
%62 = icmp ne %struct.bitarray* %61, null
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load %struct.bitarray*, %struct.bitarray** %2
%65 = call i32 @cba_free(%struct.bitarray* %64)
br label %66
66: ; preds = %63, %59
store i32 0, i32* %1
br label %80
67: ; preds = %54
br label %68
68: ; preds = %67
br label %69
69: ; preds = %68
%70 = load i32, i32* %3
%71 = add nsw i32 %70, 1
store i32 %71, i32* %3
br label %5
72: ; preds = %5
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%74 = load %struct.bitarray*, %struct.bitarray** %2
%75 = icmp ne %struct.bitarray* %74, null
br i1 %75, label %76, label %79
76: ; preds = %72
%77 = load %struct.bitarray*, %struct.bitarray** %2
%78 = call i32 @cba_free(%struct.bitarray* %77)
br label %79
79: ; preds = %76, %72
store i32 1, i32* %1
br label %80
80: ; preds = %79, %66, %51, %36, %21
%81 = load i32, i32* %1
ret i32 %81
}

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