#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 */

/* Variables and functions */
int house_coinflip();
bool coinflip(void) {
  bool rolls[2];
  while (1) {
    rolls[0] = house_coinflip();
    rolls[1] = house_coinflip();
    if (rolls[0] == true && rolls[1] == false) {
      break;
    } else if (rolls[0] == false && rolls[1] == true) {
      break;
    }
  }
  return rolls[0];
}


x86 assembly (clang, -O0):
<coinflip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <house_coinflip@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <house_coinflip@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1145 <coinflip+0x35>
cmpl   $0x0,-0x4(%rbp)
jne    1145 <coinflip+0x35>
jmp    1168 <coinflip+0x58>
cmpl   $0x0,-0x8(%rbp)
jne    115e <coinflip+0x4e>
cmpl   $0x1,-0x4(%rbp)
jne    115e <coinflip+0x4e>
jmp    1168 <coinflip+0x58>
jmp    1163 <coinflip+0x53>
jmp    1118 <coinflip+0x8>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<coinflip>:
push   %rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <house_coinflip@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <house_coinflip@plt>
cmp    $0x1,%ebx
jne    1139 <coinflip+0x29>
test   %eax,%eax
je     1146 <coinflip+0x36>
test   %ebx,%ebx
jne    1120 <coinflip+0x10>
cmp    $0x1,%eax
jne    1120 <coinflip+0x10>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @coinflip() {
%1 = alloca [2 x i32]
br label %2
2: ; preds = %0, %25
%3 = call i32 (...) @house_coinflip()
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
store i32 %3, i32* %4
%5 = call i32 (...) @house_coinflip()
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
store i32 %5, i32* %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10
br label %26
15: ; preds = %10, %2
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %24
23: ; preds = %19
br label %26
24: ; preds = %19, %15
br label %25
25: ; preds = %24
br label %2
26: ; preds = %23, %14
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%28 = load i32, i32* %27
ret i32 %28
}

LLVM IR (-O2):
define i32 @coinflip() {
br label %1
1: ; preds = %7, %0
%2 = tail call i32 (...) @house_coinflip()
%3 = tail call i32 (...) @house_coinflip()
%4 = icmp eq i32 %2, 1
%5 = icmp eq i32 %3, 0
%6 = select i1 %4, i1 %5, i1 false
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = icmp eq i32 %2, 0
%9 = icmp eq i32 %3, 1
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %1
11: ; preds = %7, %1
%12 = phi i32 [ 0, %7 ], [ 1, %1 ]
ret i32 %12
}