#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 data_getresource(int, int);
int devcards_VP(int);
int devcards_YOP(int);
int devcards_buildroad(int);
int /*<<< orphan*/ devcards_buy(int);
int /*<<< orphan*/ devcards_canplay(int, int);
int devcards_knight(int);
int devcards_monopoly(int);
int /*<<< orphan*/ map_setmessage(char *);
int devcards_handle(int player, int pos, int hascarded) {
  if (pos > 0 && hascarded) {
    map_setmessage("Cannot play more than one card per turn");
    return 0;
  }
  if (pos > 0 && !devcards_canplay(player, pos - 1)) {
    map_setmessage("Cannot play a card the same turn you buy it");
    return 0;
  }
  switch (pos) {
  case 0:
    if (data_getresource(player, 4) >= 1 && data_getresource(player, 1 >= 1) &&
        data_getresource(player, 2) >= 1)
      devcards_buy(player);
    else
      map_setmessage(
          "Not enough resources, requires one stone, wheat and sheep.");
    return 0;
    break;
  case 1:
    return devcards_knight(player);
    break;
  case 2:
    return devcards_buildroad(player);
    break;
  case 3:
    return devcards_monopoly(player);
    break;
  case 4:
    return devcards_YOP(player);
    break;
  case 5:
    return devcards_VP(player);
    break;
  default:
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<devcards_handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11cd <devcards_handle+0x3d>
cmpl   $0x0,-0x10(%rbp)
je     11cd <devcards_handle+0x3d>
lea    0xe5c(%rip),%rdi
call   1050 <map_setmessage@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ee <devcards_handle+0x15e>
cmpl   $0x0,-0xc(%rbp)
jle    1206 <devcards_handle+0x76>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1070 <devcards_canplay@plt>
cmp    $0x0,%eax
jne    1206 <devcards_handle+0x76>
lea    0xe4b(%rip),%rdi
call   1050 <map_setmessage@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ee <devcards_handle+0x15e>
mov    -0xc(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x5,%rax
ja     12e2 <devcards_handle+0x152>
mov    -0x18(%rbp),%rax
lea    0xdde(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%edi
mov    $0x4,%esi
call   1040 <data_getresource@plt>
cmp    $0x1,%eax
jl     127a <devcards_handle+0xea>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <data_getresource@plt>
cmp    $0x0,%eax
je     127a <devcards_handle+0xea>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1040 <data_getresource@plt>
cmp    $0x1,%eax
jl     127a <devcards_handle+0xea>
mov    -0x8(%rbp),%edi
call   10a0 <devcards_buy@plt>
jmp    1286 <devcards_handle+0xf6>
lea    0xdeb(%rip),%rdi
call   1050 <map_setmessage@plt>
movl   $0x0,-0x4(%rbp)
jmp    12ee <devcards_handle+0x15e>
mov    -0x8(%rbp),%edi
call   1080 <devcards_knight@plt>
mov    %eax,-0x4(%rbp)
jmp    12ee <devcards_handle+0x15e>
mov    -0x8(%rbp),%edi
call   1030 <devcards_buildroad@plt>
mov    %eax,-0x4(%rbp)
jmp    12ee <devcards_handle+0x15e>
mov    -0x8(%rbp),%edi
call   1060 <devcards_monopoly@plt>
mov    %eax,-0x4(%rbp)
jmp    12ee <devcards_handle+0x15e>
mov    -0x8(%rbp),%edi
call   10b0 <devcards_YOP@plt>
mov    %eax,-0x4(%rbp)
jmp    12ee <devcards_handle+0x15e>
mov    -0x8(%rbp),%edi
call   1090 <devcards_VP@plt>
mov    %eax,-0x4(%rbp)
jmp    12ee <devcards_handle+0x15e>
jmp    12e7 <devcards_handle+0x157>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<devcards_handle>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
test   %esi,%esi
jle    11b4 <devcards_handle+0x24>
test   %edx,%edx
je     11b4 <devcards_handle+0x24>
lea    0xe72(%rip),%rdi
call   1050 <map_setmessage@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
test   %ebx,%ebx
jle    11c6 <devcards_handle+0x36>
lea    -0x1(%rbx),%esi
mov    %ebp,%edi
call   1070 <devcards_canplay@plt>
test   %eax,%eax
je     1216 <devcards_handle+0x86>
cmp    $0x5,%ebx
ja     11ab <devcards_handle+0x1b>
mov    %ebx,%eax
lea    0xe2c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %ebp,%edi
mov    $0x4,%esi
call   1040 <data_getresource@plt>
test   %eax,%eax
jle    1260 <devcards_handle+0xd0>
mov    %ebp,%edi
mov    $0x1,%esi
call   1040 <data_getresource@plt>
test   %eax,%eax
je     1260 <devcards_handle+0xd0>
mov    %ebp,%edi
mov    $0x2,%esi
call   1040 <data_getresource@plt>
test   %eax,%eax
jle    1260 <devcards_handle+0xd0>
mov    %ebp,%edi
call   10a0 <devcards_buy@plt>
jmp    11ab <devcards_handle+0x1b>
lea    0xe23(%rip),%rdi
jmp    11a6 <devcards_handle+0x16>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1080 <devcards_knight@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <devcards_buildroad@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <devcards_monopoly@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    10b0 <devcards_YOP@plt>
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1090 <devcards_VP@plt>
lea    0xe05(%rip),%rdi
jmp    11a6 <devcards_handle+0x16>

LLVM IR (-O0):
@.str = [40 x i8] c"Cannot play more than one card per turn\00"
@.str.1 = [44 x i8] c"Cannot play a card the same turn you buy it\00"
@.str.2 = [59 x i8] c"Not enough resources, requires one stone, wheat and sheep.\00"
define i32 @devcards_handle(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %6
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @map_setmessage(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %63
15: ; preds = %10, %3
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 1
%22 = call i32 @devcards_canplay(i32 %19, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %18
%25 = call i32 @map_setmessage(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %63
26: ; preds = %18, %15
%27 = load i32, i32* %6
switch i32 %27, label %61 [
i32 0, label %28
i32 1, label %46
i32 2, label %49
i32 3, label %52
i32 4, label %55
i32 5, label %58
]
28: ; preds = %26
%29 = load i32, i32* %5
%30 = call i32 @data_getresource(i32 %29, i32 4)
%31 = icmp sge i32 %30, 1
br i1 %31, label %32, label %43
32: ; preds = %28
%33 = load i32, i32* %5
%34 = call i32 @data_getresource(i32 %33, i32 1)
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = load i32, i32* %5
%38 = call i32 @data_getresource(i32 %37, i32 2)
%39 = icmp sge i32 %38, 1
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %5
%42 = call i32 @devcards_buy(i32 %41)
br label %45
43: ; preds = %36, %32, %28
%44 = call i32 @map_setmessage(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
store i32 0, i32* %4
br label %63
46: ; preds = %26
%47 = load i32, i32* %5
%48 = call i32 @devcards_knight(i32 %47)
store i32 %48, i32* %4
br label %63
49: ; preds = %26
%50 = load i32, i32* %5
%51 = call i32 @devcards_buildroad(i32 %50)
store i32 %51, i32* %4
br label %63
52: ; preds = %26
%53 = load i32, i32* %5
%54 = call i32 @devcards_monopoly(i32 %53)
store i32 %54, i32* %4
br label %63
55: ; preds = %26
%56 = load i32, i32* %5
%57 = call i32 @devcards_YOP(i32 %56)
store i32 %57, i32* %4
br label %63
58: ; preds = %26
%59 = load i32, i32* %5
%60 = call i32 @devcards_VP(i32 %59)
store i32 %60, i32* %4
br label %63
61: ; preds = %26
br label %62
62: ; preds = %61
store i32 0, i32* %4
br label %63
63: ; preds = %62, %58, %55, %52, %49, %46, %45, %24, %13
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@.str = [40 x i8] c"Cannot play more than one card per turn\00"
@.str.1 = [44 x i8] c"Cannot play a card the same turn you buy it\00"
@.str.2 = [59 x i8] c"Not enough resources, requires one stone, wheat and sheep.\00"
define i32 @devcards_handle(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
%5 = icmp ne i32 %2, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %40
9: ; preds = %3
br i1 %4, label %10, label %16
10: ; preds = %9
%11 = add nsw i32 %1, -1
%12 = tail call i32 @devcards_canplay(i32 %0, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %40
16: ; preds = %10, %9
switch i32 %1, label %40 [
i32 0, label %17
i32 1, label %30
i32 2, label %32
i32 3, label %34
i32 4, label %36
i32 5, label %38
]
17: ; preds = %16
%18 = tail call i32 @data_getresource(i32 %0, i32 4)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = tail call i32 @data_getresource(i32 %0, i32 1)
%22 = icmp eq i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %20
%24 = tail call i32 @data_getresource(i32 %0, i32 2)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = tail call i32 @devcards_buy(i32 %0)
br label %40
28: ; preds = %23, %20, %17
%29 = tail call i32 @map_setmessage(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
br label %40
30: ; preds = %16
%31 = tail call i32 @devcards_knight(i32 %0)
br label %40
32: ; preds = %16
%33 = tail call i32 @devcards_buildroad(i32 %0)
br label %40
34: ; preds = %16
%35 = tail call i32 @devcards_monopoly(i32 %0)
br label %40
36: ; preds = %16
%37 = tail call i32 @devcards_YOP(i32 %0)
br label %40
38: ; preds = %16
%39 = tail call i32 @devcards_VP(i32 %0)
br label %40
40: ; preds = %16, %26, %28, %38, %36, %34, %32, %30, %14, %7
%41 = phi i32 [ 0, %7 ], [ %39, %38 ], [ %37, %36 ], [ %35, %34 ], [ %33, %32 ], [ %31, %30 ], [ 0, %14 ], [ 0, %28 ], [ 0, %26 ], [ 0, %16 ]
ret i32 %41
}