#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 */
typedef int s;

/* Variables and functions */
int alpha_beta(int, int, int);
int make_move(int, int);
int random_move(int);
int best_move(int s) {
  int best = random_move(s);
  int best_val = -alpha_beta(make_move(s, best), -1024, 1024);
  int i;
  for (i = 0; i < 9; i++) {
    if ((((s)&0x1ff) & (1 << (i))
             ? 0x1
             : (((s) >> 9 & 0x1ff) & (1 << (i)) ? 0x2 : 0x0)))
      continue;
    int s_new = make_move(s, i);
    int val = -alpha_beta(s_new, -1024, 1024);
    if (val > best_val) {
      best = i;
      best_val = val;
    }
  }
  return best;
}


x86 assembly (clang, -O0):
<best_move>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <random_move@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <make_move@plt>
mov    %eax,%edi
mov    $0xfffffc00,%esi
mov    $0x400,%edx
call   1030 <alpha_beta@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x9,-0x10(%rbp)
jge    1243 <best_move+0x113>
mov    -0x4(%rbp),%eax
and    $0x1ff,%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11aa <best_move+0x7a>
mov    $0x1,%al
test   $0x1,%al
jne    11ea <best_move+0xba>
jmp    11ef <best_move+0xbf>
mov    -0x4(%rbp),%eax
sar    $0x9,%eax
and    $0x1ff,%eax
mov    -0x10(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11db <best_move+0xab>
mov    $0x1,%al
test   $0x1,%al
jne    11ea <best_move+0xba>
jmp    11ef <best_move+0xbf>
xor    %eax,%eax
test   $0x1,%al
jne    11ea <best_move+0xba>
jmp    11ef <best_move+0xbf>
jmp    1235 <best_move+0x105>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1040 <make_move@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0xfffffc00,%esi
mov    $0x400,%edx
call   1030 <alpha_beta@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1230 <best_move+0x100>
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1235 <best_move+0x105>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <best_move+0x42>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<best_move>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
call   1050 <random_move@plt>
mov    %eax,%r15d
mov    %r14d,%edi
mov    %eax,%esi
call   1040 <make_move@plt>
mov    %eax,%edi
mov    $0xfffffc00,%esi
mov    $0x400,%edx
call   1030 <alpha_beta@plt>
mov    %eax,%ebx
neg    %ebx
mov    %r14d,%r12d
shr    $0x9,%r12d
or     %r14d,%r12d
xor    %ebp,%ebp
jmp    1178 <best_move+0x48>
add    $0x1,%ebp
cmp    $0x9,%ebp
je     11b3 <best_move+0x83>
mov    $0x1,%eax
mov    %ebp,%ecx
shl    %cl,%eax
and    %r12d,%eax
test   $0x1ff,%eax
jne    1170 <best_move+0x40>
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <make_move@plt>
mov    %eax,%edi
mov    $0xfffffc00,%esi
mov    $0x400,%edx
call   1030 <alpha_beta@plt>
neg    %eax
cmp    %eax,%ebx
cmovl  %eax,%ebx
cmovl  %ebp,%r15d
jmp    1170 <best_move+0x40>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @best_move(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = call i32 @random_move(i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = call i32 @make_move(i32 %10, i32 %11)
%13 = call i32 @alpha_beta(i32 %12, i32 -1024, i32 1024)
%14 = sub nsw i32 0, %13
store i32 %14, i32* %4
store i32 0, i32* %5
br label %15
15: ; preds = %51, %1
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 9
br i1 %17, label %18, label %54
18: ; preds = %15
%19 = load i32, i32* %2
%20 = and i32 %19, 511
%21 = load i32, i32* %5
%22 = shl i32 1, %21
%23 = and i32 %20, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %18
br i1 true, label %36, label %37
26: ; preds = %18
%27 = load i32, i32* %2
%28 = ashr i32 %27, 9
%29 = and i32 %28, 511
%30 = load i32, i32* %5
%31 = shl i32 1, %30
%32 = and i32 %29, %31
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %26
br i1 true, label %36, label %37
35: ; preds = %26
br i1 false, label %36, label %37
36: ; preds = %35, %34, %25
br label %51
37: ; preds = %35, %34, %25
%38 = load i32, i32* %2
%39 = load i32, i32* %5
%40 = call i32 @make_move(i32 %38, i32 %39)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = call i32 @alpha_beta(i32 %41, i32 -1024, i32 1024)
%43 = sub nsw i32 0, %42
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = load i32, i32* %4
%46 = icmp sgt i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %37
%48 = load i32, i32* %5
store i32 %48, i32* %3
%49 = load i32, i32* %7
store i32 %49, i32* %4
br label %50
50: ; preds = %47, %37
br label %51
51: ; preds = %50, %36
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %15
54: ; preds = %15
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
define i32 @best_move(i32 %0) {
%2 = tail call i32 @random_move(i32 %0)
%3 = tail call i32 @make_move(i32 %0, i32 %2)
%4 = tail call i32 @alpha_beta(i32 %3, i32 -1024, i32 1024)
%5 = sub nsw i32 0, %4
%6 = lshr i32 %0, 9
%7 = or i32 %6, %0
br label %8
8: ; preds = %1, %23
%9 = phi i32 [ %2, %1 ], [ %25, %23 ]
%10 = phi i32 [ %5, %1 ], [ %24, %23 ]
%11 = phi i32 [ 0, %1 ], [ %26, %23 ]
%12 = shl nuw nsw i32 1, %11
%13 = and i32 %12, 511
%14 = and i32 %13, %7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %8
%17 = tail call i32 @make_move(i32 %0, i32 %11)
%18 = tail call i32 @alpha_beta(i32 %17, i32 -1024, i32 1024)
%19 = sub nsw i32 0, %18
%20 = icmp slt i32 %10, %19
%21 = select i1 %20, i32 %19, i32 %10
%22 = select i1 %20, i32 %11, i32 %9
br label %23
23: ; preds = %8, %16
%24 = phi i32 [ %10, %8 ], [ %21, %16 ]
%25 = phi i32 [ %9, %8 ], [ %22, %16 ]
%26 = add nuw nsw i32 %11, 1
%27 = icmp eq i32 %26, 9
br i1 %27, label %28, label %8
28: ; preds = %23
ret i32 %25
}