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


x86 assembly (clang, -O0):
<test_allocated_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    11d7 <test_allocated_clear+0x97>
jmp    1174 <test_allocated_clear+0x34>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cba_get@plt>
cmp    $0x0,%rax
je     11bf <test_allocated_clear+0x7f>
lea    0xe6f(%rip),%rdi
lea    0xe74(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11b3 <test_allocated_clear+0x73>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1200 <test_allocated_clear+0xc0>
jmp    11c4 <test_allocated_clear+0x84>
jmp    11c9 <test_allocated_clear+0x89>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <test_allocated_clear+0x25>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11f9 <test_allocated_clear+0xb9>
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_allocated_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   1050 <cba_get@plt>
test   %rax,%rax
jne    119f <test_allocated_clear+0x4f>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1170 <test_allocated_clear+0x20>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
jne    11bb <test_allocated_clear+0x6b>
jmp    11c3 <test_allocated_clear+0x73>
lea    0xe5a(%rip),%rdi
lea    0xe5f(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     11c3 <test_allocated_clear+0x73>
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 = [15 x i8] c"cba_get(ba, i)\00"
@.str.2 = [8 x i8] c"PASSED\0A\00"
define i32 @test_allocated_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 = %24, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %27
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_get(%struct.bitarray* %10, i32 %11)
%13 = icmp ne 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 ([15 x i8], [15 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 %35
22: ; preds = %9
br label %23
23: ; preds = %22
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %5
27: ; preds = %5
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%29 = load %struct.bitarray*, %struct.bitarray** %2
%30 = icmp ne %struct.bitarray* %29, null
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load %struct.bitarray*, %struct.bitarray** %2
%33 = call i32 @cba_free(%struct.bitarray* %32)
br label %34
34: ; preds = %31, %27
store i32 1, i32* %1
br label %35
35: ; preds = %34, %21
%36 = load i32, i32* %1
ret i32 %36
}

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