#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 *);
int cba_get(struct bitarray *, int);
int /*<<< orphan*/ cba_set_all(struct bitarray *);
int /*<<< orphan*/ printf(char *, ...);
int test_set_all_then_clear_all(void) {
  struct bitarray *ba = NULL;
  {
    int i;
    ba = cba_alloc(100);
    cba_set_all(ba);
    for (i = 0; i < 100; i++) {
      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);
    }
    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_set_all_then_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   1080 <cba_set_all@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11ff <test_set_all_then_clear_all+0x9f>
jmp    119d <test_set_all_then_clear_all+0x3d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cba_get@plt>
cmp    $0x1,%eax
je     11e7 <test_set_all_then_clear_all+0x87>
lea    0xe47(%rip),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11db <test_set_all_then_clear_all+0x7b>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a9 <test_set_all_then_clear_all+0x149>
jmp    11ec <test_set_all_then_clear_all+0x8c>
jmp    11f1 <test_set_all_then_clear_all+0x91>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118e <test_set_all_then_clear_all+0x2e>
mov    -0x10(%rbp),%rdi
call   1070 <cba_clear_all@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    1280 <test_set_all_then_clear_all+0x120>
jmp    121e <test_set_all_then_clear_all+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <cba_get@plt>
cmp    $0x0,%eax
je     1268 <test_set_all_then_clear_all+0x108>
lea    0xdc6(%rip),%rdi
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     125c <test_set_all_then_clear_all+0xfc>
mov    -0x10(%rbp),%rdi
call   1060 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a9 <test_set_all_then_clear_all+0x149>
jmp    126d <test_set_all_then_clear_all+0x10d>
jmp    1272 <test_set_all_then_clear_all+0x112>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    120f <test_set_all_then_clear_all+0xaf>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     12a2 <test_set_all_then_clear_all+0x142>
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_all_then_clear_all>:
push   %rbp
push   %rbx
push   %rax
mov    $0x64,%edi
call   1040 <cba_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <cba_set_all@plt>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <cba_get@plt>
cmp    $0x1,%eax
jne    11ee <test_set_all_then_clear_all+0x7e>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1190 <test_set_all_then_clear_all+0x20>
mov    %rbx,%rdi
call   1080 <cba_clear_all@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <cba_get@plt>
test   %eax,%eax
jne    11fe <test_set_all_then_clear_all+0x8e>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    11c0 <test_set_all_then_clear_all+0x50>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
jne    121a <test_set_all_then_clear_all+0xaa>
jmp    1222 <test_set_all_then_clear_all+0xb2>
lea    0xe0b(%rip),%rdi
lea    0xe13(%rip),%rsi
jmp    120c <test_set_all_then_clear_all+0x9c>
lea    0xdfb(%rip),%rdi
lea    0xe17(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
test   %rbx,%rbx
je     1222 <test_set_all_then_clear_all+0xb2>
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) == 1\00"
@.str.2 = [20 x i8] c"cba_get(ba, i) == 0\00"
@.str.3 = [8 x i8] c"PASSED\0A\00"
define i32 @test_set_all_then_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_set_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 i32 @cba_get(%struct.bitarray* %12, i32 %13)
%15 = icmp eq i32 %14, 1
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 %62
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 = load %struct.bitarray*, %struct.bitarray** %2
%31 = call i32 @cba_clear_all(%struct.bitarray* %30)
store i32 0, i32* %3
br label %32
32: ; preds = %51, %29
%33 = load i32, i32* %3
%34 = icmp slt i32 %33, 100
br i1 %34, label %35, label %54
35: ; preds = %32
br label %36
36: ; preds = %35
%37 = load %struct.bitarray*, %struct.bitarray** %2
%38 = load i32, i32* %3
%39 = call i32 @cba_get(%struct.bitarray* %37, i32 %38)
%40 = icmp eq i32 %39, 0
br i1 %40, label %49, label %41
41: ; preds = %36
%42 = 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.2, i64 0, i64 0))
%43 = load %struct.bitarray*, %struct.bitarray** %2
%44 = icmp ne %struct.bitarray* %43, null
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load %struct.bitarray*, %struct.bitarray** %2
%47 = call i32 @cba_free(%struct.bitarray* %46)
br label %48
48: ; preds = %45, %41
store i32 0, i32* %1
br label %62
49: ; preds = %36
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
store i32 %53, i32* %3
br label %32
54: ; preds = %32
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%56 = load %struct.bitarray*, %struct.bitarray** %2
%57 = icmp ne %struct.bitarray* %56, null
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = load %struct.bitarray*, %struct.bitarray** %2
%60 = call i32 @cba_free(%struct.bitarray* %59)
br label %61
61: ; preds = %58, %54
store i32 1, i32* %1
br label %62
62: ; preds = %61, %48, %23
%63 = load i32, i32* %1
ret i32 %63
}

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) == 1\00"
@.str.2 = [20 x i8] c"cba_get(ba, i) == 0\00"
@str = [7 x i8] c"PASSED\00"
define i32 @test_set_all_then_clear_all() {
%1 = tail call %struct.bitarray* @cba_alloc(i32 100)
%2 = tail call i32 @cba_set_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 i32 @cba_get(%struct.bitarray* %1, i32 %7)
%9 = icmp eq i32 %8, 1
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 %31, label %28
13: ; preds = %3
%14 = tail call i32 @cba_clear_all(%struct.bitarray* %1)
br label %18
15: ; preds = %18
%16 = add nuw nsw i32 %19, 1
%17 = icmp eq i32 %16, 100
br i1 %17, label %25, label %18
18: ; preds = %13, %15
%19 = phi i32 [ 0, %13 ], [ %16, %15 ]
%20 = tail call i32 @cba_get(%struct.bitarray* %1, i32 %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %15, label %22
22: ; preds = %18
%23 = 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.2, i64 0, i64 0))
%24 = icmp eq %struct.bitarray* %1, null
br i1 %24, label %31, label %28
25: ; preds = %15
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%27 = icmp eq %struct.bitarray* %1, null
br i1 %27, label %31, label %28
28: ; preds = %25, %22, %10
%29 = phi i32 [ 0, %10 ], [ 0, %22 ], [ 1, %25 ]
%30 = tail call i32 @cba_free(%struct.bitarray* %1)
br label %31
31: ; preds = %28, %22, %10, %25
%32 = phi i32 [ 1, %25 ], [ 0, %10 ], [ 0, %22 ], [ %29, %28 ]
ret i32 %32
}