#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_pregame(int);
int /*<<< orphan*/ build_routine(int, int);
char *cat(char *, char *);
scalar_t__ data_isai(int);
int /*<<< orphan*/ data_pregameres(int, int /*<<< orphan*/);
int /*<<< orphan*/ data_refresh(int);
int /*<<< orphan*/ data_sleep();
int io_getkey();
int /*<<< orphan*/ io_printhelp();
int /*<<< orphan*/ io_printmap(int /*<<< orphan*/);
char *itoa(int);
int /*<<< orphan*/ map_setmessage(char *);
int /*<<< orphan*/ marker_getposition();
int /*<<< orphan*/ marker_move(int);
int /*<<< orphan*/ marker_show();
int /*<<< orphan*/ pass_between_humans(int);
int /*<<< orphan*/ quit(int /*<<< orphan*/);
int /*<<< orphan*/ road_routine(int, int);
void pregame(int player, int res) {
  int c;
  int go = 1;
  map_setmessage(cat(cat("Player ", itoa(player + 1)),
                     " pregame, please build a settlement."));
  if (data_isai(player)) {
    ai_pregame(player);
    data_refresh(player);
    io_printmap(0);
    data_sleep();
    go = 0;
  }
  while (go) {
    data_refresh(player);
    io_printmap(0);
    switch (c = io_getkey()) {
    case 0:
    case 1:
    case 2:
    case 3:
      marker_move(c);
      break;
    case 4:
    case 'b':
      marker_show();
      if (!build_routine(player, 1))
        break;
      road_routine(player, 1);
      go = 0;
      break;
    case 'h':
      io_printhelp();
      io_getkey();
      break;
    case 'q':
      quit(0);
      break;
    case 'a':
      ai_pregame(player);
      go = 0;
      break;
    case 'u':
      pass_between_humans(1);
      break;
    default:
      map_setmessage("Press 'b' to build");
      break;
    }
  }
  if (res)
    data_pregameres(player, marker_getposition());
}


x86 assembly (clang, -O0):
<pregame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
call   1130 <itoa@plt>
mov    %rax,%rsi
lea    0xdb6(%rip),%rdi
call   1140 <cat@plt>
mov    %rax,%rdi
lea    0xdaf(%rip),%rsi
call   1140 <cat@plt>
mov    %rax,%rdi
call   10a0 <map_setmessage@plt>
mov    -0x4(%rbp),%edi
call   1040 <data_isai@plt>
cmp    $0x0,%rax
je     129d <pregame+0x7d>
mov    -0x4(%rbp),%edi
call   10f0 <ai_pregame@plt>
mov    -0x4(%rbp),%edi
call   1080 <data_refresh@plt>
xor    %edi,%edi
call   1120 <io_printmap@plt>
mov    $0x0,%al
call   10d0 <data_sleep@plt>
movl   $0x0,-0x10(%rbp)
jmp    12a2 <pregame+0x82>
cmpl   $0x0,-0x10(%rbp)
je     13dd <pregame+0x1bd>
mov    -0x4(%rbp),%edi
call   1080 <data_refresh@plt>
xor    %edi,%edi
mov    %edi,-0x18(%rbp)
call   1120 <io_printmap@plt>
mov    -0x18(%rbp),%eax
call   1090 <io_getkey@plt>
mov    %eax,-0xc(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0x4,%eax
jb     1342 <pregame+0x122>
jmp    12dc <pregame+0xbc>
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
je     134f <pregame+0x12f>
jmp    12ed <pregame+0xcd>
mov    -0x14(%rbp),%eax
sub    $0x61,%eax
je     13a9 <pregame+0x189>
jmp    12fe <pregame+0xde>
mov    -0x14(%rbp),%eax
sub    $0x62,%eax
je     134f <pregame+0x12f>
jmp    130f <pregame+0xef>
mov    -0x14(%rbp),%eax
sub    $0x68,%eax
je     138a <pregame+0x16a>
jmp    1320 <pregame+0x100>
mov    -0x14(%rbp),%eax
sub    $0x71,%eax
je     139d <pregame+0x17d>
jmp    1331 <pregame+0x111>
mov    -0x14(%rbp),%eax
sub    $0x75,%eax
je     13bd <pregame+0x19d>
jmp    13cc <pregame+0x1ac>
mov    -0xc(%rbp),%edi
call   1070 <marker_move@plt>
jmp    13d8 <pregame+0x1b8>
mov    $0x0,%al
call   1110 <marker_show@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   10c0 <build_routine@plt>
cmp    $0x0,%eax
jne    1371 <pregame+0x151>
jmp    13d8 <pregame+0x1b8>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1100 <road_routine@plt>
movl   $0x0,-0x10(%rbp)
jmp    13d8 <pregame+0x1b8>
mov    $0x0,%al
call   1030 <io_printhelp@plt>
mov    $0x0,%al
call   1090 <io_getkey@plt>
jmp    13d8 <pregame+0x1b8>
xor    %edi,%edi
call   1060 <quit@plt>
jmp    13d8 <pregame+0x1b8>
mov    -0x4(%rbp),%edi
call   10f0 <ai_pregame@plt>
movl   $0x0,-0x10(%rbp)
jmp    13d8 <pregame+0x1b8>
mov    $0x1,%edi
call   10e0 <pass_between_humans@plt>
jmp    13d8 <pregame+0x1b8>
lea    0xc5a(%rip),%rdi
call   10a0 <map_setmessage@plt>
jmp    12a2 <pregame+0x82>
cmpl   $0x0,-0x8(%rbp)
je     13fe <pregame+0x1de>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <marker_getposition@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   10b0 <data_pregameres@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pregame>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
lea    0x1(%rbx),%edi
call   1130 <itoa@plt>
lea    0xe19(%rip),%rdi
mov    %rax,%rsi
call   1140 <cat@plt>
lea    0xe12(%rip),%rsi
mov    %rax,%rdi
call   1140 <cat@plt>
mov    %rax,%rdi
call   10a0 <map_setmessage@plt>
mov    %ebx,%edi
call   1040 <data_isai@plt>
test   %rax,%rax
je     1290 <pregame+0x70>
mov    %ebx,%edi
call   10f0 <ai_pregame@plt>
mov    %ebx,%edi
call   1080 <data_refresh@plt>
xor    %edi,%edi
call   1120 <io_printmap@plt>
xor    %eax,%eax
call   10d0 <data_sleep@plt>
test   %r14d,%r14d
jne    133c <pregame+0x11c>
jmp    1362 <pregame+0x142>
lea    0xdea(%rip),%r15
lea    0xd62(%rip),%rbp
jmp    12c0 <pregame+0xa0>
xor    %eax,%eax
call   1110 <marker_show@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   10c0 <build_routine@plt>
test   %eax,%eax
jne    132b <pregame+0x10b>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1080 <data_refresh@plt>
xor    %edi,%edi
call   1120 <io_printmap@plt>
xor    %eax,%eax
call   1090 <io_getkey@plt>
lea    -0x61(%rax),%ecx
cmp    $0x14,%ecx
jbe    12f0 <pregame+0xd0>
cmp    $0x4,%eax
jae    130a <pregame+0xea>
mov    %eax,%edi
call   1070 <marker_move@plt>
jmp    12c0 <pregame+0xa0>
nopl   0x0(%rax,%rax,1)
movslq 0x0(%rbp,%rcx,4),%rax
add    %rbp,%rax
jmp    *%rax
xor    %eax,%eax
call   1030 <io_printhelp@plt>
xor    %eax,%eax
call   1090 <io_getkey@plt>
jmp    12c0 <pregame+0xa0>
je     12a0 <pregame+0x80>
mov    %r15,%rdi
call   10a0 <map_setmessage@plt>
jmp    12c0 <pregame+0xa0>
xor    %edi,%edi
call   1060 <quit@plt>
jmp    12c0 <pregame+0xa0>
mov    $0x1,%edi
call   10e0 <pass_between_humans@plt>
jmp    12c0 <pregame+0xa0>
mov    %ebx,%edi
mov    $0x1,%esi
call   1100 <road_routine@plt>
test   %r14d,%r14d
je     1362 <pregame+0x142>
xor    %eax,%eax
call   1050 <marker_getposition@plt>
mov    %ebx,%edi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <data_pregameres@plt>
mov    %ebx,%edi
call   10f0 <ai_pregame@plt>
test   %r14d,%r14d
jne    133c <pregame+0x11c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Player \00"
@.str.1 = [37 x i8] c" pregame, please build a settlement.\00"
@.str.2 = [19 x i8] c"Press 'b' to build\00"
define void @pregame(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1, i32* %6
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 1
%9 = call i8* @itoa(i32 %8)
%10 = call i8* @cat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i8* @cat(i8* %10, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @map_setmessage(i8* %11)
%13 = load i32, i32* %3
%14 = call i64 @data_isai(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* %3
%18 = call i32 @ai_pregame(i32 %17)
%19 = load i32, i32* %3
%20 = call i32 @data_refresh(i32 %19)
%21 = call i32 @io_printmap(i32 0)
%22 = call i32 (...) @data_sleep()
store i32 0, i32* %6
br label %23
23: ; preds = %16, %2
br label %24
24: ; preds = %56, %23
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %57
27: ; preds = %24
%28 = load i32, i32* %3
%29 = call i32 @data_refresh(i32 %28)
%30 = call i32 @io_printmap(i32 0)
%31 = call i32 (...) @io_getkey()
store i32 %31, i32* %5
switch i32 %31, label %54 [
i32 0, label %32
i32 1, label %32
i32 2, label %32
i32 3, label %32
i32 4, label %35
i32 98, label %35
i32 104, label %44
i32 113, label %47
i32 97, label %49
i32 117, label %52
]
32: ; preds = %27, %27, %27, %27
%33 = load i32, i32* %5
%34 = call i32 @marker_move(i32 %33)
br label %56
35: ; preds = %27, %27
%36 = call i32 (...) @marker_show()
%37 = load i32, i32* %3
%38 = call i32 @build_routine(i32 %37, i32 1)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %35
br label %56
41: ; preds = %35
%42 = load i32, i32* %3
%43 = call i32 @road_routine(i32 %42, i32 1)
store i32 0, i32* %6
br label %56
44: ; preds = %27
%45 = call i32 (...) @io_printhelp()
%46 = call i32 (...) @io_getkey()
br label %56
47: ; preds = %27
%48 = call i32 @quit(i32 0)
br label %56
49: ; preds = %27
%50 = load i32, i32* %3
%51 = call i32 @ai_pregame(i32 %50)
store i32 0, i32* %6
br label %56
52: ; preds = %27
%53 = call i32 @pass_between_humans(i32 1)
br label %56
54: ; preds = %27
%55 = call i32 @map_setmessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %56
56: ; preds = %54, %52, %49, %47, %44, %41, %40, %32
br label %24
57: ; preds = %24
%58 = load i32, i32* %4
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %64
60: ; preds = %57
%61 = load i32, i32* %3
%62 = call i32 (...) @marker_getposition()
%63 = call i32 @data_pregameres(i32 %61, i32 %62)
br label %64
64: ; preds = %60, %57
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"Player \00"
@.str.1 = [37 x i8] c" pregame, please build a settlement.\00"
@.str.2 = [19 x i8] c"Press 'b' to build\00"
define void @pregame(i32 %0, i32 %1) {
%3 = add nsw i32 %0, 1
%4 = tail call i8* @itoa(i32 %3)
%5 = tail call i8* @cat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = tail call i8* @cat(i8* %5, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @map_setmessage(i8* %6)
%8 = tail call i64 @data_isai(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = tail call i32 @ai_pregame(i32 %0)
%12 = tail call i32 @data_refresh(i32 %0)
%13 = tail call i32 @io_printmap(i32 0)
%14 = tail call i32 (...) @data_sleep()
br label %39
15: ; preds = %2, %25
%16 = tail call i32 @data_refresh(i32 %0)
%17 = tail call i32 @io_printmap(i32 0)
%18 = tail call i32 (...) @io_getkey()
switch i32 %18, label %37 [
i32 0, label %19
i32 1, label %19
i32 2, label %19
i32 3, label %19
i32 4, label %21
i32 98, label %21
i32 104, label %28
i32 113, label %31
i32 97, label %33
i32 117, label %35
]
19: ; preds = %15, %15, %15, %15
%20 = tail call i32 @marker_move(i32 %18)
br label %25
21: ; preds = %15, %15
%22 = tail call i32 (...) @marker_show()
%23 = tail call i32 @build_routine(i32 %0, i32 1)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21, %37, %35, %31, %28, %19
br label %15
26: ; preds = %21
%27 = tail call i32 @road_routine(i32 %0, i32 1)
br label %39
28: ; preds = %15
%29 = tail call i32 (...) @io_printhelp()
%30 = tail call i32 (...) @io_getkey()
br label %25
31: ; preds = %15
%32 = tail call i32 @quit(i32 0)
br label %25
33: ; preds = %15
%34 = tail call i32 @ai_pregame(i32 %0)
br label %39
35: ; preds = %15
%36 = tail call i32 @pass_between_humans(i32 1)
br label %25
37: ; preds = %15
%38 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %25
39: ; preds = %26, %33, %10
%40 = icmp eq i32 %1, 0
br i1 %40, label %44, label %41
41: ; preds = %39
%42 = tail call i32 (...) @marker_getposition()
%43 = tail call i32 @data_pregameres(i32 %0, i32 %42)
br label %44
44: ; preds = %41, %39
ret void
}