int main() {
  srand((time(0)));
  int i, j;
  char again[2], winner, **board;
  board = (char **)malloc(sizeof(char *) * 3);
  for (i = 0; i < 3; i++)
    board[i] = (char *)malloc(sizeof(char) * 3);
  printf("\nWelcome to a game of Tic-Tac-Toe!\n");
  do {
    board = initboard(board);
    displayboard(board);
    do {
      board = human_move(board, 'x');
      displayboard(board);
      winner = checkwin(board, 'x');
      if (winner != 'x' && winner != ' ') {
        if (computer_move(board, 'o', 'x'))
          winner = checkwin(board, 'o');
        else
          printf("\nComputer passed\n");
        displayboard(board);
      }
    } while (winner == '-');
    if (winner != ' ')
      printf("THE WINNER IS %c!\n", winner);
    else
      printf("IT'S A TIE.\n");
    printf("\nPlay again (y)?: ");
    scanf("%s", again);
  } while (again[0] == 'y');
  for (i = 0; i < 3; i++)
    free(board[i]);
  free(board);
  printf("\nThank you for playing.\n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
mov    $0x0,%al
call   1080 <time@plt>
mov    %eax,%edi
mov    $0x0,%al
call   1070 <srand@plt>
mov    $0x18,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1217 <main+0x67>
mov    $0x3,%edi
call   1090 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e6 <main+0x36>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   10c0 <initboard@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   10d0 <displayboard@plt>
mov    -0x18(%rbp),%rdi
mov    $0x78,%esi
mov    $0x0,%al
call   10a0 <human_move@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   10d0 <displayboard@plt>
mov    -0x18(%rbp),%rdi
mov    $0x78,%esi
mov    $0x0,%al
call   1040 <checkwin@plt>
mov    %al,-0xf(%rbp)
movsbl -0xf(%rbp),%eax
cmp    $0x78,%eax
je     12de <main+0x12e>
movsbl -0xf(%rbp),%eax
cmp    $0x20,%eax
je     12de <main+0x12e>
mov    -0x18(%rbp),%rdi
mov    $0x6f,%esi
mov    $0x78,%edx
mov    $0x0,%al
call   1060 <computer_move@plt>
cmp    $0x0,%eax
je     12c5 <main+0x115>
mov    -0x18(%rbp),%rdi
mov    $0x6f,%esi
mov    $0x0,%al
call   1040 <checkwin@plt>
mov    %al,-0xf(%rbp)
jmp    12d3 <main+0x123>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   10d0 <displayboard@plt>
jmp    12e3 <main+0x133>
movsbl -0xf(%rbp),%eax
cmp    $0x2d,%eax
je     1241 <main+0x91>
movsbl -0xf(%rbp),%eax
cmp    $0x20,%eax
je     1314 <main+0x164>
movsbl -0xf(%rbp),%esi
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1322 <main+0x172>
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xe(%rbp),%rsi
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   10b0 <scanf@plt>
movsbl -0xe(%rbp),%eax
cmp    $0x79,%eax
je     1225 <main+0x75>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    137f <main+0x1cf>
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1356 <main+0x1a6>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
xor    %eax,%eax
call   1090 <time@plt>
mov    %eax,%edi
xor    %eax,%eax
call   1080 <srand@plt>
mov    $0x18,%edi
call   10a0 <malloc@plt>
mov    %rax,%rbx
mov    $0x3,%edi
call   10a0 <malloc@plt>
mov    %rax,(%rbx)
mov    $0x3,%edi
call   10a0 <malloc@plt>
mov    %rax,0x8(%rbx)
mov    $0x3,%edi
call   10a0 <malloc@plt>
mov    %rax,0x10(%rbx)
lea    0xe0f(%rip),%rdi
call   1040 <puts@plt>
lea    0xded(%rip),%r15
lea    0xdf9(%rip),%r12
lea    0x6(%rsp),%r13
lea    0xe38(%rip),%r14
jmp    126e <main+0xae>
nopl   0x0(%rax,%rax,1)
lea    0xe05(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   10c0 <scanf@plt>
cmpb   $0x79,0x6(%rsp)
jne    1334 <main+0x174>
mov    %rbx,%rdi
xor    %eax,%eax
call   10d0 <initboard@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   10e0 <displayboard@plt>
jmp    12a4 <main+0xe4>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   10e0 <displayboard@plt>
shl    $0x18,%ebp
cmp    $0x2d000000,%ebp
jne    1310 <main+0x150>
mov    %rbx,%rdi
mov    $0x78,%esi
xor    %eax,%eax
call   10b0 <human_move@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   10e0 <displayboard@plt>
mov    %rbx,%rdi
mov    $0x78,%esi
xor    %eax,%eax
call   1050 <checkwin@plt>
mov    %eax,%ebp
shl    $0x18,%eax
cmp    $0x20000000,%eax
je     1299 <main+0xd9>
cmp    $0x78000000,%eax
je     1299 <main+0xd9>
mov    %rbx,%rdi
mov    $0x6f,%esi
mov    $0x78,%edx
xor    %eax,%eax
call   1070 <computer_move@plt>
test   %eax,%eax
je     1287 <main+0xc7>
mov    %rbx,%rdi
mov    $0x6f,%esi
xor    %eax,%eax
call   1050 <checkwin@plt>
mov    %eax,%ebp
jmp    128f <main+0xcf>
nopl   (%rax)
cmp    $0x20000000,%ebp
je     1240 <main+0x80>
sar    $0x18,%ebp
lea    0xcda(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    124c <main+0x8c>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    0x8(%rbx),%rdi
call   1030 <free@plt>
mov    0x10(%rbx),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xcfb(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"\0AWelcome to a game of Tic-Tac-Toe!\0A\00"
@.str.1 = [18 x i8] c"\0AComputer passed\0A\00"
@.str.2 = [19 x i8] c"THE WINNER IS %c!\0A\00"
@.str.3 = [13 x i8] c"IT'S A TIE.\0A\00"
@.str.4 = [19 x i8] c"\0APlay again (y)?: \00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [26 x i8] c"\0AThank you for playing.\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = alloca i8
%6 = alloca i8**
store i32 0, i32* %1
%7 = call i32 (i32, ...) bitcast (i32 (...)* @time to i32 (i32, ...)*)(i32 0)
%8 = call i32 (i32, ...) bitcast (i32 (...)* @srand to i32 (i32, ...)*)(i32 %7)
%9 = call i8* @malloc(i64 24)
%10 = bitcast i8* %9 to i8**
store i8** %10, i8*** %6
store i32 0, i32* %2
br label %11
11: ; preds = %20, %0
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = call i8* @malloc(i64 3)
%16 = load i8**, i8*** %6
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
store i8* %15, i8** %19
br label %20
20: ; preds = %14
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %11
23: ; preds = %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %81, %23
%26 = load i8**, i8*** %6
%27 = call i32 (i8**, ...) bitcast (i32 (...)* @initboard to i32 (i8**, ...)*)(i8** %26)
%28 = sext i32 %27 to i64
%29 = inttoptr i64 %28 to i8**
store i8** %29, i8*** %6
%30 = load i8**, i8*** %6
%31 = call i32 (i8**, ...) bitcast (i32 (...)* @displayboard to i32 (i8**, ...)*)(i8** %30)
br label %32
32: ; preds = %63, %25
%33 = load i8**, i8*** %6
%34 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @human_move to i32 (i8**, i32, ...)*)(i8** %33, i32 120)
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i8**
store i8** %36, i8*** %6
%37 = load i8**, i8*** %6
%38 = call i32 (i8**, ...) bitcast (i32 (...)* @displayboard to i32 (i8**, ...)*)(i8** %37)
%39 = load i8**, i8*** %6
%40 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @checkwin to i32 (i8**, i32, ...)*)(i8** %39, i32 120)
%41 = trunc i32 %40 to i8
store i8 %41, i8* %5
%42 = load i8, i8* %5
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 120
br i1 %44, label %45, label %62
45: ; preds = %32
%46 = load i8, i8* %5
%47 = sext i8 %46 to i32
%48 = icmp ne i32 %47, 32
br i1 %48, label %49, label %62
49: ; preds = %45
%50 = load i8**, i8*** %6
%51 = call i32 (i8**, i32, i32, ...) bitcast (i32 (...)* @computer_move to i32 (i8**, i32, i32, ...)*)(i8** %50, i32 111, i32 120)
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i8**, i8*** %6
%55 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @checkwin to i32 (i8**, i32, ...)*)(i8** %54, i32 111)
%56 = trunc i32 %55 to i8
store i8 %56, i8* %5
br label %59
57: ; preds = %49
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = load i8**, i8*** %6
%61 = call i32 (i8**, ...) bitcast (i32 (...)* @displayboard to i32 (i8**, ...)*)(i8** %60)
br label %62
62: ; preds = %59, %45, %32
br label %63
63: ; preds = %62
%64 = load i8, i8* %5
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 45
br i1 %66, label %32, label %67
67: ; preds = %63
%68 = load i8, i8* %5
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %69, 32
br i1 %70, label %71, label %75
71: ; preds = %67
%72 = load i8, i8* %5
%73 = sext i8 %72 to i32
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %73)
br label %77
75: ; preds = %67
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %77
77: ; preds = %75, %71
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%79 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%80 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %79)
br label %81
81: ; preds = %77
%82 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp eq i32 %84, 121
br i1 %85, label %25, label %86
86: ; preds = %81
store i32 0, i32* %2
br label %87
87: ; preds = %96, %86
%88 = load i32, i32* %2
%89 = icmp slt i32 %88, 3
br i1 %89, label %90, label %99
90: ; preds = %87
%91 = load i8**, i8*** %6
%92 = load i32, i32* %2
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
br label %96
96: ; preds = %90
%97 = load i32, i32* %2
%98 = add nsw i32 %97, 1
store i32 %98, i32* %2
br label %87
99: ; preds = %87
%100 = load i8**, i8*** %6
%101 = bitcast i8** %100 to i8*
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [19 x i8] c"THE WINNER IS %c!\0A\00"
@.str.4 = [19 x i8] c"\0APlay again (y)?: \00"
@.str.5 = [3 x i8] c"%s\00"
@str = [35 x i8] c"\0AWelcome to a game of Tic-Tac-Toe!\00"
@str.7 = [12 x i8] c"IT'S A TIE.\00"
@str.8 = [25 x i8] c"\0AThank you for playing.\0A\00"
@str.9 = [17 x i8] c"\0AComputer passed\00"
define i32 @main() {
%1 = alloca [2 x i8]
%2 = tail call i32 (i32, ...) bitcast (i32 (...)* @time to i32 (i32, ...)*)(i32 0)
%3 = tail call i32 (i32, ...) bitcast (i32 (...)* @srand to i32 (i32, ...)*)(i32 %2)
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %1, i64 0, i64 0
%5 = tail call dereferenceable_or_null(24) i8* @malloc(i64 24)
%6 = bitcast i8* %5 to i8**
%7 = tail call dereferenceable_or_null(3) i8* @malloc(i64 3)
store i8* %7, i8** %6
%8 = tail call dereferenceable_or_null(3) i8* @malloc(i64 3)
%9 = getelementptr inbounds i8*, i8** %6, i64 1
store i8* %8, i8** %9
%10 = tail call dereferenceable_or_null(3) i8* @malloc(i64 3)
%11 = getelementptr inbounds i8*, i8** %6, i64 2
store i8* %10, i8** %11
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %45, %0
%14 = phi i8** [ %6, %0 ], [ %46, %45 ]
%15 = call i32 (i8**, ...) bitcast (i32 (...)* @initboard to i32 (i8**, ...)*)(i8** %14)
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8**
%18 = call i32 (i8**, ...) bitcast (i32 (...)* @displayboard to i32 (i8**, ...)*)(i8** %17)
br label %19
19: ; preds = %37, %13
%20 = phi i8** [ %17, %13 ], [ %23, %37 ]
%21 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @human_move to i32 (i8**, i32, ...)*)(i8** %20, i32 120)
%22 = sext i32 %21 to i64
%23 = inttoptr i64 %22 to i8**
%24 = call i32 (i8**, ...) bitcast (i32 (...)* @displayboard to i32 (i8**, ...)*)(i8** %23)
%25 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @checkwin to i32 (i8**, i32, ...)*)(i8** %23, i32 120)
%26 = shl i32 %25, 24
switch i32 %26, label %27 [
i32 2013265920, label %37
i32 536870912, label %37
]
27: ; preds = %19
%28 = call i32 (i8**, i32, i32, ...) bitcast (i32 (...)* @computer_move to i32 (i8**, i32, i32, ...)*)(i8** %23, i32 111, i32 120)
%29 = icmp eq i32 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 (i8**, i32, ...) bitcast (i32 (...)* @checkwin to i32 (i8**, i32, ...)*)(i8** %23, i32 111)
br label %34
32: ; preds = %27
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
%35 = phi i32 [ %31, %30 ], [ %25, %32 ]
%36 = call i32 (i8**, ...) bitcast (i32 (...)* @displayboard to i32 (i8**, ...)*)(i8** %23)
br label %37
37: ; preds = %19, %19, %34
%38 = phi i32 [ %35, %34 ], [ %25, %19 ], [ %25, %19 ]
%39 = shl i32 %38, 24
switch i32 %39, label %40 [
i32 754974720, label %19
i32 536870912, label %43
]
40: ; preds = %37
%41 = ashr exact i32 %39, 24
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %41)
br label %45
43: ; preds = %37
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.7, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = inttoptr i64 %22 to i8**
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%49 = load i8, i8* %4
%50 = icmp eq i8 %49, 121
br i1 %50, label %13, label %51
51: ; preds = %45
%52 = inttoptr i64 %22 to i8**
%53 = load i8*, i8** %52
%54 = getelementptr inbounds i8*, i8** %52, i64 1
%55 = load i8*, i8** %54
%56 = getelementptr inbounds i8*, i8** %52, i64 2
%57 = load i8*, i8** %56
%58 = inttoptr i64 %22 to i8*
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
ret i32 0
}