#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 terminal(char **);
char checkPosition(char player, char board[3][3]) {
  unsigned i, j, result;
  int t = terminal(board);
  if (t) {
    if (player == t)
      return 1;
    if (3 == t)
      return 3;
    if (player != t)
      return 2;
  } else {
    char otherPlayer, playerSign;
    if (player == 1) {
      playerSign = 'X';
      otherPlayer = 2;
    } else {
      playerSign = 'O';
      otherPlayer = 1;
    }
    for (i = 0; i < 3; i++) {
      for (j = 0; j < 3; j++) {
        if (board[i][j] == '.') {
          board[i][j] = playerSign;
          result = checkPosition(otherPlayer, board);
          board[i][j] = '.';
          if (result == 2)
            return 1;
          if (result == 3)
            return 3;
        }
      }
    }
    return 2;
  }
}


x86 assembly (clang, -O0):
<checkPosition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <terminal@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1190 <checkPosition+0x70>
movsbl -0x2(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    115e <checkPosition+0x3e>
movb   $0x1,-0x1(%rbp)
jmp    1288 <checkPosition+0x168>
mov    $0x3,%eax
cmp    -0x20(%rbp),%eax
jne    1175 <checkPosition+0x55>
movb   $0x3,-0x1(%rbp)
jmp    1288 <checkPosition+0x168>
movsbl -0x2(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     118b <checkPosition+0x6b>
movb   $0x2,-0x1(%rbp)
jmp    1288 <checkPosition+0x168>
jmp    1288 <checkPosition+0x168>
movsbl -0x2(%rbp),%eax
cmp    $0x1,%eax
jne    11aa <checkPosition+0x8a>
movb   $0x58,-0x22(%rbp)
movb   $0x2,-0x21(%rbp)
jmp    11b2 <checkPosition+0x92>
movb   $0x4f,-0x22(%rbp)
movb   $0x1,-0x21(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jae    1284 <checkPosition+0x164>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jae    1271 <checkPosition+0x151>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
mov    -0x18(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    125e <checkPosition+0x13e>
mov    -0x22(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
mov    -0x18(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x21(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1030 <checkPosition@plt>
movsbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
mov    -0x18(%rbp),%ecx
movb   $0x2e,(%rax,%rcx,1)
cmpl   $0x2,-0x1c(%rbp)
jne    1246 <checkPosition+0x126>
movb   $0x1,-0x1(%rbp)
jmp    1288 <checkPosition+0x168>
cmpl   $0x3,-0x1c(%rbp)
jne    1259 <checkPosition+0x139>
movb   $0x3,-0x1(%rbp)
jmp    1288 <checkPosition+0x168>
jmp    125e <checkPosition+0x13e>
jmp    1263 <checkPosition+0x143>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ca <checkPosition+0xaa>
jmp    1276 <checkPosition+0x156>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b9 <checkPosition+0x99>
movb   $0x2,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkPosition>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <terminal@plt>
test   %eax,%eax
je     1152 <checkPosition+0x32>
mov    %eax,%ecx
movsbl %bpl,%edx
mov    $0x1,%al
cmp    %edx,%ecx
je     129c <checkPosition+0x17c>
cmp    $0x3,%ecx
sete   %al
or     $0x2,%al
jmp    129c <checkPosition+0x17c>
xor    %eax,%eax
cmp    $0x1,%bpl
sete   %al
lea    (%rax,%rax,8),%r14d
add    $0x4f,%r14d
mov    %eax,%ebp
add    $0x1,%bpl
cmpb   $0x2e,(%rbx)
jne    1190 <checkPosition+0x70>
mov    %r14b,(%rbx)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <checkPosition@plt>
movb   $0x2e,(%rbx)
cmp    $0x2,%al
je     129a <checkPosition+0x17a>
cmp    $0x3,%al
je     1296 <checkPosition+0x176>
cmpb   $0x2e,0x1(%rbx)
jne    11ba <checkPosition+0x9a>
mov    %r14b,0x1(%rbx)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <checkPosition@plt>
movb   $0x2e,0x1(%rbx)
cmp    $0x2,%al
je     129a <checkPosition+0x17a>
cmp    $0x3,%al
je     1296 <checkPosition+0x176>
cmpb   $0x2e,0x2(%rbx)
jne    11e4 <checkPosition+0xc4>
mov    %r14b,0x2(%rbx)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <checkPosition@plt>
movb   $0x2e,0x2(%rbx)
cmp    $0x2,%al
je     129a <checkPosition+0x17a>
cmp    $0x3,%al
je     1296 <checkPosition+0x176>
cmpb   $0x2e,0x3(%rbx)
jne    120e <checkPosition+0xee>
mov    %r14b,0x3(%rbx)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <checkPosition@plt>
movb   $0x2e,0x3(%rbx)
cmp    $0x2,%al
je     129a <checkPosition+0x17a>
cmp    $0x3,%al
je     1296 <checkPosition+0x176>
cmpb   $0x2e,0x4(%rbx)
jne    1230 <checkPosition+0x110>
mov    %r14b,0x4(%rbx)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <checkPosition@plt>
movb   $0x2e,0x4(%rbx)
cmp    $0x2,%al
je     129a <checkPosition+0x17a>
cmp    $0x3,%al
je     1296 <checkPosition+0x176>
cmpb   $0x2e,0x5(%rbx)
jne    1252 <checkPosition+0x132>
mov    %r14b,0x5(%rbx)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <checkPosition@plt>
movb   $0x2e,0x5(%rbx)
cmp    $0x2,%al
je     129a <checkPosition+0x17a>
cmp    $0x3,%al
je     1296 <checkPosition+0x176>
cmpb   $0x2e,0x6(%rbx)
jne    1274 <checkPosition+0x154>
mov    %r14b,0x6(%rbx)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <checkPosition@plt>
movb   $0x2e,0x6(%rbx)
cmp    $0x2,%al
je     129a <checkPosition+0x17a>
cmp    $0x3,%al
je     1296 <checkPosition+0x176>
cmpb   $0x2e,0x7(%rbx)
jne    12a1 <checkPosition+0x181>
mov    %r14b,0x7(%rbx)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <checkPosition@plt>
movb   $0x2e,0x7(%rbx)
cmp    $0x2,%al
je     129a <checkPosition+0x17a>
cmp    $0x3,%al
jne    12a1 <checkPosition+0x181>
mov    $0x3,%al
jmp    129c <checkPosition+0x17c>
mov    $0x1,%al
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0x2,%al
cmpb   $0x2e,0x8(%rbx)
jne    129c <checkPosition+0x17c>
mov    %r14b,0x8(%rbx)
movzbl %bpl,%edi
mov    %rbx,%rsi
call   1030 <checkPosition@plt>
movb   $0x2e,0x8(%rbx)
cmp    $0x3,%al
sete   %cl
or     $0x2,%cl
cmp    $0x2,%al
movzbl %cl,%ecx
mov    $0x1,%eax
cmovne %ecx,%eax
jmp    129c <checkPosition+0x17c>

LLVM IR (-O0):
define signext i8 @checkPosition(i8 signext %0, [3 x i8]* %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca [3 x i8]*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
%11 = alloca i8
store i8 %0, i8* %4
store [3 x i8]* %1, [3 x i8]** %5
%12 = load [3 x i8]*, [3 x i8]** %5
%13 = bitcast [3 x i8]* %12 to i8**
%14 = call i32 @terminal(i8** %13)
store i32 %14, i32* %9
%15 = load i32, i32* %9
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %34
17: ; preds = %2
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = load i32, i32* %9
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %17
store i8 1, i8* %3
br label %96
23: ; preds = %17
%24 = load i32, i32* %9
%25 = icmp eq i32 3, %24
br i1 %25, label %26, label %27
26: ; preds = %23
store i8 3, i8* %3
br label %96
27: ; preds = %23
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
%30 = load i32, i32* %9
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %33
32: ; preds = %27
store i8 2, i8* %3
br label %96
33: ; preds = %27
br label %96
34: ; preds = %2
%35 = load i8, i8* %4
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %39
38: ; preds = %34
store i8 88, i8* %11
store i8 2, i8* %10
br label %40
39: ; preds = %34
store i8 79, i8* %11
store i8 1, i8* %10
br label %40
40: ; preds = %39, %38
store i32 0, i32* %6
br label %41
41: ; preds = %92, %40
%42 = load i32, i32* %6
%43 = icmp ult i32 %42, 3
br i1 %43, label %44, label %95
44: ; preds = %41
store i32 0, i32* %7
br label %45
45: ; preds = %88, %44
%46 = load i32, i32* %7
%47 = icmp ult i32 %46, 3
br i1 %47, label %48, label %91
48: ; preds = %45
%49 = load [3 x i8]*, [3 x i8]** %5
%50 = load i32, i32* %6
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %49, i64 %51
%53 = load i32, i32* %7
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds [3 x i8], [3 x i8]* %52, i64 0, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 46
br i1 %58, label %59, label %87
59: ; preds = %48
%60 = load i8, i8* %11
%61 = load [3 x i8]*, [3 x i8]** %5
%62 = load i32, i32* %6
%63 = zext i32 %62 to i64
%64 = getelementptr inbounds [3 x i8], [3 x i8]* %61, i64 %63
%65 = load i32, i32* %7
%66 = zext i32 %65 to i64
%67 = getelementptr inbounds [3 x i8], [3 x i8]* %64, i64 0, i64 %66
store i8 %60, i8* %67
%68 = load i8, i8* %10
%69 = load [3 x i8]*, [3 x i8]** %5
%70 = call signext i8 @checkPosition(i8 signext %68, [3 x i8]* %69)
%71 = sext i8 %70 to i32
store i32 %71, i32* %8
%72 = load [3 x i8]*, [3 x i8]** %5
%73 = load i32, i32* %6
%74 = zext i32 %73 to i64
%75 = getelementptr inbounds [3 x i8], [3 x i8]* %72, i64 %74
%76 = load i32, i32* %7
%77 = zext i32 %76 to i64
%78 = getelementptr inbounds [3 x i8], [3 x i8]* %75, i64 0, i64 %77
store i8 46, i8* %78
%79 = load i32, i32* %8
%80 = icmp eq i32 %79, 2
br i1 %80, label %81, label %82
81: ; preds = %59
store i8 1, i8* %3
br label %96
82: ; preds = %59
%83 = load i32, i32* %8
%84 = icmp eq i32 %83, 3
br i1 %84, label %85, label %86
85: ; preds = %82
store i8 3, i8* %3
br label %96
86: ; preds = %82
br label %87
87: ; preds = %86, %48
br label %88
88: ; preds = %87
%89 = load i32, i32* %7
%90 = add i32 %89, 1
store i32 %90, i32* %7
br label %45
91: ; preds = %45
br label %92
92: ; preds = %91
%93 = load i32, i32* %6
%94 = add i32 %93, 1
store i32 %94, i32* %6
br label %41
95: ; preds = %41
store i8 2, i8* %3
br label %96
96: ; preds = %22, %26, %32, %81, %85, %95, %33
%97 = load i8, i8* %3
ret i8 %97
}

LLVM IR (-O2):
define signext i8 @checkPosition(i8 signext %0, [3 x i8]* %1) {
%3 = bitcast [3 x i8]* %1 to i8**
%4 = tail call i32 @terminal(i8** %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = sext i8 %0 to i32
%8 = icmp eq i32 %4, %7
br i1 %8, label %74, label %9
9: ; preds = %6
%10 = icmp eq i32 %4, 3
%11 = select i1 %10, i8 3, i8 2
br label %74
12: ; preds = %2
%13 = icmp eq i8 %0, 1
%14 = select i1 %13, i8 2, i8 1
%15 = select i1 %13, i8 88, i8 79
%16 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 46
br i1 %18, label %19, label %21
19: ; preds = %12
store i8 %15, i8* %16
%20 = tail call signext i8 @checkPosition(i8 signext %14, [3 x i8]* %1)
store i8 46, i8* %16
switch i8 %20, label %21 [
i8 2, label %74
i8 3, label %73
]
21: ; preds = %19, %12
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 46
br i1 %24, label %25, label %27
25: ; preds = %21
store i8 %15, i8* %22
%26 = tail call signext i8 @checkPosition(i8 signext %14, [3 x i8]* %1)
store i8 46, i8* %22
switch i8 %26, label %27 [
i8 2, label %74
i8 3, label %73
]
27: ; preds = %25, %21
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 2
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 46
br i1 %30, label %31, label %33
31: ; preds = %27
store i8 %15, i8* %28
%32 = tail call signext i8 @checkPosition(i8 signext %14, [3 x i8]* %1)
store i8 46, i8* %28
switch i8 %32, label %33 [
i8 2, label %74
i8 3, label %73
]
33: ; preds = %31, %27
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 1, i64 0
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 46
br i1 %36, label %37, label %39
37: ; preds = %33
store i8 %15, i8* %34
%38 = tail call signext i8 @checkPosition(i8 signext %14, [3 x i8]* %1)
store i8 46, i8* %34
switch i8 %38, label %39 [
i8 2, label %74
i8 3, label %73
]
39: ; preds = %37, %33
%40 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 1, i64 1
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 46
br i1 %42, label %43, label %45
43: ; preds = %39
store i8 %15, i8* %40
%44 = tail call signext i8 @checkPosition(i8 signext %14, [3 x i8]* %1)
store i8 46, i8* %40
switch i8 %44, label %45 [
i8 2, label %74
i8 3, label %73
]
45: ; preds = %43, %39
%46 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 1, i64 2
%47 = load i8, i8* %46
%48 = icmp eq i8 %47, 46
br i1 %48, label %49, label %51
49: ; preds = %45
store i8 %15, i8* %46
%50 = tail call signext i8 @checkPosition(i8 signext %14, [3 x i8]* %1)
store i8 46, i8* %46
switch i8 %50, label %51 [
i8 2, label %74
i8 3, label %73
]
51: ; preds = %49, %45
%52 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 2, i64 0
%53 = load i8, i8* %52
%54 = icmp eq i8 %53, 46
br i1 %54, label %55, label %57
55: ; preds = %51
store i8 %15, i8* %52
%56 = tail call signext i8 @checkPosition(i8 signext %14, [3 x i8]* %1)
store i8 46, i8* %52
switch i8 %56, label %57 [
i8 2, label %74
i8 3, label %73
]
57: ; preds = %55, %51
%58 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 2, i64 1
%59 = load i8, i8* %58
%60 = icmp eq i8 %59, 46
br i1 %60, label %61, label %63
61: ; preds = %57
store i8 %15, i8* %58
%62 = tail call signext i8 @checkPosition(i8 signext %14, [3 x i8]* %1)
store i8 46, i8* %58
switch i8 %62, label %63 [
i8 2, label %74
i8 3, label %73
]
63: ; preds = %61, %57
%64 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 2, i64 2
%65 = load i8, i8* %64
%66 = icmp eq i8 %65, 46
br i1 %66, label %67, label %74
67: ; preds = %63
store i8 %15, i8* %64
%68 = tail call signext i8 @checkPosition(i8 signext %14, [3 x i8]* %1)
store i8 46, i8* %64
%69 = icmp eq i8 %68, 3
%70 = select i1 %69, i8 3, i8 2
%71 = icmp eq i8 %68, 2
%72 = select i1 %71, i8 1, i8 %70
br label %74
73: ; preds = %61, %55, %49, %43, %37, %31, %25, %19
br label %74
74: ; preds = %19, %25, %31, %37, %43, %49, %55, %61, %67, %63, %73, %9, %6
%75 = phi i8 [ 1, %6 ], [ %11, %9 ], [ 3, %73 ], [ 2, %63 ], [ %72, %67 ], [ 1, %61 ], [ 1, %55 ], [ 1, %49 ], [ 1, %43 ], [ 1, %37 ], [ 1, %31 ], [ 1, %25 ], [ 1, %19 ]
ret i8 %75
}