#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 analize_board(char **);
int /*<<< orphan*/ draw_board(char **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  char board[3][3] = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
  int num_moves = 1;
  int player = 0;
  int i = 0;
  int j = 0;
  printf("\n Player 1 plays as X\n");
  printf(" Player 2 plays as O\n\n");
  draw_board(board);
  while (num_moves != 10) {
    switch (analize_board(board)) {
    case 0:
      if ((num_moves % 2) != 0)
        player = 1;
      else
        player = 2;
      while (1) {
        printf(" Player %d insert number of row: ", player);
        scanf("%d", &i);
        i--;
        printf(" Player %d insert number of column: ", player);
        scanf("%d", &j);
        j--;
        if ((i >= 0 && i <= 2) && (j >= 0 && j <= 2) && board[i][j] == ' ')
          break;
        printf("\n Please insert correct values\n");
      }
      num_moves++;
      if (player == 1)
        board[i][j] = 'X';
      else
        board[i][j] = 'O';
      draw_board(board);
      break;
    case 1:
      printf(" Player 1 wins!\n\n");
      return 0;
    case 2:
      printf(" Player 2 wins!\n\n");
      return 0;
    }
  }
  printf(" A draw!\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0xd(%rbp)
mov    0xea8(%rip),%al
mov    %al,-0x5(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xd(%rbp),%rdi
call   1030 <draw_board@plt>
cmpl   $0xa,-0x14(%rbp)
je     1358 <main+0x218>
lea    -0xd(%rbp),%rdi
call   1050 <analize_board@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
test   %eax,%eax
je     11eb <main+0xab>
jmp    11c9 <main+0x89>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
je     131f <main+0x1df>
jmp    11da <main+0x9a>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     1339 <main+0x1f9>
jmp    1353 <main+0x213>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     120b <main+0xcb>
movl   $0x1,-0x18(%rbp)
jmp    1212 <main+0xd2>
movl   $0x2,-0x18(%rbp)
jmp    1217 <main+0xd7>
mov    -0x18(%rbp),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2a(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe00(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     12b8 <main+0x178>
cmpl   $0x2,-0x1c(%rbp)
jg     12b8 <main+0x178>
cmpl   $0x0,-0x20(%rbp)
jl     12b8 <main+0x178>
cmpl   $0x2,-0x20(%rbp)
jg     12b8 <main+0x178>
movslq -0x1c(%rbp),%rcx
lea    -0xd(%rbp),%rax
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    12b8 <main+0x178>
jmp    12cb <main+0x18b>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1217 <main+0xd7>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    12fa <main+0x1ba>
movslq -0x1c(%rbp),%rcx
lea    -0xd(%rbp),%rax
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movb   $0x58,(%rax,%rcx,1)
jmp    1311 <main+0x1d1>
movslq -0x1c(%rbp),%rcx
lea    -0xd(%rbp),%rax
imul   $0x3,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
movb   $0x4f,(%rax,%rcx,1)
lea    -0xd(%rbp),%rdi
call   1030 <draw_board@plt>
jmp    1353 <main+0x213>
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    136d <main+0x22d>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    136d <main+0x22d>
jmp    11a4 <main+0x64>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x2020202020202020,%rax
20 20 20
mov    %rax,0x8(%rsp)
movb   $0x20,0x10(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0xec2(%rip),%rdi
call   1040 <puts@plt>
lea    0xecc(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rdi
call   1030 <draw_board@plt>
mov    $0x1,%r12d
lea    0xe72(%rip),%rbx
lea    0x4(%rsp),%r13
lea    0xe69(%rip),%rbp
mov    %rsp,%r14
lea    0xedc(%rip),%r15
jmp    11da <main+0x8a>
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%r12d
je     12bd <main+0x16d>
lea    0x8(%rsp),%rdi
call   1060 <analize_board@plt>
test   %eax,%eax
je     1200 <main+0xb0>
cmp    $0x1,%eax
je     12c6 <main+0x176>
cmp    $0x2,%eax
jne    11d0 <main+0x80>
jmp    12cf <main+0x17f>
nopl   0x0(%rax,%rax,1)
mov    %r12d,0x14(%rsp)
mov    %r12d,%eax
and    $0x1,%eax
mov    $0x2,%r12d
sub    %eax,%r12d
jmp    1228 <main+0xd8>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <puts@plt>
lea    0xdd1(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <scanf@plt>
addl   $0xffffffff,0x4(%rsp)
mov    %rbp,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%edx
lea    -0x1(%rdx),%eax
mov    %eax,(%rsp)
mov    0x4(%rsp),%ecx
cmp    $0x2,%rcx
ja     1220 <main+0xd0>
test   %edx,%edx
jle    1220 <main+0xd0>
cmp    $0x3,%edx
jg     1220 <main+0xd0>
mov    %eax,%edx
lea    (%rcx,%rcx,2),%rax
add    %rsp,%rax
add    $0x8,%rax
cmpb   $0x20,(%rdx,%rax,1)
jne    1220 <main+0xd0>
add    %rdx,%rax
mov    0x14(%rsp),%edx
mov    %edx,%r12d
add    $0x1,%r12d
xor    %ecx,%ecx
test   $0x1,%dl
setne  %cl
lea    (%rcx,%rcx,8),%ecx
add    $0x4f,%ecx
mov    %cl,(%rax)
lea    0x8(%rsp),%rdi
call   1030 <draw_board@plt>
jmp    11d0 <main+0x80>
lea    0xdb2(%rip),%rdi
jmp    12d6 <main+0x186>
lea    0xdc4(%rip),%rdi
jmp    12d6 <main+0x186>
lea    0xdaa(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.board = [3 x [3 x i8]] [[3 x i8] c" ", [3 x i8] c" ", [3 x i8] c" "]
@.str = [23 x i8] c"\0A Player 1 plays as X\0A\00"
@.str.1 = [23 x i8] c" Player 2 plays as O\0A\0A\00"
@.str.2 = [34 x i8] c" Player %d insert number of row: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [37 x i8] c" Player %d insert number of column: \00"
@.str.5 = [32 x i8] c"\0A Please insert correct values\0A\00"
@.str.6 = [18 x i8] c" Player 1 wins!\0A\0A\00"
@.str.7 = [18 x i8] c" Player 2 wins!\0A\0A\00"
@.str.8 = [11 x i8] c" A draw!\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x [3 x i8]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [3 x [3 x i8]]* %2 to i8*
store i32 1, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 0
%11 = bitcast [3 x i8]* %10 to i8**
%12 = call i32 @draw_board(i8** %11)
br label %13
13: ; preds = %89, %0
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %90
16: ; preds = %13
%17 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 0
%18 = bitcast [3 x i8]* %17 to i8**
%19 = call i32 @analize_board(i8** %18)
switch i32 %19, label %89 [
i32 0, label %20
i32 1, label %85
i32 2, label %87
]
20: ; preds = %16
%21 = load i32, i32* %3
%22 = srem i32 %21, 2
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 1, i32* %4
br label %26
25: ; preds = %20
store i32 2, i32* %4
br label %26
26: ; preds = %25, %24
br label %27
27: ; preds = %26, %60
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%31 = load i32, i32* %5
%32 = add nsw i32 %31, -1
store i32 %32, i32* %5
%33 = load i32, i32* %4
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%36 = load i32, i32* %6
%37 = add nsw i32 %36, -1
store i32 %37, i32* %6
%38 = load i32, i32* %5
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %60
40: ; preds = %27
%41 = load i32, i32* %5
%42 = icmp sle i32 %41, 2
br i1 %42, label %43, label %60
43: ; preds = %40
%44 = load i32, i32* %6
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %60
46: ; preds = %43
%47 = load i32, i32* %6
%48 = icmp sle i32 %47, 2
br i1 %48, label %49, label %60
49: ; preds = %46
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 %51
%53 = load i32, i32* %6
%54 = sext 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, 32
br i1 %58, label %59, label %60
59: ; preds = %49
br label %62
60: ; preds = %49, %46, %43, %40, %27
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %27
62: ; preds = %59
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
%65 = load i32, i32* %4
%66 = icmp eq i32 %65, 1
br i1 %66, label %67, label %74
67: ; preds = %62
%68 = load i32, i32* %5
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 %69
%71 = load i32, i32* %6
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [3 x i8], [3 x i8]* %70, i64 0, i64 %72
store i8 88, i8* %73
br label %81
74: ; preds = %62
%75 = load i32, i32* %5
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 %76
%78 = load i32, i32* %6
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [3 x i8], [3 x i8]* %77, i64 0, i64 %79
store i8 79, i8* %80
br label %81
81: ; preds = %74, %67
%82 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %2, i64 0, i64 0
%83 = bitcast [3 x i8]* %82 to i8**
%84 = call i32 @draw_board(i8** %83)
br label %89
85: ; preds = %16
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %92
87: ; preds = %16
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %1
br label %92
89: ; preds = %16, %81
br label %13
90: ; preds = %13
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %1
br label %92
92: ; preds = %90, %87, %85
%93 = load i32, i32* %1
ret i32 %93
}

LLVM IR (-O2):
@.str.2 = [34 x i8] c" Player %d insert number of row: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [37 x i8] c" Player %d insert number of column: \00"
@str = [22 x i8] c"\0A Player 1 plays as X\00"
@str.9 = [22 x i8] c" Player 2 plays as O\0A\00"
@str.10 = [10 x i8] c" A draw!\0A\00"
@str.11 = [17 x i8] c" Player 2 wins!\0A\00"
@str.12 = [17 x i8] c" Player 1 wins!\0A\00"
@str.13 = [31 x i8] c"\0A Please insert correct values\00"
define i32 @main() {
%1 = alloca [3 x [3 x i8]]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %1, i64 0, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%9 = bitcast [3 x [3 x i8]]* %1 to i8**
%10 = call i32 @draw_board(i8** %9)
br label %11
11: ; preds = %0, %45
%12 = phi i32 [ 1, %0 ], [ %46, %45 ]
%13 = call i32 @analize_board(i8** %9)
switch i32 %13, label %45 [
i32 0, label %14
i32 1, label %49
i32 2, label %48
]
14: ; preds = %11
%15 = and i32 %12, 1
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i32 2, i32 1
br label %18
18: ; preds = %39, %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%21 = load i32, i32* %2
%22 = add nsw i32 %21, -1
store i32 %22, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%25 = load i32, i32* %3
%26 = add nsw i32 %25, -1
store i32 %26, i32* %3
%27 = load i32, i32* %2
%28 = icmp ult i32 %27, 3
%29 = icmp sgt i32 %25, 0
%30 = select i1 %28, i1 %29, i1 false
%31 = icmp slt i32 %25, 4
%32 = select i1 %30, i1 %31, i1 false
br i1 %32, label %33, label %39
33: ; preds = %18
%34 = zext i32 %27 to i64
%35 = zext i32 %26 to i64
%36 = getelementptr inbounds [3 x [3 x i8]], [3 x [3 x i8]]* %1, i64 0, i64 %34, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 32
br i1 %38, label %41, label %39
39: ; preds = %33, %18
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.13, i64 0, i64 0))
br label %18
41: ; preds = %33
%42 = add nsw i32 %12, 1
%43 = select i1 %16, i8 79, i8 88
store i8 %43, i8* %36
%44 = call i32 @draw_board(i8** %9)
br label %45
45: ; preds = %11, %41
%46 = phi i32 [ %12, %11 ], [ %42, %41 ]
%47 = icmp eq i32 %46, 10
br i1 %47, label %49, label %11
48: ; preds = %11
br label %49
49: ; preds = %45, %11, %48
%50 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.11, i64 0, i64 0), %48 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.10, i64 0, i64 0), %45 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @str.12, i64 0, i64 0), %11 ]
%51 = call i32 @puts(i8* dereferenceable(1) %50)
ret i32 0
}