#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*/ data_addgold(int, int);
int /*<<< orphan*/ data_build(int, int);
int /*<<< orphan*/ data_buildwonder(int, int);
int data_canafford(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ data_discard(int, int);
int /*<<< orphan*/ data_getera();
int /*<<< orphan*/ data_gethand(int, int *);
int data_getnextwonderstage(int);
int /*<<< orphan*/ data_getwonder(int);
scalar_t__ data_hasbuiltname(int, int /*<<< orphan*/, int);
int data_numplayers();
int /*<<< orphan*/ data_spendfreebuild();
int /*<<< orphan*/ postmessage(char *);
int postoptions(int, int);
scalar_t__ postyn(int, int, char *);
int player_build(int focus, int cursor, int player, int y) {
  int hand[7];
  data_gethand(player, hand);
  int afford = data_canafford(player, data_getera(), hand[cursor]);
  if (focus == data_numplayers()) {
    if (hand[cursor] == -1)
      return 0;
    int choice = postoptions(61, y);
    if (choice == 0) {
      if (data_hasbuiltname(player, data_getera(), hand[cursor])) {
        postmessage("Cannot have two of the same card!");
        return 0;
      }
      if (afford == 1 || (afford == 2 && postyn(61, y, "Spend free build?"))) {
        data_build(player, hand[cursor]);
        if (afford == 2)
          data_spendfreebuild();
        return 1;
      } else
        postmessage("Can't afford this!");
    } else if (choice == 1) {
      data_discard(player, hand[cursor]);
      data_addgold(3, player);
      return 1;
    } else if (choice == 2) {
      if (data_getnextwonderstage(player) == -1) {
        postmessage("Wonder already complete.");
      } else if (data_canafford(player, data_getwonder(player),
                                data_getnextwonderstage(player))) {
        data_buildwonder(player, hand[cursor]);
        return 1;
      } else
        postmessage("Can't afford this!");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<player_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1030 <data_gethand@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    $0x0,%al
call   1040 <data_getera@plt>
mov    -0x40(%rbp),%edi
mov    %eax,%esi
movslq -0xc(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
call   10f0 <data_canafford@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1110 <data_numplayers@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jne    1401 <player_build+0x211>
movslq -0xc(%rbp),%rax
cmpl   $0xffffffff,-0x30(%rbp,%rax,4)
jne    1267 <player_build+0x77>
movl   $0x0,-0x4(%rbp)
jmp    1408 <player_build+0x218>
mov    -0x14(%rbp),%esi
mov    $0x3d,%edi
call   10e0 <postoptions@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    1332 <player_build+0x142>
mov    -0x10(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    $0x0,%al
call   1040 <data_getera@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
movslq -0xc(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
call   10a0 <data_hasbuiltname@plt>
cmp    $0x0,%rax
je     12c2 <player_build+0xd2>
lea    0xd4f(%rip),%rdi
call   10c0 <postmessage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1408 <player_build+0x218>
cmpl   $0x1,-0x34(%rbp)
je     12f4 <player_build+0x104>
cmpl   $0x2,-0x34(%rbp)
jne    1321 <player_build+0x131>
mov    -0x14(%rbp),%esi
mov    $0x3d,%edi
lea    0xd3d(%rip),%rdx
call   10d0 <postyn@plt>
cmp    $0x0,%rax
je     1321 <player_build+0x131>
mov    -0x10(%rbp),%edi
movslq -0xc(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
call   10b0 <data_build@plt>
cmpl   $0x2,-0x34(%rbp)
jne    1315 <player_build+0x125>
mov    $0x0,%al
call   1100 <data_spendfreebuild@plt>
movl   $0x1,-0x4(%rbp)
jmp    1408 <player_build+0x218>
lea    0xd0c(%rip),%rdi
call   10c0 <postmessage@plt>
jmp    13fc <player_build+0x20c>
cmpl   $0x1,-0x38(%rbp)
jne    1365 <player_build+0x175>
mov    -0x10(%rbp),%edi
movslq -0xc(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
call   1050 <data_discard@plt>
mov    -0x10(%rbp),%esi
mov    $0x3,%edi
call   1060 <data_addgold@plt>
movl   $0x1,-0x4(%rbp)
jmp    1408 <player_build+0x218>
cmpl   $0x2,-0x38(%rbp)
jne    13f2 <player_build+0x202>
mov    -0x10(%rbp),%edi
call   1090 <data_getnextwonderstage@plt>
cmp    $0xffffffff,%eax
jne    1391 <player_build+0x1a1>
lea    0xcc0(%rip),%rdi
call   10c0 <postmessage@plt>
jmp    13ed <player_build+0x1fd>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%edi
call   1080 <data_getwonder@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%edi
call   1090 <data_getnextwonderstage@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%esi
mov    %eax,%edx
call   10f0 <data_canafford@plt>
cmp    $0x0,%eax
je     13dc <player_build+0x1ec>
mov    -0x10(%rbp),%edi
movslq -0xc(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
call   1070 <data_buildwonder@plt>
movl   $0x1,-0x4(%rbp)
jmp    1408 <player_build+0x218>
lea    0xc51(%rip),%rdi
call   10c0 <postmessage@plt>
jmp    13ed <player_build+0x1fd>
jmp    13f2 <player_build+0x202>
jmp    13f7 <player_build+0x207>
jmp    13fc <player_build+0x20c>
jmp    1401 <player_build+0x211>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<player_build>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %esi,%ebx
mov    %edi,%ebp
mov    %rsp,%rsi
mov    %edx,%edi
call   1030 <data_gethand@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <data_getera@plt>
movslq %ebx,%rbx
mov    (%rsp,%rbx,4),%edx
mov    %r12d,%edi
mov    %eax,%esi
call   10f0 <data_canafford@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1110 <data_numplayers@plt>
cmp    %ebp,%eax
jne    1349 <player_build+0x159>
cmpl   $0xffffffff,(%rsp,%rbx,4)
je     1349 <player_build+0x159>
mov    $0x3d,%edi
mov    %r15d,%esi
call   10e0 <postoptions@plt>
cmp    $0x2,%eax
je     128f <player_build+0x9f>
cmp    $0x1,%eax
je     12d5 <player_build+0xe5>
test   %eax,%eax
jne    1349 <player_build+0x159>
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <data_getera@plt>
mov    (%rsp,%rbx,4),%edx
mov    %r12d,%edi
mov    %eax,%esi
call   10a0 <data_hasbuiltname@plt>
test   %rax,%rax
je     12f5 <player_build+0x105>
lea    0xd76(%rip),%rdi
jmp    1344 <player_build+0x154>
mov    %r12d,%edi
call   1090 <data_getnextwonderstage@plt>
cmp    $0xffffffff,%eax
je     133d <player_build+0x14d>
mov    %r12d,%edi
call   1080 <data_getwonder@plt>
mov    %eax,%ebp
mov    %r12d,%edi
call   1090 <data_getnextwonderstage@plt>
mov    %r12d,%edi
mov    %ebp,%esi
mov    %eax,%edx
call   10f0 <data_canafford@plt>
test   %eax,%eax
je     1334 <player_build+0x144>
mov    (%rsp,%rbx,4),%esi
mov    %r12d,%edi
call   1070 <data_buildwonder@plt>
mov    $0x1,%r14d
jmp    1349 <player_build+0x159>
mov    (%rsp,%rbx,4),%esi
mov    %r12d,%edi
call   1050 <data_discard@plt>
mov    $0x3,%edi
mov    %r12d,%esi
call   1060 <data_addgold@plt>
mov    $0x1,%r14d
jmp    1349 <player_build+0x159>
cmp    $0x1,%r13d
je     135b <player_build+0x16b>
cmp    $0x2,%r13d
jne    1334 <player_build+0x144>
lea    0xd1a(%rip),%rdx
mov    $0x3d,%edi
mov    %r15d,%esi
call   10d0 <postyn@plt>
test   %rax,%rax
je     1334 <player_build+0x144>
mov    (%rsp,%rbx,4),%esi
mov    %r12d,%edi
call   10b0 <data_build@plt>
xor    %eax,%eax
call   1100 <data_spendfreebuild@plt>
mov    $0x1,%r14d
jmp    1349 <player_build+0x159>
lea    0xcf9(%rip),%rdi
jmp    1344 <player_build+0x154>
lea    0xd03(%rip),%rdi
call   10c0 <postmessage@plt>
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp,%rbx,4),%esi
mov    %r12d,%edi
call   10b0 <data_build@plt>
mov    $0x1,%r14d
jmp    1349 <player_build+0x159>

LLVM IR (-O0):
@.str = [34 x i8] c"Cannot have two of the same card!\00"
@.str.1 = [18 x i8] c"Spend free build?\00"
@.str.2 = [19 x i8] c"Can't afford this!\00"
@.str.3 = [25 x i8] c"Wonder already complete.\00"
define i32 @player_build(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [7 x i32]
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%13 = load i32, i32* %8
%14 = getelementptr inbounds [7 x i32], [7 x i32]* %10, i64 0, i64 0
%15 = call i32 @data_gethand(i32 %13, i32* %14)
%16 = load i32, i32* %8
%17 = call i32 (...) @data_getera()
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [7 x i32], [7 x i32]* %10, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @data_canafford(i32 %16, i32 %17, i32 %21)
store i32 %22, i32* %11
%23 = load i32, i32* %6
%24 = call i32 (...) @data_numplayers()
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %117
26: ; preds = %4
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [7 x i32], [7 x i32]* %10, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 0, i32* %5
br label %118
33: ; preds = %26
%34 = load i32, i32* %9
%35 = call i32 @postoptions(i32 61, i32 %34)
store i32 %35, i32* %12
%36 = load i32, i32* %12
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %74
38: ; preds = %33
%39 = load i32, i32* %8
%40 = call i32 (...) @data_getera()
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [7 x i32], [7 x i32]* %10, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = call i64 @data_hasbuiltname(i32 %39, i32 %40, i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %38
%48 = call i32 @postmessage(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %118
49: ; preds = %38
%50 = load i32, i32* %11
%51 = icmp eq i32 %50, 1
br i1 %51, label %59, label %52
52: ; preds = %49
%53 = load i32, i32* %11
%54 = icmp eq i32 %53, 2
br i1 %54, label %55, label %71
55: ; preds = %52
%56 = load i32, i32* %9
%57 = call i64 @postyn(i32 61, i32 %56, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %71
59: ; preds = %55, %49
%60 = load i32, i32* %8
%61 = load i32, i32* %7
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [7 x i32], [7 x i32]* %10, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = call i32 @data_build(i32 %60, i32 %64)
%66 = load i32, i32* %11
%67 = icmp eq i32 %66, 2
br i1 %67, label %68, label %70
68: ; preds = %59
%69 = call i32 (...) @data_spendfreebuild()
br label %70
70: ; preds = %68, %59
store i32 1, i32* %5
br label %118
71: ; preds = %55, %52
%72 = call i32 @postmessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %73
73: ; preds = %71
br label %116
74: ; preds = %33
%75 = load i32, i32* %12
%76 = icmp eq i32 %75, 1
br i1 %76, label %77, label %86
77: ; preds = %74
%78 = load i32, i32* %8
%79 = load i32, i32* %7
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [7 x i32], [7 x i32]* %10, i64 0, i64 %80
%82 = load i32, i32* %81
%83 = call i32 @data_discard(i32 %78, i32 %82)
%84 = load i32, i32* %8
%85 = call i32 @data_addgold(i32 3, i32 %84)
store i32 1, i32* %5
br label %118
86: ; preds = %74
%87 = load i32, i32* %12
%88 = icmp eq i32 %87, 2
br i1 %88, label %89, label %114
89: ; preds = %86
%90 = load i32, i32* %8
%91 = call i32 @data_getnextwonderstage(i32 %90)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %95
93: ; preds = %89
%94 = call i32 @postmessage(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %113
95: ; preds = %89
%96 = load i32, i32* %8
%97 = load i32, i32* %8
%98 = call i32 @data_getwonder(i32 %97)
%99 = load i32, i32* %8
%100 = call i32 @data_getnextwonderstage(i32 %99)
%101 = call i32 @data_canafford(i32 %96, i32 %98, i32 %100)
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %110
103: ; preds = %95
%104 = load i32, i32* %8
%105 = load i32, i32* %7
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [7 x i32], [7 x i32]* %10, i64 0, i64 %106
%108 = load i32, i32* %107
%109 = call i32 @data_buildwonder(i32 %104, i32 %108)
store i32 1, i32* %5
br label %118
110: ; preds = %95
%111 = call i32 @postmessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %112
112: ; preds = %110
br label %113
113: ; preds = %112, %93
br label %114
114: ; preds = %113, %86
br label %115
115: ; preds = %114
br label %116
116: ; preds = %115, %73
br label %117
117: ; preds = %116, %4
store i32 0, i32* %5
br label %118
118: ; preds = %117, %103, %77, %70, %47, %32
%119 = load i32, i32* %5
ret i32 %119
}

LLVM IR (-O2):
@.str = [34 x i8] c"Cannot have two of the same card!\00"
@.str.1 = [18 x i8] c"Spend free build?\00"
@.str.2 = [19 x i8] c"Can't afford this!\00"
@.str.3 = [25 x i8] c"Wonder already complete.\00"
define i32 @player_build(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [7 x i32]
%6 = bitcast [7 x i32]* %5 to i8*
%7 = getelementptr inbounds [7 x i32], [7 x i32]* %5, i64 0, i64 0
%8 = call i32 @data_gethand(i32 %2, i32* %7)
%9 = call i32 (...) @data_getera()
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds [7 x i32], [7 x i32]* %5, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = call i32 @data_canafford(i32 %2, i32 %9, i32 %12)
%14 = call i32 (...) @data_numplayers()
%15 = icmp eq i32 %14, %0
br i1 %15, label %16, label %60
16: ; preds = %4
%17 = load i32, i32* %11
%18 = icmp eq i32 %17, -1
br i1 %18, label %60, label %19
19: ; preds = %16
%20 = call i32 @postoptions(i32 61, i32 %3)
switch i32 %20, label %60 [
i32 0, label %21
i32 1, label %41
i32 2, label %45
]
21: ; preds = %19
%22 = call i32 (...) @data_getera()
%23 = load i32, i32* %11
%24 = call i64 @data_hasbuiltname(i32 %2, i32 %22, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = call i32 @postmessage(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %60
28: ; preds = %21
switch i32 %13, label %39 [
i32 1, label %32
i32 2, label %29
]
29: ; preds = %28
%30 = call i64 @postyn(i32 61, i32 %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %39, label %35
32: ; preds = %28
%33 = load i32, i32* %11
%34 = call i32 @data_build(i32 %2, i32 %33)
br label %60
35: ; preds = %29
%36 = load i32, i32* %11
%37 = call i32 @data_build(i32 %2, i32 %36)
%38 = call i32 (...) @data_spendfreebuild()
br label %60
39: ; preds = %28, %29
%40 = call i32 @postmessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %60
41: ; preds = %19
%42 = load i32, i32* %11
%43 = call i32 @data_discard(i32 %2, i32 %42)
%44 = call i32 @data_addgold(i32 3, i32 %2)
br label %60
45: ; preds = %19
%46 = call i32 @data_getnextwonderstage(i32 %2)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @postmessage(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %60
50: ; preds = %45
%51 = call i32 @data_getwonder(i32 %2)
%52 = call i32 @data_getnextwonderstage(i32 %2)
%53 = call i32 @data_canafford(i32 %2, i32 %51, i32 %52)
%54 = icmp eq i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %50
%56 = load i32, i32* %11
%57 = call i32 @data_buildwonder(i32 %2, i32 %56)
br label %60
58: ; preds = %50
%59 = call i32 @postmessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %60
60: ; preds = %32, %35, %26, %41, %55, %4, %39, %58, %48, %19, %16
%61 = phi i32 [ 0, %16 ], [ 0, %19 ], [ 0, %48 ], [ 0, %58 ], [ 0, %39 ], [ 0, %4 ], [ 1, %32 ], [ 1, %35 ], [ 0, %26 ], [ 1, %41 ], [ 1, %55 ]
ret i32 %61
}