#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 EXIT_SUCCESS;
short playGame();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  srand(time(NULL));
  int blackWins = 0, whiteWins = 0, ties = 0, gameIndex;
  for (gameIndex = 0; gameIndex < 1000; gameIndex++) {
    short winner = playGame();
    if (winner == 0) {
      blackWins++;
    } else if (winner == 1) {
      whiteWins++;
    } else {
      ties++;
    }
  }
  printf("b:%i\n", blackWins);
  printf("w:%i\n", whiteWins);
  printf("t:%i\n", ties);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3e8,-0x14(%rbp)
jge    11ea <main+0xaa>
mov    $0x0,%al
call   1060 <playGame@plt>
mov    %ax,-0x16(%rbp)
movswl -0x16(%rbp),%eax
cmp    $0x0,%eax
jne    11ae <main+0x6e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d7 <main+0x97>
movswl -0x16(%rbp),%eax
cmp    $0x1,%eax
jne    11c9 <main+0x89>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d2 <main+0x92>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d7 <main+0x97>
jmp    11dc <main+0x9c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <main+0x3b>
mov    -0x8(%rbp),%esi
lea    0xe0c(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xdfa(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x3e8,%ebp
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    1179 <main+0x39>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14d
add    $0xffffffff,%ebp
je     1196 <main+0x56>
xor    %eax,%eax
call   1060 <playGame@plt>
cmp    $0x1,%ax
je     1190 <main+0x50>
test   %ax,%ax
jne    1170 <main+0x30>
add    $0x1,%ebx
jmp    1174 <main+0x34>
add    $0x1,%r15d
jmp    1174 <main+0x34>
lea    0xe63(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
lea    0xe5b(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
lea    0xe52(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"b:%i\0A\00"
@.str.1 = [6 x i8] c"w:%i\0A\00"
@.str.2 = [6 x i8] c"t:%i\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
store i32 0, i32* %1
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
store i32 0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %32, %0
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %35
12: ; preds = %9
%13 = call signext i16 (...) @playGame()
store i16 %13, i16* %6
%14 = load i16, i16* %6
%15 = sext i16 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
br label %31
20: ; preds = %12
%21 = load i16, i16* %6
%22 = sext i16 %21 to i32
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %30
27: ; preds = %20
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %30
30: ; preds = %27, %24
br label %31
31: ; preds = %30, %17
br label %32
32: ; preds = %31
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %9
35: ; preds = %9
%36 = load i32, i32* %2
%37 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %3
%39 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
}

LLVM IR (-O2):
@.str = [6 x i8] c"b:%i\0A\00"
@.str.1 = [6 x i8] c"w:%i\0A\00"
@.str.2 = [6 x i8] c"t:%i\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32 @time(i32* null)
%2 = tail call i32 @srand(i32 %1)
br label %3
3: ; preds = %0, %15
%4 = phi i32 [ 0, %0 ], [ %18, %15 ]
%5 = phi i32 [ 0, %0 ], [ %19, %15 ]
%6 = phi i32 [ 0, %0 ], [ %17, %15 ]
%7 = phi i32 [ 0, %0 ], [ %16, %15 ]
%8 = tail call signext i16 (...) @playGame()
switch i16 %8, label %13 [
i16 0, label %9
i16 1, label %11
]
9: ; preds = %3
%10 = add nsw i32 %4, 1
br label %15
11: ; preds = %3
%12 = add nsw i32 %7, 1
br label %15
13: ; preds = %3
%14 = add nsw i32 %6, 1
br label %15
15: ; preds = %11, %13, %9
%16 = phi i32 [ %7, %9 ], [ %12, %11 ], [ %7, %13 ]
%17 = phi i32 [ %6, %9 ], [ %6, %11 ], [ %14, %13 ]
%18 = phi i32 [ %10, %9 ], [ %4, %11 ], [ %4, %13 ]
%19 = add nuw nsw i32 %5, 1
%20 = icmp eq i32 %19, 1000
br i1 %20, label %21, label %3
21: ; preds = %15
%22 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %18)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}