#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_cansettle(int);
int builder_placesettlement(int, int, int /*<<< orphan*/);
int data_getresource(int, int);
int /*<<< orphan*/ marker_setposition(int);
int ai_settle(int player) {
  if (data_getresource(player, 0) >= 1 && data_getresource(player, 1) >= 1 &&
      data_getresource(player, 2) >= 1 && data_getresource(player, 3) >= 1) {
    int vert = ai_cansettle(player);
    if (vert != 0) {
      marker_setposition(vert);
      return builder_placesettlement(vert, player, 0);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ai_settle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1050 <data_getresource@plt>
cmp    $0x1,%eax
jl     11d7 <ai_settle+0x97>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1050 <data_getresource@plt>
cmp    $0x1,%eax
jl     11d7 <ai_settle+0x97>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1050 <data_getresource@plt>
cmp    $0x1,%eax
jl     11d7 <ai_settle+0x97>
mov    -0x8(%rbp),%edi
mov    $0x3,%esi
call   1050 <data_getresource@plt>
cmp    $0x1,%eax
jl     11d7 <ai_settle+0x97>
mov    -0x8(%rbp),%edi
call   1040 <ai_cansettle@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11d2 <ai_settle+0x92>
mov    -0xc(%rbp),%edi
call   1060 <marker_setposition@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
xor    %edx,%edx
call   1030 <builder_placesettlement@plt>
mov    %eax,-0x4(%rbp)
jmp    11de <ai_settle+0x9e>
jmp    11d7 <ai_settle+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_settle>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %esi,%esi
call   1050 <data_getresource@plt>
test   %eax,%eax
jle    11a5 <ai_settle+0x65>
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <data_getresource@plt>
test   %eax,%eax
jle    11a5 <ai_settle+0x65>
mov    %ebx,%edi
mov    $0x2,%esi
call   1050 <data_getresource@plt>
test   %eax,%eax
jle    11a5 <ai_settle+0x65>
mov    %ebx,%edi
mov    $0x3,%esi
call   1050 <data_getresource@plt>
test   %eax,%eax
jle    11a5 <ai_settle+0x65>
mov    %ebx,%edi
call   1040 <ai_cansettle@plt>
test   %eax,%eax
je     11a5 <ai_settle+0x65>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <marker_setposition@plt>
mov    %ebp,%edi
mov    %ebx,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <builder_placesettlement@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ai_settle(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @data_getresource(i32 %5, i32 0)
%7 = icmp sge i32 %6, 1
br i1 %7, label %8, label %32
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i32 @data_getresource(i32 %9, i32 1)
%11 = icmp sge i32 %10, 1
br i1 %11, label %12, label %32
12: ; preds = %8
%13 = load i32, i32* %3
%14 = call i32 @data_getresource(i32 %13, i32 2)
%15 = icmp sge i32 %14, 1
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i32, i32* %3
%18 = call i32 @data_getresource(i32 %17, i32 3)
%19 = icmp sge i32 %18, 1
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i32, i32* %3
%22 = call i32 @ai_cansettle(i32 %21)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = load i32, i32* %4
%27 = call i32 @marker_setposition(i32 %26)
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = call i32 @builder_placesettlement(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %2
br label %33
31: ; preds = %20
br label %32
32: ; preds = %31, %16, %12, %8, %1
store i32 0, i32* %2
br label %33
33: ; preds = %32, %25
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
define i32 @ai_settle(i32 %0) {
%2 = tail call i32 @data_getresource(i32 %0, i32 0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %19
4: ; preds = %1
%5 = tail call i32 @data_getresource(i32 %0, i32 1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %4
%8 = tail call i32 @data_getresource(i32 %0, i32 2)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = tail call i32 @data_getresource(i32 %0, i32 3)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = tail call i32 @ai_cansettle(i32 %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call i32 @marker_setposition(i32 %14)
%18 = tail call i32 @builder_placesettlement(i32 %14, i32 %0, i32 0)
br label %19
19: ; preds = %13, %1, %4, %7, %10, %16
%20 = phi i32 [ %18, %16 ], [ 0, %10 ], [ 0, %7 ], [ 0, %4 ], [ 0, %1 ], [ 0, %13 ]
ret i32 %20
}