#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 /*<<< orphan*/);
int /*<<< orphan*/ cba_toggle(struct bitarray *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int test_cba_toggle(void) {
  struct bitarray *ba = NULL;
  {
    ba = cba_alloc(1);
    do {
      if (!(cba_toggle(ba, 0))) {
        printf("FAILED: !(%s)\n", "cba_toggle(ba, 0)");
        if (ba)
          cba_free(ba);
        return 0;
      }
    } while (0);
    do {
      if (!(cba_get(ba, 0) == 1)) {
        printf("FAILED: !(%s)\n", "cba_get(ba, 0) == 1");
        if (ba)
          cba_free(ba);
        return 0;
      }
    } while (0);
    do {
      if (!(cba_toggle(ba, 0))) {
        printf("FAILED: !(%s)\n", "cba_toggle(ba, 0)");
        if (ba)
          cba_free(ba);
        return 0;
      }
    } while (0);
    do {
      if (!(cba_get(ba, 0) == 0)) {
        printf("FAILED: !(%s)\n", "cba_get(ba, 0) == 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>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x10(%rbp)
mov    $0x1,%edi
call   1030 <cba_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <cba_toggle@plt>
cmp    $0x0,%eax
jne    11b7 <test_cba_toggle+0x67>
lea    0xe77(%rip),%rdi
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11ab <test_cba_toggle+0x5b>
mov    -0x10(%rbp),%rdi
call   1070 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12de <test_cba_toggle+0x18e>
jmp    11bc <test_cba_toggle+0x6c>
jmp    11c1 <test_cba_toggle+0x71>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <cba_get@plt>
cmp    $0x1,%eax
je     120a <test_cba_toggle+0xba>
lea    0xe24(%rip),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11fe <test_cba_toggle+0xae>
mov    -0x10(%rbp),%rdi
call   1070 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12de <test_cba_toggle+0x18e>
jmp    120f <test_cba_toggle+0xbf>
jmp    1214 <test_cba_toggle+0xc4>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <cba_toggle@plt>
cmp    $0x0,%eax
jne    125d <test_cba_toggle+0x10d>
lea    0xdd1(%rip),%rdi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     1251 <test_cba_toggle+0x101>
mov    -0x10(%rbp),%rdi
call   1070 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12de <test_cba_toggle+0x18e>
jmp    1262 <test_cba_toggle+0x112>
jmp    1267 <test_cba_toggle+0x117>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1050 <cba_get@plt>
cmp    $0x0,%eax
je     12b0 <test_cba_toggle+0x160>
lea    0xd7e(%rip),%rdi
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     12a4 <test_cba_toggle+0x154>
mov    -0x10(%rbp),%rdi
call   1070 <cba_free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12de <test_cba_toggle+0x18e>
jmp    12b5 <test_cba_toggle+0x165>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpq   $0x0,-0x10(%rbp)
je     12d7 <test_cba_toggle+0x187>
mov    -0x10(%rbp),%rdi
call   1070 <cba_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_cba_toggle>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1,%edi
call   1040 <cba_alloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <cba_toggle@plt>
test   %eax,%eax
je     11c1 <test_cba_toggle+0x61>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <cba_get@plt>
cmp    $0x1,%eax
jne    11d1 <test_cba_toggle+0x71>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <cba_toggle@plt>
test   %eax,%eax
je     11c1 <test_cba_toggle+0x61>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <cba_get@plt>
test   %eax,%eax
je     11fc <test_cba_toggle+0x9c>
lea    0xe48(%rip),%rdi
lea    0xe76(%rip),%rsi
jmp    11df <test_cba_toggle+0x7f>
lea    0xe38(%rip),%rdi
lea    0xe40(%rip),%rsi
jmp    11df <test_cba_toggle+0x7f>
lea    0xe28(%rip),%rdi
lea    0xe42(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
test   %rbx,%rbx
je     11f3 <test_cba_toggle+0x93>
mov    %rbx,%rdi
call   1080 <cba_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe46(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
test   %rbx,%rbx
jne    11eb <test_cba_toggle+0x8b>
jmp    11f3 <test_cba_toggle+0x93>

LLVM IR (-O0):
%struct.bitarray = type { i32 }
@.str = [15 x i8] c"FAILED: !(%s)\0A\00"
@.str.1 = [18 x i8] c"cba_toggle(ba, 0)\00"
@.str.2 = [20 x i8] c"cba_get(ba, 0) == 1\00"
@.str.3 = [20 x i8] c"cba_get(ba, 0) == 0\00"
@.str.4 = [8 x i8] c"PASSED\0A\00"
define i32 @test_cba_toggle() {
%1 = alloca i32
%2 = alloca %struct.bitarray*
store %struct.bitarray* null, %struct.bitarray** %2
%3 = call %struct.bitarray* @cba_alloc(i32 1)
store %struct.bitarray* %3, %struct.bitarray** %2
br label %4
4: ; preds = %0
%5 = load %struct.bitarray*, %struct.bitarray** %2
%6 = call i32 @cba_toggle(%struct.bitarray* %5, i32 0)
%7 = icmp ne i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%10 = load %struct.bitarray*, %struct.bitarray** %2
%11 = icmp ne %struct.bitarray* %10, null
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load %struct.bitarray*, %struct.bitarray** %2
%14 = call i32 @cba_free(%struct.bitarray* %13)
br label %15
15: ; preds = %12, %8
store i32 0, i32* %1
br label %67
16: ; preds = %4
br label %17
17: ; preds = %16
br label %18
18: ; preds = %17
%19 = load %struct.bitarray*, %struct.bitarray** %2
%20 = call i32 @cba_get(%struct.bitarray* %19, i32 0)
%21 = icmp eq i32 %20, 1
br i1 %21, label %30, label %22
22: ; preds = %18
%23 = 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))
%24 = load %struct.bitarray*, %struct.bitarray** %2
%25 = icmp ne %struct.bitarray* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load %struct.bitarray*, %struct.bitarray** %2
%28 = call i32 @cba_free(%struct.bitarray* %27)
br label %29
29: ; preds = %26, %22
store i32 0, i32* %1
br label %67
30: ; preds = %18
br label %31
31: ; preds = %30
br label %32
32: ; preds = %31
%33 = load %struct.bitarray*, %struct.bitarray** %2
%34 = call i32 @cba_toggle(%struct.bitarray* %33, i32 0)
%35 = icmp ne i32 %34, 0
br i1 %35, label %44, label %36
36: ; preds = %32
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%38 = load %struct.bitarray*, %struct.bitarray** %2
%39 = icmp ne %struct.bitarray* %38, null
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load %struct.bitarray*, %struct.bitarray** %2
%42 = call i32 @cba_free(%struct.bitarray* %41)
br label %43
43: ; preds = %40, %36
store i32 0, i32* %1
br label %67
44: ; preds = %32
br label %45
45: ; preds = %44
br label %46
46: ; preds = %45
%47 = load %struct.bitarray*, %struct.bitarray** %2
%48 = call i32 @cba_get(%struct.bitarray* %47, i32 0)
%49 = icmp eq i32 %48, 0
br i1 %49, label %58, label %50
50: ; preds = %46
%51 = 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.3, i64 0, i64 0))
%52 = load %struct.bitarray*, %struct.bitarray** %2
%53 = icmp ne %struct.bitarray* %52, null
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load %struct.bitarray*, %struct.bitarray** %2
%56 = call i32 @cba_free(%struct.bitarray* %55)
br label %57
57: ; preds = %54, %50
store i32 0, i32* %1
br label %67
58: ; preds = %46
br label %59
59: ; preds = %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%61 = load %struct.bitarray*, %struct.bitarray** %2
%62 = icmp ne %struct.bitarray* %61, null
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load %struct.bitarray*, %struct.bitarray** %2
%65 = call i32 @cba_free(%struct.bitarray* %64)
br label %66
66: ; preds = %63, %59
store i32 1, i32* %1
br label %67
67: ; preds = %66, %57, %43, %29, %15
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
%struct.bitarray = type { i32 }
@.str = [15 x i8] c"FAILED: !(%s)\0A\00"
@.str.1 = [18 x i8] c"cba_toggle(ba, 0)\00"
@.str.2 = [20 x i8] c"cba_get(ba, 0) == 1\00"
@.str.3 = [20 x i8] c"cba_get(ba, 0) == 0\00"
@str = [7 x i8] c"PASSED\00"
define i32 @test_cba_toggle() {
%1 = tail call %struct.bitarray* @cba_alloc(i32 1)
%2 = tail call i32 @cba_toggle(%struct.bitarray* %1, i32 0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq %struct.bitarray* %1, null
br i1 %6, label %31, label %28
7: ; preds = %0
%8 = tail call i32 @cba_get(%struct.bitarray* %1, i32 0)
%9 = icmp eq i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %7
%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.2, i64 0, i64 0))
%12 = icmp eq %struct.bitarray* %1, null
br i1 %12, label %31, label %28
13: ; preds = %7
%14 = tail call i32 @cba_toggle(%struct.bitarray* %1, i32 0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq %struct.bitarray* %1, null
br i1 %18, label %31, label %28
19: ; preds = %13
%20 = tail call i32 @cba_get(%struct.bitarray* %1, i32 0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%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.3, i64 0, i64 0))
%24 = icmp eq %struct.bitarray* %1, null
br i1 %24, label %31, label %28
25: ; preds = %19
%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, %16, %10, %4
%29 = phi i32 [ 0, %4 ], [ 0, %10 ], [ 0, %16 ], [ 0, %22 ], [ 1, %25 ]
%30 = tail call i32 @cba_free(%struct.bitarray* %1)
br label %31
31: ; preds = %28, %25, %22, %16, %10, %4
%32 = phi i32 [ 0, %4 ], [ 0, %10 ], [ 0, %16 ], [ 0, %22 ], [ 1, %25 ], [ %29, %28 ]
ret i32 %32
}