#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_clear_all(struct bitarray *);
int /*<<< orphan*/ cba_free(struct bitarray *);
scalar_t__ cba_get(struct bitarray *, int);
int /*<<< orphan*/ printf(char *, ...);
int test_cba_clear_all(void) {
  struct bitarray *ba = NULL;
  {
    int i;
    ba = cba_alloc(100);
    cba_clear_all(ba);
    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);
    }
  }
  printf("PASSED\n");
  if (ba)
    cba_free(ba);
  return 1;
}


x86 assembly (clang, -O0):
<test_cba_clear_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
mov    $0x64,%edi
call   1030 <cba_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <cba_clear_all@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11f0 <test_cba_clear_all+0xa0>
jmp    118d <test_cba_clear_all+0x3d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cba_get@plt>
cmp    $0x0,%rax
je     11d8 <test_cba_clear_all+0x88>
lea    0xe56(%rip),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11cc <test_cba_clear_all+0x7c>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1219 <test_cba_clear_all+0xc9>
jmp    11dd <test_cba_clear_all+0x8d>
jmp    11e2 <test_cba_clear_all+0x92>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117e <test_cba_clear_all+0x2e>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1212 <test_cba_clear_all+0xc2>
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_all>:
push   %rbp
push   %rbx
push   %rax
mov    $0x64,%edi
call   1040 <cba_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <cba_clear_all@plt>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <cba_get@plt>
test   %rax,%rax
jne    11af <test_cba_clear_all+0x4f>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1180 <test_cba_clear_all+0x20>
lea    0xe85(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
jne    11cb <test_cba_clear_all+0x6b>
jmp    11d3 <test_cba_clear_all+0x73>
lea    0xe4a(%rip),%rdi
lea    0xe52(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     11d3 <test_cba_clear_all+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 = [15 x i8] c"FAILED: !(%s)\0A\00"
@.str.1 = [20 x i8] c"cba_get(ba, i) == 0\00"
@.str.2 = [8 x i8] c"PASSED\0A\00"
define i32 @test_cba_clear_all() {
%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
%5 = load %struct.bitarray*, %struct.bitarray** %2
%6 = call i32 @cba_clear_all(%struct.bitarray* %5)
store i32 0, i32* %3
br label %7
7: ; preds = %26, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 100
br i1 %9, label %10, label %29
10: ; preds = %7
br label %11
11: ; preds = %10
%12 = load %struct.bitarray*, %struct.bitarray** %2
%13 = load i32, i32* %3
%14 = call i64 @cba_get(%struct.bitarray* %12, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %11
%17 = 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))
%18 = load %struct.bitarray*, %struct.bitarray** %2
%19 = icmp ne %struct.bitarray* %18, null
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load %struct.bitarray*, %struct.bitarray** %2
%22 = call i32 @cba_free(%struct.bitarray* %21)
br label %23
23: ; preds = %20, %16
store i32 0, i32* %1
br label %37
24: ; preds = %11
br label %25
25: ; preds = %24
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %7
29: ; preds = %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, 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 1, i32* %1
br label %37
37: ; preds = %36, %23
%38 = load i32, i32* %1
ret i32 %38
}

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