#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_canupgrade(int);
int ai_vertweight(int, int);
int /*<<< orphan*/ builder_placecity(int, int);
int data_getresource(int, int);
int *data_getsettlements(int);
int /*<<< orphan*/ marker_setposition(int);
int ai_city(int player) {
  if (data_getresource(player, 4) < 3 || data_getresource(player, 1) < 2 ||
      !ai_canupgrade(player)) {
    return 0;
  }
  int *settlements = data_getsettlements(player);
  int i, max, vert;
  max = vert = -100;
  for (i = 0; settlements[i] != 0; i++) {
    if (ai_vertweight(player, settlements[i]) > max) {
      max = ai_vertweight(player, settlements[i]);
      vert = settlements[i];
    }
  }
  marker_setposition(vert);
  builder_placecity(vert, player);
  return 1;
}


x86 assembly (clang, -O0):
<ai_city>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1050 <data_getresource@plt>
cmp    $0x3,%eax
jl     11a8 <ai_city+0x48>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1050 <data_getresource@plt>
cmp    $0x2,%eax
jl     11a8 <ai_city+0x48>
mov    -0x8(%rbp),%edi
call   1040 <ai_canupgrade@plt>
cmp    $0x0,%eax
jne    11b4 <ai_city+0x54>
movl   $0x0,-0x4(%rbp)
jmp    1254 <ai_city+0xf4>
mov    -0x8(%rbp),%edi
call   1060 <data_getsettlements@plt>
mov    %rax,-0x10(%rbp)
movl   $0xffffff9c,-0x1c(%rbp)
movl   $0xffffff9c,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     123a <ai_city+0xda>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1080 <ai_vertweight@plt>
cmp    -0x18(%rbp),%eax
jle    1227 <ai_city+0xc7>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1080 <ai_vertweight@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
jmp    122c <ai_city+0xcc>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d5 <ai_city+0x75>
mov    -0x1c(%rbp),%edi
call   1070 <marker_setposition@plt>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <builder_placecity@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_city>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x4,%esi
call   1050 <data_getresource@plt>
xor    %ebx,%ebx
cmp    $0x3,%eax
jl     1206 <ai_city+0xa6>
mov    %r15d,%edi
mov    $0x1,%esi
call   1050 <data_getresource@plt>
cmp    $0x2,%eax
jl     1206 <ai_city+0xa6>
mov    %r15d,%edi
call   1040 <ai_canupgrade@plt>
test   %eax,%eax
je     1206 <ai_city+0xa6>
mov    %r15d,%edi
call   1060 <data_getsettlements@plt>
mov    (%rax),%esi
test   %esi,%esi
je     11e8 <ai_city+0x88>
mov    %rax,%rbx
mov    $0xffffff9c,%r14d
mov    $0xffffff9c,%ebp
jmp    11cb <ai_city+0x6b>
nopl   0x0(%rax,%rax,1)
mov    0x4(%rbx),%esi
add    $0x4,%rbx
test   %esi,%esi
je     11ee <ai_city+0x8e>
mov    %r15d,%edi
call   1080 <ai_vertweight@plt>
cmp    %ebp,%eax
jle    11c0 <ai_city+0x60>
mov    (%rbx),%esi
mov    %r15d,%edi
call   1080 <ai_vertweight@plt>
mov    %eax,%ebp
mov    (%rbx),%r14d
jmp    11c0 <ai_city+0x60>
mov    $0xffffff9c,%r14d
mov    %r14d,%edi
call   1070 <marker_setposition@plt>
mov    %r14d,%edi
mov    %r15d,%esi
call   1030 <builder_placecity@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ai_city(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = call i32 @data_getresource(i32 %8, i32 4)
%10 = icmp slt i32 %9, 3
br i1 %10, label %19, label %11
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i32 @data_getresource(i32 %12, i32 1)
%14 = icmp slt i32 %13, 2
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i32, i32* %3
%17 = call i32 @ai_canupgrade(i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %15, %11, %1
store i32 0, i32* %2
br label %63
20: ; preds = %15
%21 = load i32, i32* %3
%22 = call i32* @data_getsettlements(i32 %21)
store i32* %22, i32** %4
store i32 -100, i32* %7
store i32 -100, i32* %6
store i32 0, i32* %5
br label %23
23: ; preds = %54, %20
%24 = load i32*, i32** %4
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %57
30: ; preds = %23
%31 = load i32, i32* %3
%32 = load i32*, i32** %4
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = call i32 @ai_vertweight(i32 %31, i32 %36)
%38 = load i32, i32* %6
%39 = icmp sgt i32 %37, %38
br i1 %39, label %40, label %53
40: ; preds = %30
%41 = load i32, i32* %3
%42 = load i32*, i32** %4
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = call i32 @ai_vertweight(i32 %41, i32 %46)
store i32 %47, i32* %6
%48 = load i32*, i32** %4
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i32, i32* %48, i64 %50
%52 = load i32, i32* %51
store i32 %52, i32* %7
br label %53
53: ; preds = %40, %30
br label %54
54: ; preds = %53
%55 = load i32, i32* %5
%56 = add nsw i32 %55, 1
store i32 %56, i32* %5
br label %23
57: ; preds = %23
%58 = load i32, i32* %7
%59 = call i32 @marker_setposition(i32 %58)
%60 = load i32, i32* %7
%61 = load i32, i32* %3
%62 = call i32 @builder_placecity(i32 %60, i32 %61)
store i32 1, i32* %2
br label %63
63: ; preds = %57, %19
%64 = load i32, i32* %2
ret i32 %64
}

LLVM IR (-O2):
define i32 @ai_city(i32 %0) {
%2 = tail call i32 @data_getresource(i32 %0, i32 4)
%3 = icmp slt i32 %2, 3
br i1 %3, label %37, label %4
4: ; preds = %1
%5 = tail call i32 @data_getresource(i32 %0, i32 1)
%6 = icmp slt i32 %5, 2
br i1 %6, label %37, label %7
7: ; preds = %4
%8 = tail call i32 @ai_canupgrade(i32 %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %37, label %10
10: ; preds = %7
%11 = tail call i32* @data_getsettlements(i32 %0)
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %33, label %14
14: ; preds = %10, %26
%15 = phi i64 [ %29, %26 ], [ 0, %10 ]
%16 = phi i32 [ %31, %26 ], [ %12, %10 ]
%17 = phi i32* [ %30, %26 ], [ %11, %10 ]
%18 = phi i32 [ %28, %26 ], [ -100, %10 ]
%19 = phi i32 [ %27, %26 ], [ -100, %10 ]
%20 = tail call i32 @ai_vertweight(i32 %0, i32 %16)
%21 = icmp sgt i32 %20, %19
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = load i32, i32* %17
%24 = tail call i32 @ai_vertweight(i32 %0, i32 %23)
%25 = load i32, i32* %17
br label %26
26: ; preds = %14, %22
%27 = phi i32 [ %24, %22 ], [ %19, %14 ]
%28 = phi i32 [ %25, %22 ], [ %18, %14 ]
%29 = add nuw i64 %15, 1
%30 = getelementptr inbounds i32, i32* %11, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %14
33: ; preds = %26, %10
%34 = phi i32 [ -100, %10 ], [ %28, %26 ]
%35 = tail call i32 @marker_setposition(i32 %34)
%36 = tail call i32 @builder_placecity(i32 %34, i32 %0)
br label %37
37: ; preds = %1, %4, %7, %33
%38 = phi i32 [ 1, %33 ], [ 0, %7 ], [ 0, %4 ], [ 0, %1 ]
ret i32 %38
}