#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 builder_placecity(int, int);
int builder_placesettlement(int, int, int);
int data_atvertex(int, int);
int /*<<< orphan*/ map_setmessage(char *);
int marker_getposition();
int build_routine(int player, int ispregame) {
  int position = marker_getposition();
  int atVertex = data_atvertex(player, position);
  if (atVertex == -1 && ispregame)
    atVertex = 0;
  switch (atVertex) {
  case -1:
    map_setmessage("Must have road here first");
    break;
  case 0:
    return builder_placesettlement(position, player, ispregame);
    break;
  case 1:
    if (ispregame) {
      map_setmessage("Cannot build city in pregame!");
      break;
    }
    return builder_placecity(position, player);
    break;
  default:
    map_setmessage("City already built, cannot build further here.");
  }
  return 0;
}


x86 assembly (clang, -O0):
<build_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1060 <marker_getposition@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <data_atvertex@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1191 <build_routine+0x41>
cmpl   $0x0,-0xc(%rbp)
je     1191 <build_routine+0x41>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xffffffff,%eax
je     11c6 <build_routine+0x76>
jmp    11a5 <build_routine+0x55>
mov    -0x18(%rbp),%eax
test   %eax,%eax
je     11d7 <build_routine+0x87>
jmp    11b5 <build_routine+0x65>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     11ed <build_routine+0x9d>
jmp    121b <build_routine+0xcb>
lea    0xe33(%rip),%rdi
call   1070 <map_setmessage@plt>
jmp    1227 <build_routine+0xd7>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <builder_placesettlement@plt>
mov    %eax,-0x4(%rbp)
jmp    122e <build_routine+0xde>
cmpl   $0x0,-0xc(%rbp)
je     1208 <build_routine+0xb8>
lea    0xe1c(%rip),%rdi
call   1070 <map_setmessage@plt>
jmp    1227 <build_routine+0xd7>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <builder_placecity@plt>
mov    %eax,-0x4(%rbp)
jmp    122e <build_routine+0xde>
lea    0xe16(%rip),%rdi
call   1070 <map_setmessage@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_routine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%r14d
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <marker_getposition@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %eax,%esi
call   1050 <data_atvertex@plt>
cmp    $0xffffffff,%eax
cmovne %eax,%ebp
test   %r15d,%r15d
cmove  %eax,%ebp
cmp    $0x1,%ebp
je     1195 <build_routine+0x45>
test   %ebp,%ebp
je     11a3 <build_routine+0x53>
cmp    $0xffffffff,%ebp
jne    11ba <build_routine+0x6a>
lea    0xe6d(%rip),%rdi
jmp    11c1 <build_routine+0x71>
test   %r15d,%r15d
je     11d3 <build_routine+0x83>
lea    0xe79(%rip),%rdi
jmp    11c1 <build_routine+0x71>
mov    %ebx,%edi
mov    %r14d,%esi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <builder_placesettlement@plt>
lea    0xe77(%rip),%rdi
call   1070 <map_setmessage@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%edi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <builder_placecity@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Must have road here first\00"
@.str.1 = [30 x i8] c"Cannot build city in pregame!\00"
@.str.2 = [47 x i8] c"City already built, cannot build further here.\00"
define i32 @build_routine(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = call i32 (...) @marker_getposition()
store i32 %8, i32* %6
%9 = load i32, i32* %4
%10 = load i32, i32* %6
%11 = call i32 @data_atvertex(i32 %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 0, i32* %7
br label %18
18: ; preds = %17, %14, %2
%19 = load i32, i32* %7
switch i32 %19, label %36 [
i32 -1, label %20
i32 0, label %22
i32 1, label %27
]
20: ; preds = %18
%21 = call i32 @map_setmessage(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %38
22: ; preds = %18
%23 = load i32, i32* %6
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = call i32 @builder_placesettlement(i32 %23, i32 %24, i32 %25)
store i32 %26, i32* %3
br label %39
27: ; preds = %18
%28 = load i32, i32* %5
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @map_setmessage(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %38
32: ; preds = %27
%33 = load i32, i32* %6
%34 = load i32, i32* %4
%35 = call i32 @builder_placecity(i32 %33, i32 %34)
store i32 %35, i32* %3
br label %39
36: ; preds = %18
%37 = call i32 @map_setmessage(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %30, %20
store i32 0, i32* %3
br label %39
39: ; preds = %38, %32, %22
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [26 x i8] c"Must have road here first\00"
@.str.1 = [30 x i8] c"Cannot build city in pregame!\00"
@.str.2 = [47 x i8] c"City already built, cannot build further here.\00"
define i32 @build_routine(i32 %0, i32 %1) {
%3 = tail call i32 (...) @marker_getposition()
%4 = tail call i32 @data_atvertex(i32 %0, i32 %3)
%5 = icmp eq i32 %4, -1
%6 = icmp ne i32 %1, 0
%7 = and i1 %6, %5
%8 = select i1 %7, i32 0, i32 %4
switch i32 %8, label %18 [
i32 -1, label %9
i32 0, label %11
i32 1, label %13
]
9: ; preds = %2
%10 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %20
11: ; preds = %2
%12 = tail call i32 @builder_placesettlement(i32 %3, i32 %0, i32 %1)
br label %20
13: ; preds = %2
br i1 %6, label %14, label %16
14: ; preds = %13
%15 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %20
16: ; preds = %13
%17 = tail call i32 @builder_placecity(i32 %3, i32 %0)
br label %20
18: ; preds = %2
%19 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %9, %14, %18, %16, %11
%21 = phi i32 [ %17, %16 ], [ %12, %11 ], [ 0, %18 ], [ 0, %14 ], [ 0, %9 ]
ret i32 %21
}