#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 check_diagonal(char **);
int check_horizontal(char **);
int check_vertical(char **);
int check_all(char board[][3]) {
  int winner = 0, horizontal = 0, vertical = 0, diagonal = 0;
  diagonal = check_diagonal(board);
  horizontal = check_horizontal(board);
  vertical = check_vertical(board);
  if (diagonal == 1) {
    winner = 1;
  } else if (diagonal == 2) {
    winner = 2;
  }
  if (horizontal == 1) {
    winner = 1;
  } else if (horizontal == 2) {
    winner = 2;
  }
  if (vertical == 1) {
    winner = 1;
  } else if (vertical == 2) {
    winner = 2;
  }
  return winner;
}


x86 assembly (clang, -O0):
<check_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <check_diagonal@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <check_horizontal@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <check_vertical@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    1192 <check_all+0x62>
movl   $0x1,-0xc(%rbp)
jmp    11a8 <check_all+0x78>
cmpl   $0x2,-0x18(%rbp)
jne    11a3 <check_all+0x73>
movl   $0x2,-0xc(%rbp)
jmp    11a8 <check_all+0x78>
cmpl   $0x1,-0x10(%rbp)
jne    11be <check_all+0x8e>
movl   $0x1,-0xc(%rbp)
jmp    11d4 <check_all+0xa4>
cmpl   $0x2,-0x10(%rbp)
jne    11cf <check_all+0x9f>
movl   $0x2,-0xc(%rbp)
jmp    11d4 <check_all+0xa4>
cmpl   $0x1,-0x14(%rbp)
jne    11ea <check_all+0xba>
movl   $0x1,-0xc(%rbp)
jmp    1200 <check_all+0xd0>
cmpl   $0x2,-0x14(%rbp)
jne    11fb <check_all+0xcb>
movl   $0x2,-0xc(%rbp)
jmp    1200 <check_all+0xd0>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_all>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
call   1050 <check_diagonal@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1040 <check_horizontal@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <check_vertical@plt>
cmp    $0x1,%ebx
je     1160 <check_all+0x30>
cmp    $0x2,%ebx
jne    1171 <check_all+0x41>
mov    $0x2,%ebx
cmp    $0x1,%eax
je     1189 <check_all+0x59>
cmp    $0x2,%eax
jne    118b <check_all+0x5b>
mov    $0x2,%ebx
jmp    118b <check_all+0x5b>
xor    %ebx,%ebx
cmp    $0x2,%r14d
sete   %bl
add    %ebx,%ebx
cmp    $0x1,%r14d
cmove  %r14d,%ebx
cmp    $0x1,%eax
jne    1165 <check_all+0x35>
mov    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @check_all([3 x i8]* %0) {
%2 = bitcast [3 x i8]* %0 to i8**
%3 = tail call i32 @check_diagonal(i8** %2)
%4 = tail call i32 @check_horizontal(i8** %2)
%5 = tail call i32 @check_vertical(i8** %2)
switch i32 %4, label %7 [
i32 1, label %12
i32 2, label %6
]
6: ; preds = %1
br label %12
7: ; preds = %1
%8 = icmp eq i32 %3, 1
%9 = icmp eq i32 %3, 2
%10 = select i1 %9, i32 2, i32 0
%11 = select i1 %8, i32 1, i32 %10
br label %12
12: ; preds = %1, %7, %6
%13 = phi i32 [ 2, %6 ], [ %4, %1 ], [ %11, %7 ]
switch i32 %5, label %15 [
i32 1, label %16
i32 2, label %14
]
14: ; preds = %12
br label %16
15: ; preds = %12
br label %16
16: ; preds = %12, %15, %14
%17 = phi i32 [ 2, %14 ], [ %5, %12 ], [ %13, %15 ]
ret i32 %17
}