#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 best_move(char **, int **, char);
int /*<<< orphan*/ make_move(char **, int, int, char);
int /*<<< orphan*/ valid_moves(char **, int **, char);
void computer_move(char board[][6], int moves[][6], char player) {
  int row = 0;
  int col = 0;
  int best_row = 0;
  int best_col = 0;
  int i = 0;
  int j = 0;
  int new_score = 0;
  int score = 100;
  char temp_board[6][6];
  int temp_moves[6][6];
  char opponent = (player == 'O') ? '@' : 'O';
  for (row = 0; row < 6; row++)
    for (col = 0; col < 6; col++) {
      if (moves[row][col] == 0)
        continue;
      for (i = 0; i < 6; i++)
        for (j = 0; j < 6; j++)
          temp_board[i][j] = board[i][j];
      make_move(temp_board, row, col, player);
      valid_moves(temp_board, temp_moves, opponent);
      new_score = best_move(temp_board, temp_moves, opponent);
      if (new_score < score) {
        score = new_score;
        best_row = row;
        best_col = col;
      }
    }
  make_move(board, best_row, best_col, player);
}


x86 assembly (clang, -O0):
<computer_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x64,-0x34(%rbp)
movsbl -0x11(%rbp),%edx
mov    $0x4f,%eax
mov    $0x40,%ecx
cmp    $0x4f,%edx
cmove  %ecx,%eax
mov    %al,-0xf1(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x6,-0x18(%rbp)
jge    12d5 <computer_move+0x1a5>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x6,-0x1c(%rbp)
jge    12c2 <computer_move+0x192>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11de <computer_move+0xae>
jmp    12b4 <computer_move+0x184>
movl   $0x0,-0x28(%rbp)
cmpl   $0x6,-0x28(%rbp)
jge    124d <computer_move+0x11d>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x6,-0x2c(%rbp)
jge    123a <computer_move+0x10a>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
imul   $0x6,%rcx,%rcx
add    %rcx,%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x28(%rbp),%rcx
lea    -0x60(%rbp),%rax
imul   $0x6,%rcx,%rcx
add    %rcx,%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11f6 <computer_move+0xc6>
jmp    123f <computer_move+0x10f>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e5 <computer_move+0xb5>
lea    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
movsbl -0x11(%rbp),%ecx
call   1030 <make_move@plt>
lea    -0x60(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
movsbl -0xf1(%rbp),%edx
call   1050 <valid_moves@plt>
lea    -0x60(%rbp),%rdi
lea    -0xf0(%rbp),%rsi
movsbl -0xf1(%rbp),%edx
call   1040 <best_move@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    12af <computer_move+0x17f>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    12b4 <computer_move+0x184>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b2 <computer_move+0x82>
jmp    12c7 <computer_move+0x197>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a1 <computer_move+0x71>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
movsbl -0x11(%rbp),%ecx
call   1030 <make_move@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computer_move>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %rsi,0x18(%rsp)
mov    %rdi,%rbx
mov    %edx,0xc(%rsp)
cmp    $0x4f,%dl
mov    $0x40,%eax
mov    $0x4f,%ecx
cmove  %eax,%ecx
mov    %ecx,0x14(%rsp)
xor    %ebp,%ebp
movl   $0x64,0x10(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
jmp    1194 <computer_move+0x64>
nopl   (%rax)
add    $0x1,%rbp
addq   $0x18,0x18(%rsp)
cmp    $0x6,%rbp
je     1229 <computer_move+0xf9>
xor    %r14d,%r14d
jmp    11aa <computer_move+0x7a>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    $0x6,%r14
je     1180 <computer_move+0x50>
mov    0x18(%rsp),%rax
cmpl   $0x0,(%rax,%r14,4)
je     11a0 <computer_move+0x70>
mov    0x20(%rbx),%eax
mov    %eax,0x40(%rsp)
movups (%rbx),%xmm0
movups 0x10(%rbx),%xmm1
movaps %xmm1,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movsbl 0xc(%rsp),%ecx
lea    0x20(%rsp),%r12
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <make_move@plt>
movzbl 0x14(%rsp),%r13d
mov    %r12,%rdi
lea    0x50(%rsp),%r15
mov    %r15,%rsi
mov    %r13d,%edx
call   1050 <valid_moves@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1040 <best_move@plt>
cmp    0x10(%rsp),%eax
jge    11a0 <computer_move+0x70>
mov    %ebp,%ecx
mov    %ebp,0x4(%rsp)
mov    %r14d,%ecx
mov    %r14d,0x8(%rsp)
mov    %eax,0x10(%rsp)
jmp    11a0 <computer_move+0x70>
movsbl 0xc(%rsp),%ecx
mov    %rbx,%rdi
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
call   1030 <make_move@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @computer_move([6 x i8]* %0, [6 x i32]* nocapture %1, i8 signext %2) {
%4 = getelementptr [6 x i8], [6 x i8]* %0, i64 0, i64 0
%5 = alloca [6 x [6 x i8]]
%6 = getelementptr inbounds [6 x [6 x i8]], [6 x [6 x i8]]* %5, i64 0, i64 0, i64 0
%7 = alloca [6 x [6 x i32]]
%8 = getelementptr inbounds [6 x [6 x i8]], [6 x [6 x i8]]* %5, i64 0, i64 0, i64 0
%9 = bitcast [6 x [6 x i32]]* %7 to i8*
%10 = icmp eq i8 %2, 79
%11 = select i1 %10, i8 64, i8 79
%12 = bitcast [6 x [6 x i8]]* %5 to i8**
%13 = bitcast [6 x [6 x i32]]* %7 to i32**
br label %14
14: ; preds = %3, %41
%15 = phi i64 [ 0, %3 ], [ %42, %41 ]
%16 = phi i32 [ 100, %3 ], [ %38, %41 ]
%17 = phi i32 [ 0, %3 ], [ %37, %41 ]
%18 = phi i32 [ 0, %3 ], [ %36, %41 ]
%19 = trunc i64 %15 to i32
br label %20
20: ; preds = %14, %35
%21 = phi i64 [ 0, %14 ], [ %39, %35 ]
%22 = phi i32 [ %16, %14 ], [ %38, %35 ]
%23 = phi i32 [ %17, %14 ], [ %37, %35 ]
%24 = phi i32 [ %18, %14 ], [ %36, %35 ]
%25 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 %15, i64 %21
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %20
%29 = trunc i64 %21 to i32
%30 = call i32 @make_move(i8** %12, i32 %19, i32 %29, i8 signext %2)
%31 = call i32 @valid_moves(i8** %12, i32** %13, i8 signext %11)
%32 = call i32 @best_move(i8** %12, i32** %13, i8 signext %11)
%33 = icmp slt i32 %32, %22
br i1 %33, label %34, label %35
34: ; preds = %28
br label %35
35: ; preds = %28, %34, %20
%36 = phi i32 [ %24, %20 ], [ %19, %34 ], [ %24, %28 ]
%37 = phi i32 [ %23, %20 ], [ %29, %34 ], [ %23, %28 ]
%38 = phi i32 [ %22, %20 ], [ %32, %34 ], [ %22, %28 ]
%39 = add nuw nsw i64 %21, 1
%40 = icmp eq i64 %39, 6
br i1 %40, label %41, label %20
41: ; preds = %35
%42 = add nuw nsw i64 %15, 1
%43 = icmp eq i64 %42, 6
br i1 %43, label %44, label %14
44: ; preds = %41
%45 = bitcast [6 x i8]* %0 to i8**
%46 = call i32 @make_move(i8** %45, i32 %36, i32 %37, i8 signext %2)
ret void
}