#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 */
char *cat(char *, char *);
int /*<<< orphan*/ data_addcards(int, int, int);
int data_getcards(int, int);
int /*<<< orphan*/ data_refresh(int);
int io_getkey();
int /*<<< orphan*/ io_printmap(int);
char *itoa(int);
int /*<<< orphan*/ map_setmessage(char *);
int /*<<< orphan*/ marker_move(int);
int /*<<< orphan*/ marker_show();
int /*<<< orphan*/ road_routine(int, int);
int devcards_buildroad(int player) {
  if (data_getcards(player, 1) >= 1) {
    data_addcards(player, 1, -1);
    int i = 2;
    int c;
    while (i >= 1) {
      map_setmessage(
          cat(cat(cat("Build ", itoa(i)), " road"), (i == 2) ? "s" : ""));
      data_refresh(player);
      io_printmap(1);
      switch (c = io_getkey()) {
      case 0:
      case 1:
      case 2:
      case 3:
        marker_move(c);
        break;
      case 4:
      case 'r':
        marker_show();
        if (road_routine(player, 1))
          i--;
        break;
      default:
        break;
      }
    }
    map_setmessage("");
    io_printmap(1);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<devcards_buildroad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <data_getcards@plt>
cmp    $0x1,%eax
jl     12f7 <devcards_buildroad+0x147>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <data_addcards@plt>
movl   $0x2,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jl     12d5 <devcards_buildroad+0x125>
mov    -0xc(%rbp),%edi
call   10c0 <itoa@plt>
mov    %rax,%rsi
lea    0xdfa(%rip),%rdi
call   10d0 <cat@plt>
mov    %rax,%rdi
lea    0xdf2(%rip),%rsi
call   10d0 <cat@plt>
mov    %rax,%rdi
mov    -0xc(%rbp),%eax
sub    $0x2,%eax
lea    0xde3(%rip),%rax
lea    0xdd5(%rip),%rsi
cmove  %rax,%rsi
call   10d0 <cat@plt>
mov    %rax,%rdi
call   1080 <map_setmessage@plt>
mov    -0x8(%rbp),%edi
call   1060 <data_refresh@plt>
mov    $0x1,%edi
call   10b0 <io_printmap@plt>
xor    %eax,%eax
call   1070 <io_getkey@plt>
mov    %eax,-0x10(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0x4,%eax
jb     1293 <devcards_buildroad+0xe3>
jmp    1271 <devcards_buildroad+0xc1>
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
je     12a0 <devcards_buildroad+0xf0>
jmp    1282 <devcards_buildroad+0xd2>
mov    -0x14(%rbp),%eax
sub    $0x72,%eax
je     12a0 <devcards_buildroad+0xf0>
jmp    12cb <devcards_buildroad+0x11b>
mov    -0x10(%rbp),%edi
call   1050 <marker_move@plt>
jmp    12d0 <devcards_buildroad+0x120>
mov    $0x0,%al
call   10a0 <marker_show@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1090 <road_routine@plt>
cmp    $0x0,%eax
je     12c6 <devcards_buildroad+0x116>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    12d0 <devcards_buildroad+0x120>
jmp    12d0 <devcards_buildroad+0x120>
jmp    11ea <devcards_buildroad+0x3a>
lea    0xd2a(%rip),%rdi
call   1080 <map_setmessage@plt>
mov    $0x1,%edi
call   10b0 <io_printmap@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fe <devcards_buildroad+0x14e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devcards_buildroad>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x1,%esi
call   1030 <data_getcards@plt>
test   %eax,%eax
jle    12ae <devcards_buildroad+0xfe>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <data_addcards@plt>
mov    $0x2,%ebp
lea    0xe14(%rip),%r14
lea    0xe14(%rip),%r15
lea    0xe13(%rip),%r12
lea    0xe05(%rip),%r13
jmp    121b <devcards_buildroad+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edi
call   1050 <marker_move@plt>
test   %ebp,%ebp
jle    1291 <devcards_buildroad+0xe1>
mov    %ebp,%edi
call   10c0 <itoa@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   10d0 <cat@plt>
mov    %rax,%rdi
mov    %r15,%rsi
call   10d0 <cat@plt>
cmp    $0x2,%ebp
mov    %r13,%rsi
cmove  %r12,%rsi
mov    %rax,%rdi
call   10d0 <cat@plt>
mov    %rax,%rdi
call   1080 <map_setmessage@plt>
mov    %ebx,%edi
call   1060 <data_refresh@plt>
mov    $0x1,%edi
call   10b0 <io_printmap@plt>
xor    %eax,%eax
call   1070 <io_getkey@plt>
cmp    $0x4,%eax
jb     1210 <devcards_buildroad+0x60>
je     1276 <devcards_buildroad+0xc6>
cmp    $0x72,%eax
jne    1217 <devcards_buildroad+0x67>
xor    %eax,%eax
call   10a0 <marker_show@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1090 <road_routine@plt>
cmp    $0x1,%eax
adc    $0xffffffff,%ebp
jmp    1217 <devcards_buildroad+0x67>
lea    0xd6e(%rip),%rdi
call   1080 <map_setmessage@plt>
mov    $0x1,%ebx
mov    $0x1,%edi
call   10b0 <io_printmap@plt>
jmp    12b0 <devcards_buildroad+0x100>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Build \00"
@.str.1 = [6 x i8] c" road\00"
@.str.2 = [2 x i8] c"s\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @devcards_buildroad(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @data_getcards(i32 %6, i32 1)
%8 = icmp sge i32 %7, 1
br i1 %8, label %9, label %47
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @data_addcards(i32 %10, i32 1, i32 -1)
store i32 2, i32* %4
br label %12
12: ; preds = %43, %9
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 1
br i1 %14, label %15, label %44
15: ; preds = %12
%16 = load i32, i32* %4
%17 = call i8* @itoa(i32 %16)
%18 = call i8* @cat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i8* @cat(i8* %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 2
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%24 = call i8* @cat(i8* %19, i8* %23)
%25 = call i32 @map_setmessage(i8* %24)
%26 = load i32, i32* %3
%27 = call i32 @data_refresh(i32 %26)
%28 = call i32 @io_printmap(i32 1)
%29 = call i32 (...) @io_getkey()
store i32 %29, i32* %5
switch i32 %29, label %42 [
i32 0, label %30
i32 1, label %30
i32 2, label %30
i32 3, label %30
i32 4, label %33
i32 114, label %33
]
30: ; preds = %15, %15, %15, %15
%31 = load i32, i32* %5
%32 = call i32 @marker_move(i32 %31)
br label %43
33: ; preds = %15, %15
%34 = call i32 (...) @marker_show()
%35 = load i32, i32* %3
%36 = call i32 @road_routine(i32 %35, i32 1)
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* %4
%40 = add nsw i32 %39, -1
store i32 %40, i32* %4
br label %41
41: ; preds = %38, %33
br label %43
42: ; preds = %15
br label %43
43: ; preds = %42, %41, %30
br label %12
44: ; preds = %12
%45 = call i32 @map_setmessage(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @io_printmap(i32 1)
store i32 1, i32* %2
br label %48
47: ; preds = %1
store i32 0, i32* %2
br label %48
48: ; preds = %47, %44
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
@.str = [7 x i8] c"Build \00"
@.str.1 = [6 x i8] c" road\00"
@.str.2 = [2 x i8] c"s\00"
@.str.3 = [1 x i8] zeroinitializer
define i32 @devcards_buildroad(i32 %0) {
%2 = tail call i32 @data_getcards(i32 %0, i32 1)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %32
4: ; preds = %1
%5 = tail call i32 @data_addcards(i32 %0, i32 1, i32 -1)
br label %6
6: ; preds = %4, %26
%7 = phi i32 [ 2, %4 ], [ %27, %26 ]
%8 = tail call i8* @itoa(i32 %7)
%9 = tail call i8* @cat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i8* @cat(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %7, 2
%12 = select i1 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%13 = tail call i8* @cat(i8* %10, i8* %12)
%14 = tail call i32 @map_setmessage(i8* %13)
%15 = tail call i32 @data_refresh(i32 %0)
%16 = tail call i32 @io_printmap(i32 1)
%17 = tail call i32 (...) @io_getkey()
switch i32 %17, label %26 [
i32 0, label %18
i32 1, label %18
i32 2, label %18
i32 3, label %18
i32 4, label %20
i32 114, label %20
]
18: ; preds = %6, %6, %6, %6
%19 = tail call i32 @marker_move(i32 %17)
br label %26
20: ; preds = %6, %6
%21 = tail call i32 (...) @marker_show()
%22 = tail call i32 @road_routine(i32 %0, i32 1)
%23 = icmp ne i32 %22, 0
%24 = sext i1 %23 to i32
%25 = add nsw i32 %7, %24
br label %26
26: ; preds = %20, %6, %18
%27 = phi i32 [ %7, %6 ], [ %7, %18 ], [ %25, %20 ]
%28 = icmp sgt i32 %27, 0
br i1 %28, label %6, label %29
29: ; preds = %26
%30 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%31 = tail call i32 @io_printmap(i32 1)
br label %32
32: ; preds = %1, %29
%33 = phi i32 [ 1, %29 ], [ 0, %1 ]
ret i32 %33
}