#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 checkColumn(int, int **);
int checkDiagon(int **);
int checkRow(int, int **);
int gameState(int board[3][3]) {
  int state = checkDiagon(board);
  if (state != 0)
    return state;
  for (int i = 0; i < 3; i++) {
    state = checkColumn(i, board);
    if (state != 0)
      return state;
    state = checkRow(i, board);
    if (state != 0)
      return state;
  }
  return 0;
}


x86 assembly (clang, -O0):
<gameState>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <checkDiagon@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     115d <gameState+0x2d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d0 <gameState+0xa0>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11c9 <gameState+0x99>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <checkColumn@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1192 <gameState+0x62>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d0 <gameState+0xa0>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <checkRow@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b6 <gameState+0x86>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d0 <gameState+0xa0>
jmp    11bb <gameState+0x8b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1164 <gameState+0x34>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gameState>:
push   %rbx
mov    %rdi,%rbx
call   1040 <checkDiagon@plt>
test   %eax,%eax
jne    118c <gameState+0x5c>
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <checkColumn@plt>
test   %eax,%eax
jne    118c <gameState+0x5c>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <checkRow@plt>
test   %eax,%eax
jne    118c <gameState+0x5c>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1030 <checkColumn@plt>
test   %eax,%eax
jne    118c <gameState+0x5c>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1050 <checkRow@plt>
test   %eax,%eax
jne    118c <gameState+0x5c>
mov    $0x2,%edi
mov    %rbx,%rsi
call   1030 <checkColumn@plt>
test   %eax,%eax
je     118e <gameState+0x5e>
pop    %rbx
ret
mov    $0x2,%edi
mov    %rbx,%rsi
pop    %rbx
jmp    1050 <checkRow@plt>

LLVM IR (-O0):
define i32 @gameState([3 x i32]* %0) {
%2 = alloca i32
%3 = alloca [3 x i32]*
%4 = alloca i32
%5 = alloca i32
store [3 x i32]* %0, [3 x i32]** %3
%6 = load [3 x i32]*, [3 x i32]** %3
%7 = bitcast [3 x i32]* %6 to i32**
%8 = call i32 @checkDiagon(i32** %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %40
13: ; preds = %1
store i32 0, i32* %5
br label %14
14: ; preds = %36, %13
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %39
17: ; preds = %14
%18 = load i32, i32* %5
%19 = load [3 x i32]*, [3 x i32]** %3
%20 = bitcast [3 x i32]* %19 to i32**
%21 = call i32 @checkColumn(i32 %18, i32** %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = load i32, i32* %4
store i32 %25, i32* %2
br label %40
26: ; preds = %17
%27 = load i32, i32* %5
%28 = load [3 x i32]*, [3 x i32]** %3
%29 = bitcast [3 x i32]* %28 to i32**
%30 = call i32 @checkRow(i32 %27, i32** %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = load i32, i32* %4
store i32 %34, i32* %2
br label %40
35: ; preds = %26
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %14
39: ; preds = %14
store i32 0, i32* %2
br label %40
40: ; preds = %39, %33, %24, %11
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @gameState([3 x i32]* %0) {
%2 = bitcast [3 x i32]* %0 to i32**
%3 = tail call i32 @checkDiagon(i32** %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %1
%6 = tail call i32 @checkColumn(i32 0, i32** %2)
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %22
8: ; preds = %19
%9 = tail call i32 @checkColumn(i32 1, i32** %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = tail call i32 @checkRow(i32 1, i32** %2)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = tail call i32 @checkColumn(i32 2, i32** %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = tail call i32 @checkRow(i32 2, i32** %2)
br label %22
19: ; preds = %5
%20 = tail call i32 @checkRow(i32 0, i32** %2)
%21 = icmp eq i32 %20, 0
br i1 %21, label %8, label %22
22: ; preds = %17, %19, %5, %8, %11, %14, %1
%23 = phi i32 [ %3, %1 ], [ %20, %19 ], [ %6, %5 ], [ %9, %8 ], [ %12, %11 ], [ %15, %14 ], [ %18, %17 ]
ret i32 %23
}