#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 uint8_t;

/* Variables and functions */
int abs(int);
int /*<<< orphan*/ dropCounter(int *, char, int);
int score(int *, char, char);
int bestMove(uint8_t board[42], char token, char oppToken, uint8_t *bestCol,
             uint8_t lookAhead) {
  uint8_t col;
  int bestScore = -9999;
  for (col = 0; col < 7; col++) {
    if (board[col] == '.') {
      int thisScore;
      uint8_t boardCopy[42], i;
      for (i = 0; i < 42; i++) {
        boardCopy[i] = board[i];
      }
      dropCounter(boardCopy, token, col);
      thisScore = score(boardCopy, token, oppToken);
      if (abs(thisScore) < 1000 && lookAhead > 0) {
        uint8_t oppBestCol;
        thisScore =
            -bestMove(boardCopy, oppToken, token, &oppBestCol, (lookAhead - 1));
      }
      if (thisScore > bestScore) {
        bestScore = thisScore;
        *bestCol = col;
      }
    }
  }
  return bestScore;
}


x86 assembly (clang, -O0):
<bestMove>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %rdi,-0x8(%rbp)
mov    %dl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
movl   $0xffffd8f1,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x7,-0x20(%rbp)
jge    1281 <bestMove+0x141>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpl   $0x2e,(%rax,%rcx,4)
jne    126e <bestMove+0x12e>
movl   $0x0,-0xd4(%rbp)
cmpl   $0x2a,-0xd4(%rbp)
jge    11d3 <bestMove+0x93>
mov    -0x8(%rbp),%rax
movslq -0xd4(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
movslq -0xd4(%rbp),%rax
mov    %ecx,-0xd0(%rbp,%rax,4)
mov    -0xd4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xd4(%rbp)
jmp    1196 <bestMove+0x56>
lea    -0xd0(%rbp),%rdi
mov    -0x9(%rbp),%al
mov    -0x20(%rbp),%edx
movsbl %al,%esi
call   1040 <dropCounter@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x9(%rbp),%al
movsbl %al,%esi
movsbl -0xa(%rbp),%edx
call   1060 <score@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1050 <abs@plt>
cmp    $0x3e8,%eax
jge    124e <bestMove+0x10e>
cmpl   $0x0,-0x1c(%rbp)
jle    124e <bestMove+0x10e>
lea    -0xd0(%rbp),%rdi
mov    -0xa(%rbp),%dl
mov    -0x9(%rbp),%al
mov    -0x1c(%rbp),%r8d
sub    $0x1,%r8d
lea    -0xd8(%rbp),%rcx
movsbl %dl,%esi
movsbl %al,%edx
call   1030 <bestMove@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    1269 <bestMove+0x129>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    126e <bestMove+0x12e>
jmp    1273 <bestMove+0x133>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1170 <bestMove+0x30>
mov    -0x24(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bestMove>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdi,%rbx
mov    %r8,%rax
mov    %r8,0x10(%rsp)
lea    -0x1(%r8),%eax
mov    %eax,0x4(%rsp)
mov    $0xffffd8f1,%r13d
xor    %ebp,%ebp
lea    0x20(%rsp),%r14
movsbl %sil,%r12d
movsbl %dl,%r15d
jmp    118a <bestMove+0x4a>
add    $0x1,%rbp
cmp    $0x7,%rbp
je     11fc <bestMove+0xbc>
cmpl   $0x2e,(%rbx,%rbp,4)
jne    1180 <bestMove+0x40>
mov    $0xa8,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <memcpy@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1040 <dropCounter@plt>
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1060 <score@plt>
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
cmpl   $0x0,0x10(%rsp)
jle    11eb <bestMove+0xab>
cmp    $0x3e7,%ecx
ja     11eb <bestMove+0xab>
mov    %r14,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
lea    0x1c(%rsp),%rcx
mov    0x4(%rsp),%r8d
call   1030 <bestMove@plt>
neg    %eax
cmp    %r13d,%eax
jle    1180 <bestMove+0x40>
mov    0x8(%rsp),%rcx
mov    %ebp,(%rcx)
mov    %eax,%r13d
jmp    1180 <bestMove+0x40>
mov    %r13d,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bestMove(i32* %0, i8 signext %1, i8 signext %2, i32* %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i8
%8 = alloca i8
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [42 x i32]
%15 = alloca i32
%16 = alloca i32
store i32* %0, i32** %6
store i8 %1, i8* %7
store i8 %2, i8* %8
store i32* %3, i32** %9
store i32 %4, i32* %10
store i32 -9999, i32* %12
store i32 0, i32* %11
br label %17
17: ; preds = %76, %5
%18 = load i32, i32* %11
%19 = icmp slt i32 %18, 7
br i1 %19, label %20, label %79
20: ; preds = %17
%21 = load i32*, i32** %6
%22 = load i32, i32* %11
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 46
br i1 %26, label %27, label %75
27: ; preds = %20
store i32 0, i32* %15
br label %28
28: ; preds = %40, %27
%29 = load i32, i32* %15
%30 = icmp slt i32 %29, 42
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load i32*, i32** %6
%33 = load i32, i32* %15
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %15
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [42 x i32], [42 x i32]* %14, i64 0, i64 %38
store i32 %36, i32* %39
br label %40
40: ; preds = %31
%41 = load i32, i32* %15
%42 = add nsw i32 %41, 1
store i32 %42, i32* %15
br label %28
43: ; preds = %28
%44 = getelementptr inbounds [42 x i32], [42 x i32]* %14, i64 0, i64 0
%45 = load i8, i8* %7
%46 = load i32, i32* %11
%47 = call i32 @dropCounter(i32* %44, i8 signext %45, i32 %46)
%48 = getelementptr inbounds [42 x i32], [42 x i32]* %14, i64 0, i64 0
%49 = load i8, i8* %7
%50 = load i8, i8* %8
%51 = call i32 @score(i32* %48, i8 signext %49, i8 signext %50)
store i32 %51, i32* %13
%52 = load i32, i32* %13
%53 = call i32 @abs(i32 %52)
%54 = icmp slt i32 %53, 1000
br i1 %54, label %55, label %66
55: ; preds = %43
%56 = load i32, i32* %10
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %66
58: ; preds = %55
%59 = getelementptr inbounds [42 x i32], [42 x i32]* %14, i64 0, i64 0
%60 = load i8, i8* %8
%61 = load i8, i8* %7
%62 = load i32, i32* %10
%63 = sub nsw i32 %62, 1
%64 = call i32 @bestMove(i32* %59, i8 signext %60, i8 signext %61, i32* %16, i32 %63)
%65 = sub nsw i32 0, %64
store i32 %65, i32* %13
br label %66
66: ; preds = %58, %55, %43
%67 = load i32, i32* %13
%68 = load i32, i32* %12
%69 = icmp sgt i32 %67, %68
br i1 %69, label %70, label %74
70: ; preds = %66
%71 = load i32, i32* %13
store i32 %71, i32* %12
%72 = load i32, i32* %11
%73 = load i32*, i32** %9
store i32 %72, i32* %73
br label %74
74: ; preds = %70, %66
br label %75
75: ; preds = %74, %20
br label %76
76: ; preds = %75
%77 = load i32, i32* %11
%78 = add nsw i32 %77, 1
store i32 %78, i32* %11
br label %17
79: ; preds = %17
%80 = load i32, i32* %12
ret i32 %80
}

LLVM IR (-O2):
define i32 @bestMove(i32* nocapture %0, i8 signext %1, i8 signext %2, i32* nocapture writeonly %3, i32 %4) {
%6 = bitcast i32* %0 to i8*
%7 = alloca [42 x i32]
%8 = bitcast [42 x i32]* %7 to i8*
%9 = alloca i32
%10 = getelementptr inbounds [42 x i32], [42 x i32]* %7, i64 0, i64 0
%11 = icmp sgt i32 %4, 0
%12 = bitcast i32* %9 to i8*
%13 = add nsw i32 %4, -1
br label %14
14: ; preds = %5, %36
%15 = phi i64 [ 0, %5 ], [ %38, %36 ]
%16 = phi i32 [ -9999, %5 ], [ %37, %36 ]
%17 = getelementptr inbounds i32, i32* %0, i64 %15
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 46
br i1 %19, label %20, label %36
20: ; preds = %14
%21 = trunc i64 %15 to i32
%22 = call i32 @dropCounter(i32* %10, i8 signext %1, i32 %21)
%23 = call i32 @score(i32* %10, i8 signext %1, i8 signext %2)
%24 = call i32 @llvm.abs.i32(i32 %23, i1 true)
%25 = icmp ult i32 %24, 1000
%26 = and i1 %11, %25
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @bestMove(i32* %10, i8 signext %2, i8 signext %1, i32* %9, i32 %13)
%29 = sub nsw i32 0, %28
br label %30
30: ; preds = %27, %20
%31 = phi i32 [ %29, %27 ], [ %23, %20 ]
%32 = icmp sgt i32 %31, %16
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 %21, i32* %3
br label %34
34: ; preds = %33, %30
%35 = phi i32 [ %31, %33 ], [ %16, %30 ]
br label %36
36: ; preds = %14, %34
%37 = phi i32 [ %35, %34 ], [ %16, %14 ]
%38 = add nuw nsw i64 %15, 1
%39 = icmp eq i64 %38, 7
br i1 %39, label %40, label %14
40: ; preds = %36
ret i32 %37
}