#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 ai_vertweight(int, int);
scalar_t__ data_poslegal(int);
int ai_bestvert(int player) {
  int i, besti, bestweight;
  besti = bestweight = 0;
  for (i = 2; i < 64; i++)
    if (data_poslegal(i) && ai_vertweight(player, i) > bestweight) {
      besti = i;
      bestweight = ai_vertweight(player, i);
    }
  return besti;
}


x86 assembly (clang, -O0):
<ai_bestvert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x2,-0x8(%rbp)
cmpl   $0x40,-0x8(%rbp)
jge    1197 <ai_bestvert+0x77>
mov    -0x8(%rbp),%edi
call   1030 <data_poslegal@plt>
cmp    $0x0,%rax
je     1184 <ai_bestvert+0x64>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <ai_vertweight@plt>
cmp    -0x10(%rbp),%eax
jle    1184 <ai_bestvert+0x64>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <ai_vertweight@plt>
mov    %eax,-0x10(%rbp)
jmp    1189 <ai_bestvert+0x69>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1140 <ai_bestvert+0x20>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_bestvert>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x2,%ebp
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    1148 <ai_bestvert+0x28>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0x40,%ebp
je     1173 <ai_bestvert+0x53>
mov    %ebp,%edi
call   1030 <data_poslegal@plt>
test   %rax,%rax
je     1140 <ai_bestvert+0x20>
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <ai_vertweight@plt>
cmp    %ebx,%eax
jle    1140 <ai_bestvert+0x20>
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <ai_vertweight@plt>
mov    %eax,%ebx
mov    %ebp,%r15d
jmp    1140 <ai_bestvert+0x20>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ai_bestvert(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
store i32 0, i32* %4
store i32 2, i32* %3
br label %6
6: ; preds = %25, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 64
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = load i32, i32* %3
%11 = call i64 @data_poslegal(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = call i32 @ai_vertweight(i32 %14, i32 %15)
%17 = load i32, i32* %5
%18 = icmp sgt i32 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = load i32, i32* %3
store i32 %20, i32* %4
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = call i32 @ai_vertweight(i32 %21, i32 %22)
store i32 %23, i32* %5
br label %24
24: ; preds = %19, %13, %9
br label %25
25: ; preds = %24
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %6
28: ; preds = %6
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @ai_bestvert(i32 %0) {
br label %2
2: ; preds = %1, %13
%3 = phi i32 [ 0, %1 ], [ %15, %13 ]
%4 = phi i32 [ 0, %1 ], [ %14, %13 ]
%5 = phi i32 [ 2, %1 ], [ %16, %13 ]
%6 = tail call i64 @data_poslegal(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @ai_vertweight(i32 %0, i32 %5)
%10 = icmp sgt i32 %9, %3
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @ai_vertweight(i32 %0, i32 %5)
br label %13
13: ; preds = %2, %8, %11
%14 = phi i32 [ %5, %11 ], [ %4, %8 ], [ %4, %2 ]
%15 = phi i32 [ %12, %11 ], [ %3, %8 ], [ %3, %2 ]
%16 = add nuw nsw i32 %5, 1
%17 = icmp eq i32 %16, 64
br i1 %17, label %18, label %2
18: ; preds = %13
ret i32 %14
}