#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 *);
int cba_get(struct bitarray *, int);
int /*<<< orphan*/ cba_toggle_all(struct bitarray *);
int /*<<< orphan*/ printf(char *, ...);
int test_cba_toggle_all(void) {
  struct bitarray *ba = NULL;
  {
    int i;
    ba = cba_alloc(100);
    cba_toggle_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_toggle_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_toggle_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
mov    $0x64,%edi
call   1040 <cba_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <cba_toggle_all@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    11ef <test_cba_toggle_all+0x9f>
jmp    118d <test_cba_toggle_all+0x3d>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <cba_get@plt>
cmp    $0x1,%eax
je     11d7 <test_cba_toggle_all+0x87>
lea    0xe57(%rip),%rdi
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11cb <test_cba_toggle_all+0x7b>
mov    -0x10(%rbp),%rdi
call   1070 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <test_cba_toggle_all+0x149>
jmp    11dc <test_cba_toggle_all+0x8c>
jmp    11e1 <test_cba_toggle_all+0x91>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117e <test_cba_toggle_all+0x2e>
mov    -0x10(%rbp),%rdi
call   1030 <cba_toggle_all@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    1270 <test_cba_toggle_all+0x120>
jmp    120e <test_cba_toggle_all+0xbe>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <cba_get@plt>
cmp    $0x0,%eax
je     1258 <test_cba_toggle_all+0x108>
lea    0xdd6(%rip),%rdi
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     124c <test_cba_toggle_all+0xfc>
mov    -0x10(%rbp),%rdi
call   1070 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <test_cba_toggle_all+0x149>
jmp    125d <test_cba_toggle_all+0x10d>
jmp    1262 <test_cba_toggle_all+0x112>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ff <test_cba_toggle_all+0xaf>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1292 <test_cba_toggle_all+0x142>
mov    -0x10(%rbp),%rdi
call   1070 <cba_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_cba_toggle_all>:
push   %rbp
push   %rbx
push   %rax
mov    $0x64,%edi
call   1050 <cba_alloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <cba_toggle_all@plt>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <cba_get@plt>
cmp    $0x1,%eax
jne    11de <test_cba_toggle_all+0x7e>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1180 <test_cba_toggle_all+0x20>
mov    %rbx,%rdi
call   1030 <cba_toggle_all@plt>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <cba_get@plt>
test   %eax,%eax
jne    11ee <test_cba_toggle_all+0x8e>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    11b0 <test_cba_toggle_all+0x50>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
jne    120a <test_cba_toggle_all+0xaa>
jmp    1212 <test_cba_toggle_all+0xb2>
lea    0xe1b(%rip),%rdi
lea    0xe23(%rip),%rsi
jmp    11fc <test_cba_toggle_all+0x9c>
lea    0xe0b(%rip),%rdi
lea    0xe27(%rip),%rsi
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <printf@plt>
test   %rbx,%rbx
je     1212 <test_cba_toggle_all+0xb2>
mov    %rbx,%rdi
call   1080 <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_cba_toggle_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_toggle_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_toggle_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_cba_toggle_all() {
%1 = tail call %struct.bitarray* @cba_alloc(i32 100)
%2 = tail call i32 @cba_toggle_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_toggle_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
}