#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 *);
scalar_t__ cba_get(struct bitarray *, int);
int /*<<< orphan*/ printf(char *, ...);
int test_cba_clear(void) {
  struct bitarray *ba = NULL;
  {
    int i;
    ba = cba_alloc(100);
    for (i = 0; i < 100; i++) {
      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_cba_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    123c <test_cba_clear+0xec>
jmp    1184 <test_cba_clear+0x34>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <cba_clear@plt>
cmp    $0x0,%rax
jge    11cf <test_cba_clear+0x7f>
lea    0xe5f(%rip),%rdi
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11c3 <test_cba_clear+0x73>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1265 <test_cba_clear+0x115>
jmp    11d4 <test_cba_clear+0x84>
jmp    11d9 <test_cba_clear+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cba_get@plt>
cmp    $0x0,%rax
je     1224 <test_cba_clear+0xd4>
lea    0xe2b(%rip),%rdi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1218 <test_cba_clear+0xc8>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1265 <test_cba_clear+0x115>
jmp    1229 <test_cba_clear+0xd9>
jmp    122e <test_cba_clear+0xde>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <test_cba_clear+0x25>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     125e <test_cba_clear+0x10e>
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_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   1080 <cba_clear@plt>
test   %rax,%rax
js     11be <test_cba_clear+0x5e>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <cba_get@plt>
test   %rax,%rax
jne    11ce <test_cba_clear+0x6e>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1180 <test_cba_clear+0x20>
lea    0xe97(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
jne    11ea <test_cba_clear+0x8a>
jmp    11f2 <test_cba_clear+0x92>
lea    0xe3b(%rip),%rdi
lea    0xe40(%rip),%rsi
jmp    11dc <test_cba_clear+0x7c>
lea    0xe4c(%rip),%rdi
lea    0xe54(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     11f2 <test_cba_clear+0x92>
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 = [21 x i8] c"cba_clear(ba, i) < 0\00"
@.str.2 = [15 x i8] c"FAILED: !(%s)\0A\00"
@.str.3 = [20 x i8] c"cba_get(ba, i) == 0\00"
@.str.4 = [8 x i8] c"PASSED\0A\00"
define i32 @test_cba_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 = %39, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %42
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_clear(%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 ([21 x i8], [21 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 %50
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_get(%struct.bitarray* %25, i32 %26)
%28 = icmp eq i64 %27, 0
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 %50
37: ; preds = %24
br label %38
38: ; preds = %37
br label %39
39: ; preds = %38
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %5
42: ; preds = %5
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%44 = load %struct.bitarray*, %struct.bitarray** %2
%45 = icmp ne %struct.bitarray* %44, null
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load %struct.bitarray*, %struct.bitarray** %2
%48 = call i32 @cba_free(%struct.bitarray* %47)
br label %49
49: ; preds = %46, %42
store i32 1, i32* %1
br label %50
50: ; preds = %49, %36, %21
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
%struct.bitarray = type { i32 }
@.str = [12 x i8] c"FAILED: %s\0A\00"
@.str.1 = [21 x i8] c"cba_clear(ba, i) < 0\00"
@.str.2 = [15 x i8] c"FAILED: !(%s)\0A\00"
@.str.3 = [20 x i8] c"cba_get(ba, i) == 0\00"
@str = [7 x i8] c"PASSED\00"
define i32 @test_cba_clear() {
%1 = tail call %struct.bitarray* @cba_alloc(i32 100)
br label %5
2: ; preds = %12
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 100
br i1 %4, label %18, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call i64 @cba_clear(%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 ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq %struct.bitarray* %1, null
br i1 %11, label %24, label %21
12: ; preds = %5
%13 = tail call i64 @cba_get(%struct.bitarray* %1, i32 %6)
%14 = icmp eq i64 %13, 0
br i1 %14, label %2, 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 %24, label %21
18: ; preds = %2
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%20 = icmp eq %struct.bitarray* %1, null
br i1 %20, label %24, label %21
21: ; preds = %18, %15, %9
%22 = phi i32 [ 0, %9 ], [ 0, %15 ], [ 1, %18 ]
%23 = tail call i32 @cba_free(%struct.bitarray* %1)
br label %24
24: ; preds = %21, %15, %9, %18
%25 = phi i32 [ 1, %18 ], [ 0, %9 ], [ 0, %15 ], [ %22, %21 ]
ret i32 %25
}