#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_win(int **, int);
void *malloc(int);
int /*<<< orphan*/ minimax(int **, int, int /*<<< orphan*/, int, int);
int /*<<< orphan*/ print_board(int **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int i, j, row, column, position = -1, moves = 9;
  int player, computer;
  int **board;
  board = malloc(3 * sizeof(int *));
  for (i = 0; i < 3; i++) {
    board[i] = malloc(3 * sizeof(int));
  }
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      board[i][j] = -1;
    }
  }
  while (position != 1 && position != 2) {
    printf("Play first(=1) or play second(=2)?\n");
    scanf("%d", &position);
    if (position == 1) {
      player = 'O';
      computer = 'X';
    }
    if (position == 2) {
      player = 'X';
      computer = 'O';
    }
    if (position != 1 && position != 2) {
      printf("Please give a valid input\n");
    }
  }
  while (moves >= 0) {
    if (position == 1) {
      print_board(board);
      printf("Player's turn\n");
      printf("Enter the row and the column you want to put O\n");
      scanf("%d %d", &row, &column);
      printf("\033[2J\033[1;1H");
      if (row < 0 || row >= 3 || column < 0 || column >= 3) {
        while (row < 0 || row >= 3 || column < 0 || column >= 3) {
          printf("Please give me a valid box\n");
          printf("Enter the row and the column you want to put O\n");
          scanf("%d %d", &row, &column);
        }
      }
      if (board[row][column] == computer || board[row][column] == player) {
        while (board[row][column] == computer || board[row][column] == player) {
          printf("Please give me a box that is free\n");
          printf("Enter the row and the column you want to put O\n");
          scanf("%d %d", &row, &column);
        }
      }
      board[row][column] = player;
      if (check_win(board, player) == 1) {
        print_board(board);
        printf("You won\n");
        return 0;
      }
      moves = moves - 1;
      if (moves == 0 && check_win(board, player) == 0) {
        print_board(board);
        printf("Draw\n");
        return 0;
      }
      minimax(board, computer, 0, player, computer);
      if (check_win(board, computer) == 1) {
        print_board(board);
        printf("You lost\n");
        return 0;
      }
      moves = moves - 1;
    }
    if (position == 2) {
      minimax(board, computer, 0, player, computer);
      if (check_win(board, computer) == 1) {
        print_board(board);
        printf("You lost\n");
        return 0;
      }
      moves = moves - 1;
      if (moves == 0 && check_win(board, computer) == 0) {
        print_board(board);
        printf("Draw\n");
        return 0;
      }
      print_board(board);
      printf("Player's turn\n");
      printf("Enter the row and the column you want to put X\n");
      scanf("%d %d", &row, &column);
      if (row < 0 || row >= 3 || column < 0 || column >= 3) {
        while (row < 0 || row >= 3 || column < 0 || column >= 3) {
          printf("Please give me a valid box\n");
          printf("Enter the row and the column you want to put X\n");
          scanf("%d %d", &row, &column);
        }
      }
      if (board[row][column] == computer || board[row][column] == player) {
        while (board[row][column] == computer || board[row][column] == player) {
          printf("Please give me a box that is free\n");
          printf("Enter the row and the column you want to put X\n");
          scanf("%d %d", &row, &column);
        }
      }
      board[row][column] = player;
      if (check_win(board, player) == 1) {
        print_board(board);
        printf("You won\n");
        return 0;
      }
      moves = moves - 1;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x9,-0x1c(%rbp)
mov    $0x18,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c3 <main+0x63>
mov    $0xc,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1192 <main+0x32>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    121d <main+0xbd>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    120a <main+0xaa>
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0xc(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11db <main+0x7b>
jmp    120f <main+0xaf>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ca <main+0x6a>
jmp    1222 <main+0xc2>
xor    %eax,%eax
cmpl   $0x1,-0x18(%rbp)
mov    %al,-0x31(%rbp)
je     123b <main+0xdb>
cmpl   $0x2,-0x18(%rbp)
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    124b <main+0xeb>
jmp    12be <main+0x15e>
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
lea    0xe23(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1281 <main+0x121>
movl   $0x4f,-0x20(%rbp)
movl   $0x58,-0x24(%rbp)
cmpl   $0x2,-0x18(%rbp)
jne    1299 <main+0x139>
movl   $0x58,-0x20(%rbp)
movl   $0x4f,-0x24(%rbp)
cmpl   $0x1,-0x18(%rbp)
je     12b9 <main+0x159>
cmpl   $0x2,-0x18(%rbp)
je     12b9 <main+0x159>
lea    0xd70(%rip),%rdi
call   1040 <printf@plt>
jmp    1222 <main+0xc2>
jmp    12c3 <main+0x163>
cmpl   $0x0,-0x1c(%rbp)
jl     180e <main+0x6ae>
cmpl   $0x1,-0x18(%rbp)
jne    1571 <main+0x411>
mov    -0x30(%rbp),%rdi
call   1060 <print_board@plt>
lea    0xd58(%rip),%rdi
call   1040 <printf@plt>
lea    0xd5b(%rip),%rdi
call   1040 <printf@plt>
lea    0xd7f(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
lea    0xd6f(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jl     1342 <main+0x1e2>
cmpl   $0x3,-0x10(%rbp)
jge    1342 <main+0x1e2>
cmpl   $0x0,-0x14(%rbp)
jl     1342 <main+0x1e2>
cmpl   $0x3,-0x14(%rbp)
jl     13c6 <main+0x266>
jmp    1347 <main+0x1e7>
mov    $0x1,%al
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x32(%rbp)
jl     137e <main+0x21e>
mov    $0x1,%al
cmpl   $0x3,-0x10(%rbp)
mov    %al,-0x32(%rbp)
jge    137e <main+0x21e>
mov    $0x1,%al
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x32(%rbp)
jl     137e <main+0x21e>
cmpl   $0x3,-0x14(%rbp)
setge  %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
test   $0x1,%al
jne    138e <main+0x22e>
jmp    13c1 <main+0x261>
lea    0xcfa(%rip),%rdi
call   1040 <printf@plt>
lea    0xcad(%rip),%rdi
call   1040 <printf@plt>
lea    0xcd1(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
jmp    1347 <main+0x1e7>
jmp    13c6 <main+0x266>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x24(%rbp),%eax
je     13fe <main+0x29e>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x20(%rbp),%eax
jne    1488 <main+0x328>
jmp    1403 <main+0x2a3>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    $0x1,%al
cmp    -0x24(%rbp),%ecx
mov    %al,-0x33(%rbp)
je     1440 <main+0x2e0>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x20(%rbp),%eax
sete   %al
mov    %al,-0x33(%rbp)
mov    -0x33(%rbp),%al
test   $0x1,%al
jne    1450 <main+0x2f0>
jmp    1483 <main+0x323>
lea    0xc54(%rip),%rdi
call   1040 <printf@plt>
lea    0xbeb(%rip),%rdi
call   1040 <printf@plt>
lea    0xc0f(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
jmp    1403 <main+0x2a3>
jmp    1488 <main+0x328>
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <check_win@plt>
cmp    $0x1,%eax
jne    14d4 <main+0x374>
mov    -0x30(%rbp),%rdi
call   1060 <print_board@plt>
lea    0xc0b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    180e <main+0x6ae>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    151d <main+0x3bd>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <check_win@plt>
cmp    $0x0,%eax
jne    151d <main+0x3bd>
mov    -0x30(%rbp),%rdi
call   1060 <print_board@plt>
lea    0xbcb(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    180e <main+0x6ae>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
xor    %edx,%edx
call   1030 <minimax@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <check_win@plt>
cmp    $0x1,%eax
jne    1568 <main+0x408>
mov    -0x30(%rbp),%rdi
call   1060 <print_board@plt>
lea    0xb86(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    180e <main+0x6ae>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x2,-0x18(%rbp)
jne    1809 <main+0x6a9>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
xor    %edx,%edx
call   1030 <minimax@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <check_win@plt>
cmp    $0x1,%eax
jne    15c6 <main+0x466>
mov    -0x30(%rbp),%rdi
call   1060 <print_board@plt>
lea    0xb28(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    180e <main+0x6ae>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    160f <main+0x4af>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <check_win@plt>
cmp    $0x0,%eax
jne    160f <main+0x4af>
mov    -0x30(%rbp),%rdi
call   1060 <print_board@plt>
lea    0xad9(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    180e <main+0x6ae>
mov    -0x30(%rbp),%rdi
call   1060 <print_board@plt>
lea    0xa20(%rip),%rdi
call   1040 <printf@plt>
lea    0xabc(%rip),%rdi
call   1040 <printf@plt>
lea    0xa47(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jl     166e <main+0x50e>
cmpl   $0x3,-0x10(%rbp)
jge    166e <main+0x50e>
cmpl   $0x0,-0x14(%rbp)
jl     166e <main+0x50e>
cmpl   $0x3,-0x14(%rbp)
jl     16f2 <main+0x592>
jmp    1673 <main+0x513>
mov    $0x1,%al
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x34(%rbp)
jl     16aa <main+0x54a>
mov    $0x1,%al
cmpl   $0x3,-0x10(%rbp)
mov    %al,-0x34(%rbp)
jge    16aa <main+0x54a>
mov    $0x1,%al
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x34(%rbp)
jl     16aa <main+0x54a>
cmpl   $0x3,-0x14(%rbp)
setge  %al
mov    %al,-0x34(%rbp)
mov    -0x34(%rbp),%al
test   $0x1,%al
jne    16ba <main+0x55a>
jmp    16ed <main+0x58d>
lea    0x9ce(%rip),%rdi
call   1040 <printf@plt>
lea    0xa1a(%rip),%rdi
call   1040 <printf@plt>
lea    0x9a5(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
jmp    1673 <main+0x513>
jmp    16f2 <main+0x592>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x24(%rbp),%eax
je     172a <main+0x5ca>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x20(%rbp),%eax
jne    17b4 <main+0x654>
jmp    172f <main+0x5cf>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    $0x1,%al
cmp    -0x24(%rbp),%ecx
mov    %al,-0x35(%rbp)
je     176c <main+0x60c>
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x20(%rbp),%eax
sete   %al
mov    %al,-0x35(%rbp)
mov    -0x35(%rbp),%al
test   $0x1,%al
jne    177c <main+0x61c>
jmp    17af <main+0x64f>
lea    0x928(%rip),%rdi
call   1040 <printf@plt>
lea    0x958(%rip),%rdi
call   1040 <printf@plt>
lea    0x8e3(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
jmp    172f <main+0x5cf>
jmp    17b4 <main+0x654>
mov    -0x20(%rbp),%edx
mov    -0x30(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1050 <check_win@plt>
cmp    $0x1,%eax
jne    1800 <main+0x6a0>
mov    -0x30(%rbp),%rdi
call   1060 <print_board@plt>
lea    0x8df(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    180e <main+0x6ae>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12c3 <main+0x163>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0xffffffff,0x14(%rsp)
ff
mov    $0x18,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0xc,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%r14)
mov    $0xc,%edi
call   1080 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x8(%r14)
mov    $0xc,%edi
call   1080 <malloc@plt>
mov    %rax,0x10(%r14)
movq   $0xffffffffffffffff,(%rbx)
movl   $0xffffffff,0x8(%rbx)
movl   $0xffffffff,0x8(%rbp)
movq   $0xffffffffffffffff,0x0(%rbp)
ff
movl   $0xffffffff,0x8(%rax)
movq   $0xffffffffffffffff,(%rax)
mov    $0x4f,%r12d
mov    $0x58,%r13d
lea    0xef3(%rip),%r15
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
lea    0xdf0(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    $0x1,%eax
cmove  %r12d,%ebx
cmove  %r13d,%ebp
cmp    $0x2,%eax
cmove  %r13d,%ebx
cmove  %r12d,%ebp
lea    -0x3(%rax),%ecx
cmp    $0xfffffffd,%ecx
ja     1255 <main+0xe5>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    0x14(%rsp),%eax
lea    -0x3(%rax),%ecx
cmp    $0xfffffffe,%ecx
jb     1200 <main+0x90>
mov    $0x9,%ecx
lea    0xd9f(%rip),%r13
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r12
cmp    $0x1,%eax
jne    13cf <main+0x25f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ecx,0x10(%rsp)
mov    %r14,%rdi
call   1070 <print_board@plt>
lea    0xdad(%rip),%rdi
call   1030 <puts@plt>
lea    0xe02(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
lea    0xd4b(%rip),%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
ja     12e0 <main+0x170>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
js     12e0 <main+0x170>
cmp    $0x3,%ecx
jl     131e <main+0x1ae>
cs nopw 0x0(%rax,%rax,1)
lea    0xd9f(%rip),%rdi
call   1030 <puts@plt>
lea    0xdae(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
ja     12e0 <main+0x170>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
js     12e0 <main+0x170>
cmp    $0x2,%ecx
jg     12e0 <main+0x170>
mov    %eax,%eax
mov    (%r14,%rax,8),%rax
mov    %ecx,%ecx
jmp    1366 <main+0x1f6>
nopl   0x0(%rax,%rax,1)
lea    0xd2d(%rip),%rdi
call   1030 <puts@plt>
lea    0xd5e(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
movslq 0xc(%rsp),%rax
mov    (%r14,%rax,8),%rax
movslq 0x8(%rsp),%rcx
mov    (%rax,%rcx,4),%edx
cmp    %ebp,%edx
je     1330 <main+0x1c0>
cmp    %ebx,%edx
je     1330 <main+0x1c0>
mov    %ebx,(%rax,%rcx,4)
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <check_win@plt>
cmp    $0x1,%eax
je     1531 <main+0x3c1>
cmpl   $0x1,0x10(%rsp)
jne    13a0 <main+0x230>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <check_win@plt>
test   %eax,%eax
je     1542 <main+0x3d2>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %edx,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
call   1040 <minimax@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <check_win@plt>
cmp    $0x1,%eax
je     1520 <main+0x3b0>
mov    0x10(%rsp),%ecx
add    $0xfffffffe,%ecx
mov    0x14(%rsp),%eax
cmp    $0x2,%eax
jne    150a <main+0x39a>
mov    %ecx,0x10(%rsp)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %edx,%edx
mov    %ebx,%ecx
mov    %ebp,%r8d
call   1040 <minimax@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <check_win@plt>
cmp    $0x1,%eax
je     1520 <main+0x3b0>
cmpl   $0x1,0x10(%rsp)
jne    1419 <main+0x2a9>
mov    %r14,%rdi
mov    %ebp,%esi
call   1060 <check_win@plt>
test   %eax,%eax
je     1542 <main+0x3d2>
mov    %r14,%rdi
call   1070 <print_board@plt>
lea    0xc18(%rip),%rdi
call   1030 <puts@plt>
lea    0xbdd(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
ja     1460 <main+0x2f0>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
js     1460 <main+0x2f0>
cmp    $0x3,%ecx
jl     149e <main+0x32e>
nop
lea    0xc1f(%rip),%rdi
call   1030 <puts@plt>
lea    0xb9e(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
ja     1460 <main+0x2f0>
mov    0x8(%rsp),%ecx
test   %ecx,%ecx
js     1460 <main+0x2f0>
cmp    $0x2,%ecx
jg     1460 <main+0x2f0>
mov    %eax,%eax
mov    (%r14,%rax,8),%rax
mov    %ecx,%ecx
jmp    14e6 <main+0x376>
nopl   0x0(%rax,%rax,1)
lea    0xbad(%rip),%rdi
call   1030 <puts@plt>
lea    0xb4e(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
movslq 0xc(%rsp),%rax
mov    (%r14,%rax,8),%rax
movslq 0x8(%rsp),%rcx
mov    (%rax,%rcx,4),%edx
cmp    %ebp,%edx
je     14b0 <main+0x340>
cmp    %ebx,%edx
je     14b0 <main+0x340>
mov    %ebx,(%rax,%rcx,4)
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <check_win@plt>
cmp    $0x1,%eax
je     1531 <main+0x3c1>
mov    0x10(%rsp),%ecx
add    $0xfffffffe,%ecx
test   %ecx,%ecx
js     1556 <main+0x3e6>
mov    0x14(%rsp),%eax
cmp    $0x1,%eax
je     1280 <main+0x110>
jmp    13cf <main+0x25f>
mov    %r14,%rdi
call   1070 <print_board@plt>
lea    0xb1f(%rip),%rdi
jmp    1551 <main+0x3e1>
mov    %r14,%rdi
call   1070 <print_board@plt>
lea    0xb1c(%rip),%rdi
jmp    1551 <main+0x3e1>
mov    %r14,%rdi
call   1070 <print_board@plt>
lea    0xb06(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Play first(=1) or play second(=2)?\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Please give a valid input\0A\00"
@.str.3 = [15 x i8] c"Player's turn\0A\00"
@.str.4 = [48 x i8] c"Enter the row and the column you want to put O\0A\00"
@.str.5 = [6 x i8] c"%d %d\00"
@.str.6 = [11 x i8] c"\1B[2J\1B[1;1H\00"
@.str.7 = [28 x i8] c"Please give me a valid box\0A\00"
@.str.8 = [35 x i8] c"Please give me a box that is free\0A\00"
@.str.9 = [9 x i8] c"You won\0A\00"
@.str.10 = [6 x i8] c"Draw\0A\00"
@.str.11 = [10 x i8] c"You lost\0A\00"
@.str.12 = [48 x i8] c"Enter the row and the column you want to put X\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32**
store i32 0, i32* %1
store i32 -1, i32* %6
store i32 9, i32* %7
%11 = call i8* @malloc(i32 24)
%12 = bitcast i8* %11 to i32**
store i32** %12, i32*** %10
store i32 0, i32* %2
br label %13
13: ; preds = %23, %0
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = call i8* @malloc(i32 12)
%18 = bitcast i8* %17 to i32*
%19 = load i32**, i32*** %10
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32*, i32** %19, i64 %21
store i32* %18, i32** %22
br label %23
23: ; preds = %16
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %13
26: ; preds = %13
store i32 0, i32* %2
br label %27
27: ; preds = %47, %26
%28 = load i32, i32* %2
%29 = icmp slt i32 %28, 3
br i1 %29, label %30, label %50
30: ; preds = %27
store i32 0, i32* %3
br label %31
31: ; preds = %43, %30
%32 = load i32, i32* %3
%33 = icmp slt i32 %32, 3
br i1 %33, label %34, label %46
34: ; preds = %31
%35 = load i32**, i32*** %10
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32*, i32** %35, i64 %37
%39 = load i32*, i32** %38
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 -1, i32* %42
br label %43
43: ; preds = %34
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %31
46: ; preds = %31
br label %47
47: ; preds = %46
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %27
50: ; preds = %27
br label %51
51: ; preds = %77, %50
%52 = load i32, i32* %6
%53 = icmp ne i32 %52, 1
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %6
%56 = icmp ne i32 %55, 2
br label %57
57: ; preds = %54, %51
%58 = phi i1 [ false, %51 ], [ %56, %54 ]
br i1 %58, label %59, label %78
59: ; preds = %57
%60 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%61 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%62 = load i32, i32* %6
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %65
64: ; preds = %59
store i32 79, i32* %8
store i32 88, i32* %9
br label %65
65: ; preds = %64, %59
%66 = load i32, i32* %6
%67 = icmp eq i32 %66, 2
br i1 %67, label %68, label %69
68: ; preds = %65
store i32 88, i32* %8
store i32 79, i32* %9
br label %69
69: ; preds = %68, %65
%70 = load i32, i32* %6
%71 = icmp ne i32 %70, 1
br i1 %71, label %72, label %77
72: ; preds = %69
%73 = load i32, i32* %6
%74 = icmp ne i32 %73, 2
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %77
77: ; preds = %75, %72, %69
br label %51
78: ; preds = %57
br label %79
79: ; preds = %373, %78
%80 = load i32, i32* %7
%81 = icmp sge i32 %80, 0
br i1 %81, label %82, label %374
82: ; preds = %79
%83 = load i32, i32* %6
%84 = icmp eq i32 %83, 1
br i1 %84, label %85, label %228
85: ; preds = %82
%86 = load i32**, i32*** %10
%87 = call i32 @print_board(i32** %86)
%88 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%89 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%90 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %4, i32* %5)
%91 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%92 = load i32, i32* %4
%93 = icmp slt i32 %92, 0
br i1 %93, label %103, label %94
94: ; preds = %85
%95 = load i32, i32* %4
%96 = icmp sge i32 %95, 3
br i1 %96, label %103, label %97
97: ; preds = %94
%98 = load i32, i32* %5
%99 = icmp slt i32 %98, 0
br i1 %99, label %103, label %100
100: ; preds = %97
%101 = load i32, i32* %5
%102 = icmp sge i32 %101, 3
br i1 %102, label %103, label %123
103: ; preds = %100, %97, %94, %85
br label %104
104: ; preds = %118, %103
%105 = load i32, i32* %4
%106 = icmp slt i32 %105, 0
br i1 %106, label %116, label %107
107: ; preds = %104
%108 = load i32, i32* %4
%109 = icmp sge i32 %108, 3
br i1 %109, label %116, label %110
110: ; preds = %107
%111 = load i32, i32* %5
%112 = icmp slt i32 %111, 0
br i1 %112, label %116, label %113
113: ; preds = %110
%114 = load i32, i32* %5
%115 = icmp sge i32 %114, 3
br label %116
116: ; preds = %113, %110, %107, %104
%117 = phi i1 [ true, %110 ], [ true, %107 ], [ true, %104 ], [ %115, %113 ]
br i1 %117, label %118, label %122
118: ; preds = %116
%119 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%120 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%121 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %4, i32* %5)
br label %104
122: ; preds = %116
br label %123
123: ; preds = %122, %100
%124 = load i32**, i32*** %10
%125 = load i32, i32* %4
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i32*, i32** %124, i64 %126
%128 = load i32*, i32** %127
%129 = load i32, i32* %5
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i32, i32* %128, i64 %130
%132 = load i32, i32* %131
%133 = load i32, i32* %9
%134 = icmp eq i32 %132, %133
br i1 %134, label %147, label %135
135: ; preds = %123
%136 = load i32**, i32*** %10
%137 = load i32, i32* %4
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds i32*, i32** %136, i64 %138
%140 = load i32*, i32** %139
%141 = load i32, i32* %5
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i32, i32* %140, i64 %142
%144 = load i32, i32* %143
%145 = load i32, i32* %8
%146 = icmp eq i32 %144, %145
br i1 %146, label %147, label %179
147: ; preds = %135, %123
br label %148
148: ; preds = %174, %147
%149 = load i32**, i32*** %10
%150 = load i32, i32* %4
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds i32*, i32** %149, i64 %151
%153 = load i32*, i32** %152
%154 = load i32, i32* %5
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds i32, i32* %153, i64 %155
%157 = load i32, i32* %156
%158 = load i32, i32* %9
%159 = icmp eq i32 %157, %158
br i1 %159, label %172, label %160
160: ; preds = %148
%161 = load i32**, i32*** %10
%162 = load i32, i32* %4
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds i32*, i32** %161, i64 %163
%165 = load i32*, i32** %164
%166 = load i32, i32* %5
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds i32, i32* %165, i64 %167
%169 = load i32, i32* %168
%170 = load i32, i32* %8
%171 = icmp eq i32 %169, %170
br label %172
172: ; preds = %160, %148
%173 = phi i1 [ true, %148 ], [ %171, %160 ]
br i1 %173, label %174, label %178
174: ; preds = %172
%175 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%176 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%177 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %4, i32* %5)
br label %148
178: ; preds = %172
br label %179
179: ; preds = %178, %135
%180 = load i32, i32* %8
%181 = load i32**, i32*** %10
%182 = load i32, i32* %4
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds i32*, i32** %181, i64 %183
%185 = load i32*, i32** %184
%186 = load i32, i32* %5
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds i32, i32* %185, i64 %187
store i32 %180, i32* %188
%189 = load i32**, i32*** %10
%190 = load i32, i32* %8
%191 = call i32 @check_win(i32** %189, i32 %190)
%192 = icmp eq i32 %191, 1
br i1 %192, label %193, label %197
193: ; preds = %179
%194 = load i32**, i32*** %10
%195 = call i32 @print_board(i32** %194)
%196 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %1
br label %374
197: ; preds = %179
%198 = load i32, i32* %7
%199 = sub nsw i32 %198, 1
store i32 %199, i32* %7
%200 = load i32, i32* %7
%201 = icmp eq i32 %200, 0
br i1 %201, label %202, label %211
202: ; preds = %197
%203 = load i32**, i32*** %10
%204 = load i32, i32* %8
%205 = call i32 @check_win(i32** %203, i32 %204)
%206 = icmp eq i32 %205, 0
br i1 %206, label %207, label %211
207: ; preds = %202
%208 = load i32**, i32*** %10
%209 = call i32 @print_board(i32** %208)
%210 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %1
br label %374
211: ; preds = %202, %197
%212 = load i32**, i32*** %10
%213 = load i32, i32* %9
%214 = load i32, i32* %8
%215 = load i32, i32* %9
%216 = call i32 @minimax(i32** %212, i32 %213, i32 0, i32 %214, i32 %215)
%217 = load i32**, i32*** %10
%218 = load i32, i32* %9
%219 = call i32 @check_win(i32** %217, i32 %218)
%220 = icmp eq i32 %219, 1
br i1 %220, label %221, label %225
221: ; preds = %211
%222 = load i32**, i32*** %10
%223 = call i32 @print_board(i32** %222)
%224 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %1
br label %374
225: ; preds = %211
%226 = load i32, i32* %7
%227 = sub nsw i32 %226, 1
store i32 %227, i32* %7
br label %228
228: ; preds = %225, %82
%229 = load i32, i32* %6
%230 = icmp eq i32 %229, 2
br i1 %230, label %231, label %373
231: ; preds = %228
%232 = load i32**, i32*** %10
%233 = load i32, i32* %9
%234 = load i32, i32* %8
%235 = load i32, i32* %9
%236 = call i32 @minimax(i32** %232, i32 %233, i32 0, i32 %234, i32 %235)
%237 = load i32**, i32*** %10
%238 = load i32, i32* %9
%239 = call i32 @check_win(i32** %237, i32 %238)
%240 = icmp eq i32 %239, 1
br i1 %240, label %241, label %245
241: ; preds = %231
%242 = load i32**, i32*** %10
%243 = call i32 @print_board(i32** %242)
%244 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
store i32 0, i32* %1
br label %374
245: ; preds = %231
%246 = load i32, i32* %7
%247 = sub nsw i32 %246, 1
store i32 %247, i32* %7
%248 = load i32, i32* %7
%249 = icmp eq i32 %248, 0
br i1 %249, label %250, label %259
250: ; preds = %245
%251 = load i32**, i32*** %10
%252 = load i32, i32* %9
%253 = call i32 @check_win(i32** %251, i32 %252)
%254 = icmp eq i32 %253, 0
br i1 %254, label %255, label %259
255: ; preds = %250
%256 = load i32**, i32*** %10
%257 = call i32 @print_board(i32** %256)
%258 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %1
br label %374
259: ; preds = %250, %245
%260 = load i32**, i32*** %10
%261 = call i32 @print_board(i32** %260)
%262 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%263 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.12, i64 0, i64 0))
%264 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %4, i32* %5)
%265 = load i32, i32* %4
%266 = icmp slt i32 %265, 0
br i1 %266, label %276, label %267
267: ; preds = %259
%268 = load i32, i32* %4
%269 = icmp sge i32 %268, 3
br i1 %269, label %276, label %270
270: ; preds = %267
%271 = load i32, i32* %5
%272 = icmp slt i32 %271, 0
br i1 %272, label %276, label %273
273: ; preds = %270
%274 = load i32, i32* %5
%275 = icmp sge i32 %274, 3
br i1 %275, label %276, label %296
276: ; preds = %273, %270, %267, %259
br label %277
277: ; preds = %291, %276
%278 = load i32, i32* %4
%279 = icmp slt i32 %278, 0
br i1 %279, label %289, label %280
280: ; preds = %277
%281 = load i32, i32* %4
%282 = icmp sge i32 %281, 3
br i1 %282, label %289, label %283
283: ; preds = %280
%284 = load i32, i32* %5
%285 = icmp slt i32 %284, 0
br i1 %285, label %289, label %286
286: ; preds = %283
%287 = load i32, i32* %5
%288 = icmp sge i32 %287, 3
br label %289
289: ; preds = %286, %283, %280, %277
%290 = phi i1 [ true, %283 ], [ true, %280 ], [ true, %277 ], [ %288, %286 ]
br i1 %290, label %291, label %295
291: ; preds = %289
%292 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%293 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.12, i64 0, i64 0))
%294 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %4, i32* %5)
br label %277
295: ; preds = %289
br label %296
296: ; preds = %295, %273
%297 = load i32**, i32*** %10
%298 = load i32, i32* %4
%299 = sext i32 %298 to i64
%300 = getelementptr inbounds i32*, i32** %297, i64 %299
%301 = load i32*, i32** %300
%302 = load i32, i32* %5
%303 = sext i32 %302 to i64
%304 = getelementptr inbounds i32, i32* %301, i64 %303
%305 = load i32, i32* %304
%306 = load i32, i32* %9
%307 = icmp eq i32 %305, %306
br i1 %307, label %320, label %308
308: ; preds = %296
%309 = load i32**, i32*** %10
%310 = load i32, i32* %4
%311 = sext i32 %310 to i64
%312 = getelementptr inbounds i32*, i32** %309, i64 %311
%313 = load i32*, i32** %312
%314 = load i32, i32* %5
%315 = sext i32 %314 to i64
%316 = getelementptr inbounds i32, i32* %313, i64 %315
%317 = load i32, i32* %316
%318 = load i32, i32* %8
%319 = icmp eq i32 %317, %318
br i1 %319, label %320, label %352
320: ; preds = %308, %296
br label %321
321: ; preds = %347, %320
%322 = load i32**, i32*** %10
%323 = load i32, i32* %4
%324 = sext i32 %323 to i64
%325 = getelementptr inbounds i32*, i32** %322, i64 %324
%326 = load i32*, i32** %325
%327 = load i32, i32* %5
%328 = sext i32 %327 to i64
%329 = getelementptr inbounds i32, i32* %326, i64 %328
%330 = load i32, i32* %329
%331 = load i32, i32* %9
%332 = icmp eq i32 %330, %331
br i1 %332, label %345, label %333
333: ; preds = %321
%334 = load i32**, i32*** %10
%335 = load i32, i32* %4
%336 = sext i32 %335 to i64
%337 = getelementptr inbounds i32*, i32** %334, i64 %336
%338 = load i32*, i32** %337
%339 = load i32, i32* %5
%340 = sext i32 %339 to i64
%341 = getelementptr inbounds i32, i32* %338, i64 %340
%342 = load i32, i32* %341
%343 = load i32, i32* %8
%344 = icmp eq i32 %342, %343
br label %345
345: ; preds = %333, %321
%346 = phi i1 [ true, %321 ], [ %344, %333 ]
br i1 %346, label %347, label %351
347: ; preds = %345
%348 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0))
%349 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.12, i64 0, i64 0))
%350 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %4, i32* %5)
br label %321
351: ; preds = %345
br label %352
352: ; preds = %351, %308
%353 = load i32, i32* %8
%354 = load i32**, i32*** %10
%355 = load i32, i32* %4
%356 = sext i32 %355 to i64
%357 = getelementptr inbounds i32*, i32** %354, i64 %356
%358 = load i32*, i32** %357
%359 = load i32, i32* %5
%360 = sext i32 %359 to i64
%361 = getelementptr inbounds i32, i32* %358, i64 %360
store i32 %353, i32* %361
%362 = load i32**, i32*** %10
%363 = load i32, i32* %8
%364 = call i32 @check_win(i32** %362, i32 %363)
%365 = icmp eq i32 %364, 1
br i1 %365, label %366, label %370
366: ; preds = %352
%367 = load i32**, i32*** %10
%368 = call i32 @print_board(i32** %367)
%369 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %1
br label %374
370: ; preds = %352
%371 = load i32, i32* %7
%372 = sub nsw i32 %371, 1
store i32 %372, i32* %7
br label %373
373: ; preds = %370, %228
br label %79
374: ; preds = %193, %207, %221, %241, %255, %366, %79
%375 = load i32, i32* %1
ret i32 %375
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.5 = [6 x i8] c"%d %d\00"
@.str.6 = [11 x i8] c"\1B[2J\1B[1;1H\00"
@str.18 = [47 x i8] c"Enter the row and the column you want to put X\00"
@str.21 = [14 x i8] c"Player's turn\00"
@str.23 = [9 x i8] c"You lost\00"
@str.24 = [5 x i8] c"Draw\00"
@str.25 = [8 x i8] c"You won\00"
@str.26 = [34 x i8] c"Please give me a box that is free\00"
@str.28 = [27 x i8] c"Please give me a valid box\00"
@str.29 = [47 x i8] c"Enter the row and the column you want to put O\00"
@str.30 = [35 x i8] c"Play first(=1) or play second(=2)?\00"
@str.31 = [26 x i8] c"Please give a valid input\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%7 = tail call dereferenceable_or_null(24) i8* @malloc(i32 24)
%8 = bitcast i8* %7 to i32**
%9 = tail call dereferenceable_or_null(12) i8* @malloc(i32 12)
%10 = bitcast i8* %7 to i8**
store i8* %9, i8** %10
%11 = tail call dereferenceable_or_null(12) i8* @malloc(i32 12)
%12 = getelementptr inbounds i32*, i32** %8, i64 1
%13 = bitcast i32** %12 to i8**
store i8* %11, i8** %13
%14 = tail call dereferenceable_or_null(12) i8* @malloc(i32 12)
%15 = getelementptr inbounds i32*, i32** %8, i64 2
%16 = bitcast i32** %15 to i8**
store i8* %14, i8** %16
br label %17
17: ; preds = %0, %31
%18 = phi i32 [ %28, %31 ], [ undef, %0 ]
%19 = phi i32 [ %27, %31 ], [ undef, %0 ]
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.30, i64 0, i64 0))
%21 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 1
%24 = select i1 %23, i32 79, i32 %19
%25 = select i1 %23, i32 88, i32 %18
%26 = icmp eq i32 %22, 2
%27 = select i1 %26, i32 88, i32 %24
%28 = select i1 %26, i32 79, i32 %25
%29 = add i32 %22, -3
%30 = icmp ult i32 %29, -2
br i1 %30, label %31, label %36
31: ; preds = %17
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.31, i64 0, i64 0))
%33 = load i32, i32* %3
%34 = add i32 %33, -3
%35 = icmp ult i32 %34, -2
br i1 %35, label %17, label %36
36: ; preds = %17, %31
%37 = phi i32 [ %22, %17 ], [ %33, %31 ]
br label %38
38: ; preds = %36, %201
%39 = phi i32 [ %202, %201 ], [ %37, %36 ]
%40 = phi i32 [ %199, %201 ], [ 9, %36 ]
%41 = icmp eq i32 %39, 1
br i1 %41, label %42, label %119
42: ; preds = %38
%43 = call i32 @print_board(i32** %8)
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.21, i64 0, i64 0))
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.29, i64 0, i64 0))
%46 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %1, i32* %2)
%47 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%48 = load i32, i32* %1
%49 = icmp ugt i32 %48, 2
%50 = load i32, i32* %2
%51 = icmp slt i32 %50, 0
%52 = select i1 %49, i1 true, i1 %51
%53 = icmp sgt i32 %50, 2
%54 = select i1 %52, i1 true, i1 %53
br i1 %54, label %55, label %66
55: ; preds = %42, %55
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.28, i64 0, i64 0))
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.29, i64 0, i64 0))
%58 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %1, i32* %2)
%59 = load i32, i32* %1
%60 = icmp ugt i32 %59, 2
%61 = load i32, i32* %2
%62 = icmp slt i32 %61, 0
%63 = select i1 %60, i1 true, i1 %62
%64 = icmp sgt i32 %61, 2
%65 = select i1 %63, i1 true, i1 %64
br i1 %65, label %55, label %66
66: ; preds = %55, %42
%67 = phi i32 [ %50, %42 ], [ %61, %55 ]
%68 = phi i32 [ %48, %42 ], [ %59, %55 ]
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds i32*, i32** %8, i64 %69
%71 = load i32*, i32** %70
%72 = zext i32 %67 to i64
%73 = getelementptr inbounds i32, i32* %71, i64 %72
%74 = load i32, i32* %73
%75 = icmp eq i32 %74, %28
%76 = icmp eq i32 %74, %27
%77 = select i1 %75, i1 true, i1 %76
br i1 %77, label %78, label %95
78: ; preds = %66, %78
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.26, i64 0, i64 0))
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.29, i64 0, i64 0))
%81 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %1, i32* %2)
%82 = load i32, i32* %1
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32*, i32** %8, i64 %83
%85 = load i32*, i32** %84
%86 = load i32, i32* %2
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %85, i64 %87
%89 = load i32, i32* %88
%90 = icmp eq i32 %89, %28
%91 = icmp eq i32 %89, %27
%92 = select i1 %90, i1 true, i1 %91
br i1 %92, label %78, label %93
93: ; preds = %78
%94 = sext i32 %86 to i64
br label %95
95: ; preds = %93, %66
%96 = phi i64 [ %72, %66 ], [ %94, %93 ]
%97 = phi i32* [ %71, %66 ], [ %85, %93 ]
%98 = getelementptr inbounds i32, i32* %97, i64 %96
store i32 %27, i32* %98
%99 = call i32 @check_win(i32** %8, i32 %27)
%100 = icmp eq i32 %99, 1
br i1 %100, label %101, label %103
101: ; preds = %95
%102 = call i32 @print_board(i32** %8)
br label %203
103: ; preds = %95
%104 = icmp eq i32 %40, 1
br i1 %104, label %105, label %110
105: ; preds = %103
%106 = call i32 @check_win(i32** %8, i32 %27)
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %110
108: ; preds = %105
%109 = call i32 @print_board(i32** %8)
br label %203
110: ; preds = %105, %103
%111 = call i32 @minimax(i32** %8, i32 %28, i32 0, i32 %27, i32 %28)
%112 = call i32 @check_win(i32** %8, i32 %28)
%113 = icmp eq i32 %112, 1
br i1 %113, label %114, label %116
114: ; preds = %110
%115 = call i32 @print_board(i32** %8)
br label %203
116: ; preds = %110
%117 = add nsw i32 %40, -2
%118 = load i32, i32* %3
br label %119
119: ; preds = %116, %38
%120 = phi i32 [ %118, %116 ], [ %39, %38 ]
%121 = phi i32 [ %117, %116 ], [ %40, %38 ]
%122 = icmp eq i32 %120, 2
br i1 %122, label %123, label %198
123: ; preds = %119
%124 = call i32 @minimax(i32** %8, i32 %28, i32 0, i32 %27, i32 %28)
%125 = call i32 @check_win(i32** %8, i32 %28)
%126 = icmp eq i32 %125, 1
br i1 %126, label %127, label %129
127: ; preds = %123
%128 = call i32 @print_board(i32** %8)
br label %203
129: ; preds = %123
%130 = icmp eq i32 %121, 1
br i1 %130, label %131, label %136
131: ; preds = %129
%132 = call i32 @check_win(i32** %8, i32 %28)
%133 = icmp eq i32 %132, 0
br i1 %133, label %134, label %136
134: ; preds = %131
%135 = call i32 @print_board(i32** %8)
br label %203
136: ; preds = %131, %129
%137 = call i32 @print_board(i32** %8)
%138 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.21, i64 0, i64 0))
%139 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.18, i64 0, i64 0))
%140 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %1, i32* %2)
%141 = load i32, i32* %1
%142 = icmp ugt i32 %141, 2
%143 = load i32, i32* %2
%144 = icmp slt i32 %143, 0
%145 = select i1 %142, i1 true, i1 %144
%146 = icmp sgt i32 %143, 2
%147 = select i1 %145, i1 true, i1 %146
br i1 %147, label %148, label %159
148: ; preds = %136, %148
%149 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.28, i64 0, i64 0))
%150 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.18, i64 0, i64 0))
%151 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %1, i32* %2)
%152 = load i32, i32* %1
%153 = icmp ugt i32 %152, 2
%154 = load i32, i32* %2
%155 = icmp slt i32 %154, 0
%156 = select i1 %153, i1 true, i1 %155
%157 = icmp sgt i32 %154, 2
%158 = select i1 %156, i1 true, i1 %157
br i1 %158, label %148, label %159
159: ; preds = %148, %136
%160 = phi i32 [ %143, %136 ], [ %154, %148 ]
%161 = phi i32 [ %141, %136 ], [ %152, %148 ]
%162 = zext i32 %161 to i64
%163 = getelementptr inbounds i32*, i32** %8, i64 %162
%164 = load i32*, i32** %163
%165 = zext i32 %160 to i64
%166 = getelementptr inbounds i32, i32* %164, i64 %165
%167 = load i32, i32* %166
%168 = icmp eq i32 %167, %28
%169 = icmp eq i32 %167, %27
%170 = select i1 %168, i1 true, i1 %169
br i1 %170, label %171, label %188
171: ; preds = %159, %171
%172 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.26, i64 0, i64 0))
%173 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.18, i64 0, i64 0))
%174 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32* %1, i32* %2)
%175 = load i32, i32* %1
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds i32*, i32** %8, i64 %176
%178 = load i32*, i32** %177
%179 = load i32, i32* %2
%180 = sext i32 %179 to i64
%181 = getelementptr inbounds i32, i32* %178, i64 %180
%182 = load i32, i32* %181
%183 = icmp eq i32 %182, %28
%184 = icmp eq i32 %182, %27
%185 = select i1 %183, i1 true, i1 %184
br i1 %185, label %171, label %186
186: ; preds = %171
%187 = sext i32 %179 to i64
br label %188
188: ; preds = %186, %159
%189 = phi i64 [ %165, %159 ], [ %187, %186 ]
%190 = phi i32* [ %164, %159 ], [ %178, %186 ]
%191 = getelementptr inbounds i32, i32* %190, i64 %189
store i32 %27, i32* %191
%192 = call i32 @check_win(i32** %8, i32 %27)
%193 = icmp eq i32 %192, 1
br i1 %193, label %194, label %196
194: ; preds = %188
%195 = call i32 @print_board(i32** %8)
br label %203
196: ; preds = %188
%197 = add nsw i32 %121, -2
br label %198
198: ; preds = %196, %119
%199 = phi i32 [ %197, %196 ], [ %121, %119 ]
%200 = icmp sgt i32 %199, -1
br i1 %200, label %201, label %206
201: ; preds = %198
%202 = load i32, i32* %3
br label %38
203: ; preds = %101, %108, %114, %127, %134, %194
%204 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.25, i64 0, i64 0), %194 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.24, i64 0, i64 0), %134 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @str.23, i64 0, i64 0), %127 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @str.23, i64 0, i64 0), %114 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.24, i64 0, i64 0), %108 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.25, i64 0, i64 0), %101 ]
%205 = call i32 @puts(i8* dereferenceable(1) %204)
br label %206
206: ; preds = %198, %203
ret i32 0
}