#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 PlayBoard();
scalar_t__ ReadBoard();
int /*<<< orphan*/ printf(char *, unsigned long, char const *);
int main() {
  unsigned long game = 0;
  while (ReadBoard()) {
    const char *szLoser = "no";
    int winner = 0;
    game++;
    winner = PlayBoard();
    switch (winner) {
    case 1:
      szLoser = "white";
      break;
    case 2:
      szLoser = "black";
      break;
    }
    printf("Game #%d: %s king is in check.\n", game, szLoser);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <ReadBoard@plt>
cmp    $0x0,%rax
je     11d9 <main+0xa9>
lea    0xea1(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
call   1050 <PlayBoard@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x1,%eax
je     11a5 <main+0x75>
jmp    1194 <main+0x64>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     11b5 <main+0x85>
jmp    11c0 <main+0x90>
lea    0xe57(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11c0 <main+0x90>
lea    0xe4d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
jmp    1147 <main+0x17>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
xor    %eax,%eax
call   1030 <ReadBoard@plt>
test   %rax,%rax
je     11a3 <main+0x73>
mov    $0x1,%ebx
lea    0xeb8(%rip),%r15
lea    0xea8(%rip),%r12
lea    0xea4(%rip),%r13
lea    0xea9(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <PlayBoard@plt>
cmp    $0x2,%eax
mov    %r12,%rdx
cmove  %r15,%rdx
cmp    $0x1,%eax
cmove  %r13,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <ReadBoard@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1170 <main+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"no\00"
@.str.1 = [6 x i8] c"white\00"
@.str.2 = [6 x i8] c"black\00"
@.str.3 = [32 x i8] c"Game #%d: %s king is in check.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %2
br label %5
5: ; preds = %15, %0
%6 = call i64 (...) @ReadBoard()
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %4
%9 = load i64, i64* %2
%10 = add i64 %9, 1
store i64 %10, i64* %2
%11 = call i32 (...) @PlayBoard()
store i32 %11, i32* %4
%12 = load i32, i32* %4
switch i32 %12, label %15 [
i32 1, label %13
i32 2, label %14
]
13: ; preds = %8
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %15
14: ; preds = %8
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %15
15: ; preds = %8, %14, %13
%16 = load i64, i64* %2
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i64 %16, i8* %17)
br label %5
19: ; preds = %5
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [3 x i8] c"no\00"
@.str.1 = [6 x i8] c"white\00"
@.str.2 = [6 x i8] c"black\00"
@.str.3 = [32 x i8] c"Game #%d: %s king is in check.\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @ReadBoard()
%2 = icmp eq i64 %1, 0
br i1 %2, label %14, label %3
3: ; preds = %0, %3
%4 = phi i64 [ %5, %3 ], [ 0, %0 ]
%5 = add i64 %4, 1
%6 = tail call i32 (...) @PlayBoard()
%7 = icmp eq i32 %6, 2
%8 = select i1 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%9 = icmp eq i32 %6, 1
%10 = select i1 %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %8
%11 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i64 %5, i8* %10)
%12 = tail call i64 (...) @ReadBoard()
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %3
14: ; preds = %3, %0
ret i32 0
}