#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 */
scalar_t__ ai_canroad(int, int);
int /*<<< orphan*/ ai_road(int, int);
char *cat(char *, char *);
int /*<<< orphan*/ data_addcards(int, int, int);
scalar_t__ data_getcards(int, int);
char *itoa(int);
int /*<<< orphan*/ map_setmessage(char *);
int /*<<< orphan*/ sleep(int);
int ai_playroad(int player) {
  if (data_getcards(player, 1) && ai_canroad(player, 1)) {
    map_setmessage(
        cat(cat("Player ", itoa(player + 1)), " played road building"));
    data_addcards(player, 1, -1);
    ai_road(player, 1);
    sleep(1);
    ai_road(player, 1);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ai_playroad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <data_getcards@plt>
cmp    $0x0,%rax
je     122c <ai_playroad+0xac>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1070 <ai_canroad@plt>
cmp    $0x0,%rax
je     122c <ai_playroad+0xac>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1080 <itoa@plt>
mov    %rax,%rsi
lea    0xe32(%rip),%rdi
call   10a0 <cat@plt>
mov    %rax,%rdi
lea    0xe2b(%rip),%rsi
call   10a0 <cat@plt>
mov    %rax,%rdi
call   1050 <map_setmessage@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <data_addcards@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1060 <ai_road@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1060 <ai_road@plt>
movl   $0x1,-0x4(%rbp)
jmp    1233 <ai_playroad+0xb3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_playroad>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x1,%esi
call   1030 <data_getcards@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     120d <ai_playroad+0x8d>
mov    %ebx,%edi
mov    $0x1,%esi
call   1070 <ai_canroad@plt>
test   %rax,%rax
je     120d <ai_playroad+0x8d>
lea    0x1(%rbx),%edi
call   1080 <itoa@plt>
lea    0xe4a(%rip),%rdi
mov    %rax,%rsi
call   10a0 <cat@plt>
lea    0xe43(%rip),%rsi
mov    %rax,%rdi
call   10a0 <cat@plt>
mov    %rax,%rdi
call   1050 <map_setmessage@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1040 <data_addcards@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <ai_road@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
mov    %ebx,%edi
mov    $0x1,%esi
call   1060 <ai_road@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Player \00"
@.str.1 = [22 x i8] c" played road building\00"
define i32 @ai_playroad(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i64 @data_getcards(i32 %4, i32 1)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %25
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i64 @ai_canroad(i32 %8, i32 1)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %7
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
%14 = call i8* @itoa(i32 %13)
%15 = call i8* @cat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i8* @cat(i8* %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @map_setmessage(i8* %16)
%18 = load i32, i32* %3
%19 = call i32 @data_addcards(i32 %18, i32 1, i32 -1)
%20 = load i32, i32* %3
%21 = call i32 @ai_road(i32 %20, i32 1)
%22 = call i32 @sleep(i32 1)
%23 = load i32, i32* %3
%24 = call i32 @ai_road(i32 %23, i32 1)
store i32 1, i32* %2
br label %26
25: ; preds = %7, %1
store i32 0, i32* %2
br label %26
26: ; preds = %25, %11
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [8 x i8] c"Player \00"
@.str.1 = [22 x i8] c" played road building\00"
define i32 @ai_playroad(i32 %0) {
%2 = tail call i64 @data_getcards(i32 %0, i32 1)
%3 = icmp eq i64 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i64 @ai_canroad(i32 %0, i32 1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = add nsw i32 %0, 1
%9 = tail call i8* @itoa(i32 %8)
%10 = tail call i8* @cat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i8* @cat(i8* %10, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @map_setmessage(i8* %11)
%13 = tail call i32 @data_addcards(i32 %0, i32 1, i32 -1)
%14 = tail call i32 @ai_road(i32 %0, i32 1)
%15 = tail call i32 @sleep(i32 1)
%16 = tail call i32 @ai_road(i32 %0, i32 1)
br label %17
17: ; preds = %1, %4, %7
%18 = phi i32 [ 1, %7 ], [ 0, %4 ], [ 0, %1 ]
ret i32 %18
}