#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_routine(int, int);
int /*<<< orphan*/ build_routine(int, int /*<<< orphan*/);
scalar_t__ data_isai(int);
int /*<<< orphan*/ data_refresh(int);
int devcards_knightoption(int);
int /*<<< orphan*/ devcards_newturn();
int devcards_routine(int, int);
int io_getkey();
int /*<<< orphan*/ io_printhelp();
int /*<<< orphan*/ io_printmap(int);
int /*<<< orphan*/ map_setmessage(char *);
int /*<<< orphan*/ marker_hide();
int /*<<< orphan*/ marker_move(int);
int /*<<< orphan*/ marker_show();
int /*<<< orphan*/ pass_between_humans(int);
int /*<<< orphan*/ quit(int);
int /*<<< orphan*/ road_routine(int, int /*<<< orphan*/);
int /*<<< orphan*/ roll(int);
int /*<<< orphan*/ trade_routine_other(int, int /*<<< orphan*/,
                                       int /*<<< orphan*/);
void main_routine(int p) {
  int c;
  int hascarded;
  hascarded = 0;
  int player = p;
  while (1) {
    data_refresh(player);
    io_printmap(!data_isai(player));
    map_setmessage("");
    if (data_isai(player)) {
      ai_routine(player, hascarded);
      player = (player + 1) % 4;
      data_refresh(player);
      devcards_newturn();
      hascarded = devcards_knightoption(player);
      roll(player);
      continue;
    }
    switch (c = io_getkey()) {
    case 0:
    case 1:
    case 2:
    case 3:
      marker_move(c);
      break;
    case 'p':
      player = (player + 1) % 4;
      if (!data_isai(player))
        pass_between_humans(player);
      data_refresh(player);
      devcards_newturn();
      hascarded = devcards_knightoption(player);
      roll(player);
      break;
    case 'b':
      marker_show();
      build_routine(player, 0);
      break;
    case 'c':
      hascarded += devcards_routine(player, hascarded);
      break;
    case 't':
      marker_hide();
      trade_routine_other(player, 0, 0);
      break;
    case 'r':
      marker_show();
      road_routine(player, 0);
      break;
    case 'h':
      io_printhelp();
      io_getkey();
      break;
    case 'q':
      quit(1);
      break;
    default:
      map_setmessage("Undefined key, press 'h' for help");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1080 <data_refresh@plt>
mov    -0x10(%rbp),%edi
call   1040 <data_isai@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1140 <io_printmap@plt>
lea    0xdaf(%rip),%rdi
call   10b0 <map_setmessage@plt>
mov    -0x10(%rbp),%edi
call   1040 <data_isai@plt>
cmp    $0x0,%rax
je     12cc <main_routine+0x9c>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1090 <ai_routine@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1080 <data_refresh@plt>
mov    $0x0,%al
call   1050 <devcards_newturn@plt>
mov    -0x10(%rbp),%edi
call   10f0 <devcards_knightoption@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1150 <roll@plt>
jmp    1248 <main_routine+0x18>
xor    %eax,%eax
call   10a0 <io_getkey@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0x4,%eax
jb     1360 <main_routine+0x130>
jmp    12e9 <main_routine+0xb9>
mov    -0x14(%rbp),%eax
sub    $0x62,%eax
je     13bf <main_routine+0x18f>
jmp    12fa <main_routine+0xca>
mov    -0x14(%rbp),%eax
sub    $0x63,%eax
je     13d5 <main_routine+0x1a5>
jmp    130b <main_routine+0xdb>
mov    -0x14(%rbp),%eax
sub    $0x68,%eax
je     1419 <main_routine+0x1e9>
jmp    131c <main_routine+0xec>
mov    -0x14(%rbp),%eax
sub    $0x70,%eax
je     136d <main_routine+0x13d>
jmp    132d <main_routine+0xfd>
mov    -0x14(%rbp),%eax
sub    $0x71,%eax
je     142c <main_routine+0x1fc>
jmp    133e <main_routine+0x10e>
mov    -0x14(%rbp),%eax
sub    $0x72,%eax
je     1403 <main_routine+0x1d3>
jmp    134f <main_routine+0x11f>
mov    -0x14(%rbp),%eax
sub    $0x74,%eax
je     13eb <main_routine+0x1bb>
jmp    143b <main_routine+0x20b>
mov    -0x8(%rbp),%edi
call   1070 <marker_move@plt>
jmp    1447 <main_routine+0x217>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <data_isai@plt>
cmp    $0x0,%rax
jne    1398 <main_routine+0x168>
mov    -0x10(%rbp),%edi
call   1110 <pass_between_humans@plt>
mov    -0x10(%rbp),%edi
call   1080 <data_refresh@plt>
mov    $0x0,%al
call   1050 <devcards_newturn@plt>
mov    -0x10(%rbp),%edi
call   10f0 <devcards_knightoption@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1150 <roll@plt>
jmp    1447 <main_routine+0x217>
mov    $0x0,%al
call   1130 <marker_show@plt>
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   10d0 <build_routine@plt>
jmp    1447 <main_routine+0x217>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1100 <devcards_routine@plt>
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1447 <main_routine+0x217>
mov    $0x0,%al
call   10e0 <marker_hide@plt>
mov    -0x10(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10c0 <trade_routine_other@plt>
jmp    1447 <main_routine+0x217>
mov    $0x0,%al
call   1130 <marker_show@plt>
mov    -0x10(%rbp),%edi
xor    %esi,%esi
call   1120 <road_routine@plt>
jmp    1447 <main_routine+0x217>
mov    $0x0,%al
call   1030 <io_printhelp@plt>
mov    $0x0,%al
call   10a0 <io_getkey@plt>
jmp    1447 <main_routine+0x217>
mov    $0x1,%edi
call   1060 <quit@plt>
jmp    1447 <main_routine+0x217>
lea    0xbbe(%rip),%rdi
call   10b0 <map_setmessage@plt>
jmp    1248 <main_routine+0x18>

x86 assembly (clang, -O2):
<main_routine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
lea    0xe2c(%rip),%r14
lea    0xe04(%rip),%r15
lea    0xdb1(%rip),%r12
xor    %ebp,%ebp
jmp    1260 <main_routine+0x30>
mov    %r15,%rdi
call   10b0 <map_setmessage@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1080 <data_refresh@plt>
mov    %ebx,%edi
call   1040 <data_isai@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1140 <io_printmap@plt>
mov    %r14,%rdi
call   10b0 <map_setmessage@plt>
mov    %ebx,%edi
call   1040 <data_isai@plt>
test   %rax,%rax
je     12d0 <main_routine+0xa0>
mov    %ebx,%edi
mov    %ebp,%esi
call   1090 <ai_routine@plt>
lea    0x1(%rbx),%eax
lea    0x4(%rbx),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
neg    %ecx
add    %ecx,%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1080 <data_refresh@plt>
xor    %eax,%eax
call   1050 <devcards_newturn@plt>
mov    %ebx,%edi
call   10f0 <devcards_knightoption@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1150 <roll@plt>
jmp    1260 <main_routine+0x30>
xchg   %ax,%ax
xor    %eax,%eax
call   10a0 <io_getkey@plt>
lea    -0x62(%rax),%ecx
cmp    $0x12,%ecx
ja     12fd <main_routine+0xcd>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
xor    %eax,%eax
call   1130 <marker_show@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   10d0 <build_routine@plt>
jmp    1260 <main_routine+0x30>
cmp    $0x4,%eax
jae    1253 <main_routine+0x23>
mov    %eax,%edi
call   1070 <marker_move@plt>
jmp    1260 <main_routine+0x30>
mov    %ebx,%edi
mov    %ebp,%esi
call   1100 <devcards_routine@plt>
add    %eax,%ebp
jmp    1260 <main_routine+0x30>
xor    %eax,%eax
call   1030 <io_printhelp@plt>
xor    %eax,%eax
call   10a0 <io_getkey@plt>
jmp    1260 <main_routine+0x30>
lea    0x1(%rbx),%eax
lea    0x4(%rbx),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
neg    %ecx
add    %ecx,%ebx
add    $0x1,%ebx
mov    %ebx,%edi
call   1040 <data_isai@plt>
test   %rax,%rax
jne    12ae <main_routine+0x7e>
mov    %ebx,%edi
call   1110 <pass_between_humans@plt>
jmp    12ae <main_routine+0x7e>
mov    $0x1,%edi
call   1060 <quit@plt>
jmp    1260 <main_routine+0x30>
xor    %eax,%eax
call   1130 <marker_show@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1120 <road_routine@plt>
jmp    1260 <main_routine+0x30>
xor    %eax,%eax
call   10e0 <marker_hide@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <trade_routine_other@plt>
jmp    1260 <main_routine+0x30>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [34 x i8] c"Undefined key, press 'h' for help\00"
define void @main_routine(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
%6 = load i32, i32* %2
store i32 %6, i32* %5
br label %7
7: ; preds = %1, %20, %82
%8 = load i32, i32* %5
%9 = call i32 @data_refresh(i32 %8)
%10 = load i32, i32* %5
%11 = call i64 @data_isai(i32 %10)
%12 = icmp ne i64 %11, 0
%13 = xor i1 %12, true
%14 = zext i1 %13 to i32
%15 = call i32 @io_printmap(i32 %14)
%16 = call i32 @map_setmessage(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %5
%18 = call i64 @data_isai(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %34
20: ; preds = %7
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = call i32 @ai_routine(i32 %21, i32 %22)
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = srem i32 %25, 4
store i32 %26, i32* %5
%27 = load i32, i32* %5
%28 = call i32 @data_refresh(i32 %27)
%29 = call i32 (...) @devcards_newturn()
%30 = load i32, i32* %5
%31 = call i32 @devcards_knightoption(i32 %30)
store i32 %31, i32* %4
%32 = load i32, i32* %5
%33 = call i32 @roll(i32 %32)
br label %7
34: ; preds = %7
%35 = call i32 (...) @io_getkey()
store i32 %35, i32* %3
switch i32 %35, label %80 [
i32 0, label %36
i32 1, label %36
i32 2, label %36
i32 3, label %36
i32 112, label %39
i32 98, label %57
i32 99, label %61
i32 116, label %67
i32 114, label %71
i32 104, label %75
i32 113, label %78
]
36: ; preds = %34, %34, %34, %34
%37 = load i32, i32* %3
%38 = call i32 @marker_move(i32 %37)
br label %82
39: ; preds = %34
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
%42 = srem i32 %41, 4
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = call i64 @data_isai(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %39
%47 = load i32, i32* %5
%48 = call i32 @pass_between_humans(i32 %47)
br label %49
49: ; preds = %46, %39
%50 = load i32, i32* %5
%51 = call i32 @data_refresh(i32 %50)
%52 = call i32 (...) @devcards_newturn()
%53 = load i32, i32* %5
%54 = call i32 @devcards_knightoption(i32 %53)
store i32 %54, i32* %4
%55 = load i32, i32* %5
%56 = call i32 @roll(i32 %55)
br label %82
57: ; preds = %34
%58 = call i32 (...) @marker_show()
%59 = load i32, i32* %5
%60 = call i32 @build_routine(i32 %59, i32 0)
br label %82
61: ; preds = %34
%62 = load i32, i32* %5
%63 = load i32, i32* %4
%64 = call i32 @devcards_routine(i32 %62, i32 %63)
%65 = load i32, i32* %4
%66 = add nsw i32 %65, %64
store i32 %66, i32* %4
br label %82
67: ; preds = %34
%68 = call i32 (...) @marker_hide()
%69 = load i32, i32* %5
%70 = call i32 @trade_routine_other(i32 %69, i32 0, i32 0)
br label %82
71: ; preds = %34
%72 = call i32 (...) @marker_show()
%73 = load i32, i32* %5
%74 = call i32 @road_routine(i32 %73, i32 0)
br label %82
75: ; preds = %34
%76 = call i32 (...) @io_printhelp()
%77 = call i32 (...) @io_getkey()
br label %82
78: ; preds = %34
%79 = call i32 @quit(i32 1)
br label %82
80: ; preds = %34
%81 = call i32 @map_setmessage(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %82
82: ; preds = %80, %78, %75, %71, %67, %61, %57, %49, %36
br label %7
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [34 x i8] c"Undefined key, press 'h' for help\00"
define void @main_routine(i32 %0) {
br label %2
2: ; preds = %25, %1
%3 = phi i32 [ 0, %1 ], [ %26, %25 ]
%4 = phi i32 [ %0, %1 ], [ %27, %25 ]
%5 = tail call i32 @data_refresh(i32 %4)
%6 = tail call i64 @data_isai(i32 %4)
%7 = icmp eq i64 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @io_printmap(i32 %8)
%10 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%11 = tail call i64 @data_isai(i32 %4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %2
%14 = tail call i32 @ai_routine(i32 %4, i32 %3)
%15 = add nsw i32 %4, 1
%16 = srem i32 %15, 4
%17 = tail call i32 @data_refresh(i32 %16)
%18 = tail call i32 (...) @devcards_newturn()
%19 = tail call i32 @devcards_knightoption(i32 %16)
%20 = tail call i32 @roll(i32 %16)
br label %25
21: ; preds = %2
%22 = tail call i32 (...) @io_getkey()
switch i32 %22, label %57 [
i32 0, label %23
i32 1, label %23
i32 2, label %23
i32 3, label %23
i32 112, label %28
i32 98, label %40
i32 99, label %43
i32 116, label %46
i32 114, label %49
i32 104, label %52
i32 113, label %55
]
23: ; preds = %21, %21, %21, %21
%24 = tail call i32 @marker_move(i32 %22)
br label %25
25: ; preds = %23, %35, %40, %43, %46, %49, %52, %55, %57, %13
%26 = phi i32 [ %19, %13 ], [ %3, %57 ], [ %3, %55 ], [ %3, %52 ], [ %3, %49 ], [ %3, %46 ], [ %45, %43 ], [ %3, %40 ], [ %38, %35 ], [ %3, %23 ]
%27 = phi i32 [ %16, %13 ], [ %4, %57 ], [ %4, %55 ], [ %4, %52 ], [ %4, %49 ], [ %4, %46 ], [ %4, %43 ], [ %4, %40 ], [ %30, %35 ], [ %4, %23 ]
br label %2
28: ; preds = %21
%29 = add nsw i32 %4, 1
%30 = srem i32 %29, 4
%31 = tail call i64 @data_isai(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = tail call i32 @pass_between_humans(i32 %30)
br label %35
35: ; preds = %33, %28
%36 = tail call i32 @data_refresh(i32 %30)
%37 = tail call i32 (...) @devcards_newturn()
%38 = tail call i32 @devcards_knightoption(i32 %30)
%39 = tail call i32 @roll(i32 %30)
br label %25
40: ; preds = %21
%41 = tail call i32 (...) @marker_show()
%42 = tail call i32 @build_routine(i32 %4, i32 0)
br label %25
43: ; preds = %21
%44 = tail call i32 @devcards_routine(i32 %4, i32 %3)
%45 = add nsw i32 %44, %3
br label %25
46: ; preds = %21
%47 = tail call i32 (...) @marker_hide()
%48 = tail call i32 @trade_routine_other(i32 %4, i32 0, i32 0)
br label %25
49: ; preds = %21
%50 = tail call i32 (...) @marker_show()
%51 = tail call i32 @road_routine(i32 %4, i32 0)
br label %25
52: ; preds = %21
%53 = tail call i32 (...) @io_printhelp()
%54 = tail call i32 (...) @io_getkey()
br label %25
55: ; preds = %21
%56 = tail call i32 @quit(i32 1)
br label %25
57: ; preds = %21
%58 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %25
}