#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 /*<<< orphan*/ copy(char *, char *);
scalar_t__ is_a_valid_move(char);
int minimax(char *, int /*<<< orphan*/);
int /*<<< orphan*/ opponent(char);
int minimax_strategy(char board[], char player) {
  char new_board[9];
  int best_move, score = 0, best_score = -1, i;
  for (i = 0; i < 9; ++i) {
    copy(board, new_board);
    if (is_a_valid_move(new_board[i])) {
      new_board[i] = player;
      score = minimax(new_board, opponent(player)) * -1;
      if (score > best_score) {
        best_score = score;
        best_move = i;
      }
    }
  }
  return best_move;
}


x86 assembly (clang, -O0):
<minimax_strategy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x9,-0x24(%rbp)
jge    11f3 <minimax_strategy+0xb3>
mov    -0x8(%rbp),%rdi
lea    -0x12(%rbp),%rsi
call   1060 <copy@plt>
movslq -0x24(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%edi
call   1050 <is_a_valid_move@plt>
cmp    $0x0,%rax
je     11e0 <minimax_strategy+0xa0>
mov    -0x9(%rbp),%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x12(%rbp,%rax,1)
lea    -0x12(%rbp),%rax
mov    %rax,-0x30(%rbp)
movsbl -0x9(%rbp),%edi
call   1030 <opponent@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1040 <minimax@plt>
imul   $0xffffffff,%eax,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    11db <minimax_strategy+0x9b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11e0 <minimax_strategy+0xa0>
jmp    11e5 <minimax_strategy+0xa5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1167 <minimax_strategy+0x27>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minimax_strategy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
lea    0xf(%rsp),%r14
movsbl %sil,%r12d
jmp    117a <minimax_strategy+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
cmp    $0x9,%rbx
je     11b8 <minimax_strategy+0x78>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <copy@plt>
movsbl 0xf(%rsp,%rbx,1),%edi
call   1050 <is_a_valid_move@plt>
test   %rax,%rax
je     1170 <minimax_strategy+0x30>
mov    %r12b,0xf(%rsp,%rbx,1)
mov    %r12d,%edi
call   1030 <opponent@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <minimax@plt>
neg    %eax
cmp    %eax,%ebp
cmovl  %ebx,%r13d
cmovl  %eax,%ebp
jmp    1170 <minimax_strategy+0x30>
mov    %r13d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @minimax_strategy(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [9 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %7
store i32 -1, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %41, %2
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 9
br i1 %12, label %13, label %44
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%16 = call i32 @copy(i8* %14, i8* %15)
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = call i64 @is_a_valid_move(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %40
23: ; preds = %13
%24 = load i8, i8* %4
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %26
store i8 %24, i8* %27
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%29 = load i8, i8* %4
%30 = call i32 @opponent(i8 signext %29)
%31 = call i32 @minimax(i8* %28, i32 %30)
%32 = mul nsw i32 %31, -1
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %23
%37 = load i32, i32* %7
store i32 %37, i32* %8
%38 = load i32, i32* %9
store i32 %38, i32* %6
br label %39
39: ; preds = %36, %23
br label %40
40: ; preds = %39, %13
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %10
44: ; preds = %10
%45 = load i32, i32* %6
ret i32 %45
}

LLVM IR (-O2):
define i32 @minimax_strategy(i8* %0, i8 signext %1) {
%3 = alloca [9 x i8]
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %22
%6 = phi i64 [ 0, %2 ], [ %25, %22 ]
%7 = phi i32 [ -1, %2 ], [ %24, %22 ]
%8 = phi i32 [ undef, %2 ], [ %23, %22 ]
%9 = call i32 @copy(i8* %0, i8* %4)
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 %6
%11 = load i8, i8* %10
%12 = call i64 @is_a_valid_move(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %5
store i8 %1, i8* %10
%15 = call i32 @opponent(i8 signext %1)
%16 = call i32 @minimax(i8* %4, i32 %15)
%17 = sub nsw i32 0, %16
%18 = icmp slt i32 %7, %17
%19 = trunc i64 %6 to i32
%20 = select i1 %18, i32 %19, i32 %8
%21 = select i1 %18, i32 %17, i32 %7
br label %22
22: ; preds = %14, %5
%23 = phi i32 [ %8, %5 ], [ %20, %14 ]
%24 = phi i32 [ %7, %5 ], [ %21, %14 ]
%25 = add nuw nsw i64 %6, 1
%26 = icmp eq i64 %25, 9
br i1 %26, label %27, label %5
27: ; preds = %22
ret i32 %23
}