#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_canupgrade(int);
char *cat(char *, char *);
int data_getresource(int, int);
int /*<<< orphan*/ devcards_buy(int);
scalar_t__ devcards_remaining();
char *itoa(int);
int /*<<< orphan*/ map_setmessage(char *);
int ai_card(int player) {
  if (data_getresource(player, 4) < 1 || data_getresource(player, 1) < 1 ||
      data_getresource(player, 2) < 1 || devcards_remaining() == 0) {
    return 0;
  }
  if ((data_getresource(player, 4) >= 3 ||
       (data_getresource(player, 4) == 2 &&
        data_getresource(player, 1) == 2)) &&
      ai_canupgrade(player)) {
    return 0;
  }
  devcards_buy(player);
  map_setmessage(
      cat(cat("Player ", itoa(player + 1)), " purchased a dev card"));
  return 1;
}


x86 assembly (clang, -O0):
<ai_card>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1040 <data_getresource@plt>
cmp    $0x1,%eax
jl     11ce <ai_card+0x5e>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <data_getresource@plt>
cmp    $0x1,%eax
jl     11ce <ai_card+0x5e>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1040 <data_getresource@plt>
cmp    $0x1,%eax
jl     11ce <ai_card+0x5e>
mov    $0x0,%al
call   1080 <devcards_remaining@plt>
cmp    $0x0,%rax
jne    11da <ai_card+0x6a>
movl   $0x0,-0x4(%rbp)
jmp    127a <ai_card+0x10a>
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1040 <data_getresource@plt>
cmp    $0x3,%eax
jge    121c <ai_card+0xac>
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1040 <data_getresource@plt>
cmp    $0x2,%eax
jne    123a <ai_card+0xca>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <data_getresource@plt>
cmp    $0x2,%eax
jne    123a <ai_card+0xca>
mov    -0x8(%rbp),%edi
call   1030 <ai_canupgrade@plt>
cmp    $0x0,%rax
je     123a <ai_card+0xca>
movl   $0x0,-0x4(%rbp)
jmp    127a <ai_card+0x10a>
mov    -0x8(%rbp),%edi
call   1060 <devcards_buy@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1070 <itoa@plt>
mov    %rax,%rsi
lea    0xda9(%rip),%rdi
call   1090 <cat@plt>
mov    %rax,%rdi
lea    0xda2(%rip),%rsi
call   1090 <cat@plt>
mov    %rax,%rdi
call   1050 <map_setmessage@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ai_card>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x4,%esi
call   1040 <data_getresource@plt>
xor    %ebp,%ebp
test   %eax,%eax
jle    123a <ai_card+0xca>
mov    %ebx,%edi
mov    $0x1,%esi
call   1040 <data_getresource@plt>
test   %eax,%eax
jle    123a <ai_card+0xca>
mov    %ebx,%edi
mov    $0x2,%esi
call   1040 <data_getresource@plt>
test   %eax,%eax
jle    123a <ai_card+0xca>
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <devcards_remaining@plt>
test   %rax,%rax
je     123a <ai_card+0xca>
mov    %ebx,%edi
mov    $0x4,%esi
call   1040 <data_getresource@plt>
cmp    $0x2,%eax
jg     11f2 <ai_card+0x82>
mov    %ebx,%edi
mov    $0x4,%esi
call   1040 <data_getresource@plt>
cmp    $0x2,%eax
jne    11fe <ai_card+0x8e>
mov    %ebx,%edi
mov    $0x1,%esi
call   1040 <data_getresource@plt>
cmp    $0x2,%eax
jne    11fe <ai_card+0x8e>
mov    %ebx,%edi
call   1030 <ai_canupgrade@plt>
test   %rax,%rax
jne    123a <ai_card+0xca>
mov    %ebx,%edi
call   1060 <devcards_buy@plt>
add    $0x1,%ebx
mov    %ebx,%edi
call   1070 <itoa@plt>
lea    0xdea(%rip),%rdi
mov    %rax,%rsi
call   1090 <cat@plt>
lea    0xde3(%rip),%rsi
mov    %rax,%rdi
call   1090 <cat@plt>
mov    %rax,%rdi
call   1050 <map_setmessage@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" purchased a dev card\00"
define i32 @ai_card(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i32 @data_getresource(i32 %4, i32 4)
%6 = icmp slt i32 %5, 1
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i32 @data_getresource(i32 %8, i32 1)
%10 = icmp slt i32 %9, 1
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = load i32, i32* %3
%13 = call i32 @data_getresource(i32 %12, i32 2)
%14 = icmp slt i32 %13, 1
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = call i64 (...) @devcards_remaining()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %15, %11, %7, %1
store i32 0, i32* %2
br label %45
19: ; preds = %15
%20 = load i32, i32* %3
%21 = call i32 @data_getresource(i32 %20, i32 4)
%22 = icmp sge i32 %21, 3
br i1 %22, label %31, label %23
23: ; preds = %19
%24 = load i32, i32* %3
%25 = call i32 @data_getresource(i32 %24, i32 4)
%26 = icmp eq i32 %25, 2
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i32, i32* %3
%29 = call i32 @data_getresource(i32 %28, i32 1)
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %36
31: ; preds = %27, %19
%32 = load i32, i32* %3
%33 = call i64 @ai_canupgrade(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 0, i32* %2
br label %45
36: ; preds = %31, %27, %23
%37 = load i32, i32* %3
%38 = call i32 @devcards_buy(i32 %37)
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
%41 = call i8* @itoa(i32 %40)
%42 = call i8* @cat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %41)
%43 = call i8* @cat(i8* %42, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 @map_setmessage(i8* %43)
store i32 1, i32* %2
br label %45
45: ; preds = %36, %35, %18
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@.str = [8 x i8] c"Player \00"
@.str.1 = [22 x i8] c" purchased a dev card\00"
define i32 @ai_card(i32 %0) {
%2 = tail call i32 @data_getresource(i32 %0, i32 4)
%3 = icmp slt i32 %2, 1
br i1 %3, label %32, label %4
4: ; preds = %1
%5 = tail call i32 @data_getresource(i32 %0, i32 1)
%6 = icmp slt i32 %5, 1
br i1 %6, label %32, label %7
7: ; preds = %4
%8 = tail call i32 @data_getresource(i32 %0, i32 2)
%9 = icmp slt i32 %8, 1
br i1 %9, label %32, label %10
10: ; preds = %7
%11 = tail call i64 (...) @devcards_remaining()
%12 = icmp eq i64 %11, 0
br i1 %12, label %32, label %13
13: ; preds = %10
%14 = tail call i32 @data_getresource(i32 %0, i32 4)
%15 = icmp sgt i32 %14, 2
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = tail call i32 @data_getresource(i32 %0, i32 4)
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = tail call i32 @data_getresource(i32 %0, i32 1)
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %25
22: ; preds = %19, %13
%23 = tail call i64 @ai_canupgrade(i32 %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %22, %19, %16
%26 = tail call i32 @devcards_buy(i32 %0)
%27 = add nsw i32 %0, 1
%28 = tail call i8* @itoa(i32 %27)
%29 = tail call i8* @cat(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = tail call i8* @cat(i8* %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%31 = tail call i32 @map_setmessage(i8* %30)
br label %32
32: ; preds = %22, %1, %4, %7, %10, %25
%33 = phi i32 [ 1, %25 ], [ 0, %10 ], [ 0, %7 ], [ 0, %4 ], [ 0, %1 ], [ 0, %22 ]
ret i32 %33
}