#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*/ ai_surroundingverts(int, int *);
scalar_t__ ai_vertweight(int, int);
scalar_t__ data_poslegal(int);
int ai_shouldsettle(int player, int vert) {
  int surrounding[3];
  ai_surroundingverts(vert, surrounding);
  int i;
  for (i = 0; i < 3; i++) {
    if (data_poslegal(surrounding[i]) &&
        ai_vertweight(player, surrounding[i]) > ai_vertweight(player, vert) + 3)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ai_shouldsettle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1030 <ai_surroundingverts@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    11c4 <ai_shouldsettle+0x94>
movslq -0x1c(%rbp),%rax
mov    -0x18(%rbp,%rax,4),%edi
call   1040 <data_poslegal@plt>
cmp    $0x0,%rax
je     11b1 <ai_shouldsettle+0x81>
mov    -0x8(%rbp),%edi
movslq -0x1c(%rbp),%rax
mov    -0x18(%rbp,%rax,4),%esi
call   1050 <ai_vertweight@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <ai_vertweight@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    $0x3,%rcx
cmp    %rcx,%rax
jle    11b1 <ai_shouldsettle+0x81>
movl   $0x0,-0x4(%rbp)
jmp    11cb <ai_shouldsettle+0x9b>
jmp    11b6 <ai_shouldsettle+0x86>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1151 <ai_shouldsettle+0x21>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_shouldsettle>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x4(%rsp),%rsi
mov    %r14d,%edi
call   1030 <ai_surroundingverts@plt>
mov    0x4(%rsp),%edi
call   1040 <data_poslegal@plt>
test   %rax,%rax
je     117e <ai_shouldsettle+0x4e>
mov    0x4(%rsp),%esi
mov    %ebp,%edi
call   1050 <ai_vertweight@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <ai_vertweight@plt>
mov    %rax,%rcx
add    $0x3,%rcx
xor    %eax,%eax
cmp    %rcx,%rbx
jg     11eb <ai_shouldsettle+0xbb>
mov    0x8(%rsp),%edi
call   1040 <data_poslegal@plt>
test   %rax,%rax
je     11b2 <ai_shouldsettle+0x82>
mov    0x8(%rsp),%esi
mov    %ebp,%edi
call   1050 <ai_vertweight@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <ai_vertweight@plt>
mov    %rax,%rcx
add    $0x3,%rcx
xor    %eax,%eax
cmp    %rcx,%rbx
jg     11eb <ai_shouldsettle+0xbb>
mov    0xc(%rsp),%edi
call   1040 <data_poslegal@plt>
test   %rax,%rax
je     11e6 <ai_shouldsettle+0xb6>
mov    0xc(%rsp),%esi
mov    %ebp,%edi
call   1050 <ai_vertweight@plt>
mov    %rax,%rbx
mov    %ebp,%edi
mov    %r14d,%esi
call   1050 <ai_vertweight@plt>
mov    %rax,%rcx
add    $0x3,%rcx
xor    %eax,%eax
cmp    %rcx,%rbx
jg     11eb <ai_shouldsettle+0xbb>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @ai_shouldsettle(i32 %0, i32 %1) {
%3 = alloca [3 x i32]
%4 = bitcast [3 x i32]* %3 to i8*
%5 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 0
%6 = call i32 @ai_surroundingverts(i32 %1, i32* %5)
%7 = load i32, i32* %5
%8 = call i64 @data_poslegal(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* %5
%12 = call i64 @ai_vertweight(i32 %0, i32 %11)
%13 = call i64 @ai_vertweight(i32 %0, i32 %1)
%14 = add nsw i64 %13, 3
%15 = icmp sgt i64 %12, %14
br i1 %15, label %39, label %16
16: ; preds = %2, %10
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i64 @data_poslegal(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %16
%22 = load i32, i32* %17
%23 = call i64 @ai_vertweight(i32 %0, i32 %22)
%24 = call i64 @ai_vertweight(i32 %0, i32 %1)
%25 = add nsw i64 %24, 3
%26 = icmp sgt i64 %23, %25
br i1 %26, label %39, label %27
27: ; preds = %21, %16
%28 = getelementptr inbounds [3 x i32], [3 x i32]* %3, i64 0, i64 2
%29 = load i32, i32* %28
%30 = call i64 @data_poslegal(i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %27
%33 = load i32, i32* %28
%34 = call i64 @ai_vertweight(i32 %0, i32 %33)
%35 = call i64 @ai_vertweight(i32 %0, i32 %1)
%36 = add nsw i64 %35, 3
%37 = icmp sgt i64 %34, %36
br i1 %37, label %39, label %38
38: ; preds = %32, %27
br label %39
39: ; preds = %38, %32, %21, %10
%40 = phi i32 [ 0, %10 ], [ 0, %21 ], [ 0, %32 ], [ 1, %38 ]
ret i32 %40
}