#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_deletediscard(int, int);
int /*<<< orphan*/ data_freebuild(int, int, int);
int /*<<< orphan*/ data_getdiscards(int *);
int /*<<< orphan*/ data_hasbuiltname(int, int, int);
int data_numbuilt(int);
int data_numplayers();
int io_getkey();
int /*<<< orphan*/ posthelp();
int /*<<< orphan*/ postmessage(char *);
int /*<<< orphan*/ view_refresh(int, int, int, int);
int wonder_numstages(int);
void Halicarnassus(int player) {
  int focus = data_numplayers();
  int cursor = 0;
  int discards[150];
  data_getdiscards(discards);
  int numcards = 0;
  while (discards[numcards++] != -1 && numcards < 50)
    ;
  numcards /= 2;
  if (numcards == 0) {
    postmessage("No cards in the discard pile. Sucks to suck.");
    return;
  }
  while (1) {
    view_refresh(focus, cursor, player, 1);
    switch (io_getkey()) {
    case 2:
      cursor--;
      break;
    case 3:
      cursor++;
      break;
    case 1:
      focus++;
      cursor = 0;
      break;
    case 0:
      focus--;
      cursor = 0;
      break;
    case '\t':
      focus = (focus + 1) % (data_numplayers() + 1);
      cursor = 0;
      break;
    case 'h':
      posthelp();
      break;
    case 4:
      if (data_hasbuiltname(player, discards[cursor * 2],
                            discards[cursor * 2 + 1])) {
        postmessage("Cannot have two of the same card!");
      } else {
        data_freebuild(player, discards[cursor * 2], discards[cursor * 2 + 1]);
        data_deletediscard(discards[cursor * 2], discards[cursor * 2 + 1]);
        return;
      }
      break;
    default:
      break;
    }
    if (focus < 0)
      focus = data_numplayers();
    focus = focus % (data_numplayers() + 1);
    if (focus == data_numplayers()) {
      if (cursor < 0)
        cursor = numcards - 1;
      if (cursor >= numcards)
        cursor = 0;
    } else {
      if (cursor < 0)
        cursor = wonder_numstages((player + focus) % data_numplayers()) +
                 data_numbuilt(player + focus % data_numplayers()) - 1;
      cursor =
          cursor % (wonder_numstages((player + focus) % data_numplayers()) +
                    data_numbuilt(player + focus % data_numplayers()));
    }
  }
}


x86 assembly (clang, -O0):
<Halicarnassus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b0,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   10d0 <data_numplayers@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x270(%rbp),%rdi
call   1070 <data_getdiscards@plt>
movl   $0x0,-0x274(%rbp)
mov    -0x274(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x274(%rbp)
movslq %eax,%rcx
xor    %eax,%eax
cmpl   $0xffffffff,-0x270(%rbp,%rcx,4)
ff
mov    %al,-0x275(%rbp)
je     121f <Halicarnassus+0x6f>
cmpl   $0x32,-0x274(%rbp)
setl   %al
mov    %al,-0x275(%rbp)
mov    -0x275(%rbp),%al
test   $0x1,%al
jne    1232 <Halicarnassus+0x82>
jmp    1237 <Halicarnassus+0x87>
jmp    11e5 <Halicarnassus+0x35>
mov    -0x274(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x274(%rbp)
cmpl   $0x0,-0x274(%rbp)
jne    1269 <Halicarnassus+0xb9>
lea    0xda1(%rip),%rdi
call   10a0 <postmessage@plt>
jmp    15b4 <Halicarnassus+0x404>
jmp    126e <Halicarnassus+0xbe>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    $0x1,%ecx
call   10b0 <view_refresh@plt>
xor    %eax,%eax
call   1050 <io_getkey@plt>
mov    %eax,%ecx
mov    %ecx,-0x27c(%rbp)
test   %eax,%eax
je     1346 <Halicarnassus+0x196>
jmp    129d <Halicarnassus+0xed>
mov    -0x27c(%rbp),%eax
sub    $0x1,%eax
je     1331 <Halicarnassus+0x181>
jmp    12b1 <Halicarnassus+0x101>
mov    -0x27c(%rbp),%eax
sub    $0x2,%eax
je     1315 <Halicarnassus+0x165>
jmp    12c5 <Halicarnassus+0x115>
mov    -0x27c(%rbp),%eax
sub    $0x3,%eax
je     1323 <Halicarnassus+0x173>
jmp    12d9 <Halicarnassus+0x129>
mov    -0x27c(%rbp),%eax
sub    $0x4,%eax
je     1397 <Halicarnassus+0x1e7>
jmp    12ed <Halicarnassus+0x13d>
mov    -0x27c(%rbp),%eax
sub    $0x9,%eax
je     135b <Halicarnassus+0x1ab>
jmp    1301 <Halicarnassus+0x151>
mov    -0x27c(%rbp),%eax
sub    $0x68,%eax
je     138b <Halicarnassus+0x1db>
jmp    1433 <Halicarnassus+0x283>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1438 <Halicarnassus+0x288>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1438 <Halicarnassus+0x288>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
jmp    1438 <Halicarnassus+0x288>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
jmp    1438 <Halicarnassus+0x288>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x280(%rbp)
mov    $0x0,%al
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
mov    -0x280(%rbp),%eax
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
jmp    1438 <Halicarnassus+0x288>
mov    $0x0,%al
call   1060 <posthelp@plt>
jmp    1438 <Halicarnassus+0x288>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
cltq
mov    -0x270(%rbp,%rax,4),%esi
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cltq
mov    -0x270(%rbp,%rax,4),%edx
call   1080 <data_hasbuiltname@plt>
cmp    $0x0,%eax
je     13da <Halicarnassus+0x22a>
lea    0xc5d(%rip),%rdi
call   10a0 <postmessage@plt>
jmp    142e <Halicarnassus+0x27e>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
cltq
mov    -0x270(%rbp,%rax,4),%esi
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cltq
mov    -0x270(%rbp,%rax,4),%edx
call   10c0 <data_freebuild@plt>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
cltq
mov    -0x270(%rbp,%rax,4),%edi
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cltq
mov    -0x270(%rbp,%rax,4),%esi
call   1040 <data_deletediscard@plt>
jmp    15b4 <Halicarnassus+0x404>
jmp    1438 <Halicarnassus+0x288>
jmp    1438 <Halicarnassus+0x288>
cmpl   $0x0,-0x8(%rbp)
jge    144c <Halicarnassus+0x29c>
mov    $0x0,%al
call   10d0 <data_numplayers@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x288(%rbp)
mov    $0x0,%al
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
mov    -0x288(%rbp),%eax
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x284(%rbp)
mov    $0x0,%al
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
mov    -0x284(%rbp),%eax
cmp    %ecx,%eax
jne    14be <Halicarnassus+0x30e>
cmpl   $0x0,-0xc(%rbp)
jge    14a3 <Halicarnassus+0x2f3>
mov    -0x274(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x274(%rbp),%eax
jl     14b9 <Halicarnassus+0x309>
movl   $0x0,-0xc(%rbp)
jmp    15af <Halicarnassus+0x3ff>
cmpl   $0x0,-0xc(%rbp)
jge    1534 <Halicarnassus+0x384>
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x298(%rbp)
mov    $0x0,%al
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
mov    -0x298(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <wonder_numstages@plt>
mov    %eax,-0x28c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x294(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x290(%rbp)
mov    $0x0,%al
call   10d0 <data_numplayers@plt>
mov    -0x294(%rbp),%edi
mov    %eax,%ecx
mov    -0x290(%rbp),%eax
cltd
idiv   %ecx
add    %edx,%edi
call   1090 <data_numbuilt@plt>
mov    %eax,%ecx
mov    -0x28c(%rbp),%eax
add    %ecx,%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x29c(%rbp)
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x2ac(%rbp)
mov    $0x0,%al
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
mov    -0x2ac(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <wonder_numstages@plt>
mov    %eax,-0x2a0(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2a8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x2a4(%rbp)
mov    $0x0,%al
call   10d0 <data_numplayers@plt>
mov    -0x2a8(%rbp),%edi
mov    %eax,%ecx
mov    -0x2a4(%rbp),%eax
cltd
idiv   %ecx
add    %edx,%edi
call   1090 <data_numbuilt@plt>
mov    -0x2a0(%rbp),%ecx
mov    %eax,%edx
mov    -0x29c(%rbp),%eax
add    %edx,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
jmp    126e <Halicarnassus+0xbe>
add    $0x2b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Halicarnassus>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x268,%rsp
mov    %edi,%r15d
xor    %ebx,%ebx
xor    %eax,%eax
call   10d0 <data_numplayers@plt>
mov    %eax,%r12d
lea    0x10(%rsp),%rdi
call   1070 <data_getdiscards@plt>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r13
cmpl   $0xffffffff,0x10(%rsp,%rbx,4)
je     11f4 <Halicarnassus+0x44>
cmp    $0x31,%rbx
mov    %r13,%rbx
jb     11e0 <Halicarnassus+0x30>
cmp    $0x1,%r13d
jne    120b <Halicarnassus+0x5b>
lea    0xe27(%rip),%rdi
call   10a0 <postmessage@plt>
jmp    13d7 <Halicarnassus+0x227>
shr    %r13d
lea    -0x1(%r13),%r14d
xor    %ebx,%ebx
mov    %r13,0x8(%rsp)
jmp    1231 <Halicarnassus+0x81>
nopl   0x0(%rax,%rax,1)
test   %ebx,%ebx
cmovs  %r14d,%ebx
cmp    %r13d,%ebx
mov    $0x0,%eax
cmovge %eax,%ebx
mov    %r12d,%edi
mov    %ebx,%esi
mov    %r15d,%edx
mov    $0x1,%ecx
call   10b0 <view_refresh@plt>
xor    %eax,%eax
call   1050 <io_getkey@plt>
cmp    $0x9,%eax
ja     1267 <Halicarnassus+0xb7>
mov    %eax,%eax
lea    0xda8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
add    $0xffffffff,%r12d
jmp    127e <Halicarnassus+0xce>
cmp    $0x68,%eax
jne    12c0 <Halicarnassus+0x110>
xor    %eax,%eax
call   1060 <posthelp@plt>
test   %r12d,%r12d
jns    12cf <Halicarnassus+0x11f>
jmp    12c5 <Halicarnassus+0x115>
add    $0x1,%r12d
xor    %ebx,%ebx
test   %r12d,%r12d
jns    12cf <Halicarnassus+0x11f>
jmp    12c5 <Halicarnassus+0x115>
add    $0xffffffff,%ebx
test   %r12d,%r12d
jns    12cf <Halicarnassus+0x11f>
jmp    12c5 <Halicarnassus+0x115>
add    $0x1,%ebx
test   %r12d,%r12d
jns    12cf <Halicarnassus+0x11f>
jmp    12c5 <Halicarnassus+0x115>
add    $0x1,%r12d
xor    %ebx,%ebx
xor    %eax,%eax
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    %r12d,%eax
cltd
idiv   %ecx
mov    %edx,%r12d
cs nopw 0x0(%rax,%rax,1)
test   %r12d,%r12d
jns    12cf <Halicarnassus+0x11f>
xor    %eax,%eax
call   10d0 <data_numplayers@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    %r12d,%eax
cltd
idiv   %ecx
mov    %edx,%r12d
xor    %eax,%eax
call   10d0 <data_numplayers@plt>
cmp    %eax,%r12d
je     1220 <Halicarnassus+0x70>
mov    %r12d,%ebp
add    %r15d,%ebp
test   %ebx,%ebx
jns    1332 <Halicarnassus+0x182>
xor    %eax,%eax
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <wonder_numstages@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
mov    %r12d,%eax
cltd
idiv   %ecx
lea    (%rdx,%r15,1),%edi
call   1090 <data_numbuilt@plt>
add    %eax,%ebx
add    $0xffffffff,%ebx
xor    %eax,%eax
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <wonder_numstages@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   10d0 <data_numplayers@plt>
mov    %eax,%ecx
mov    %r12d,%eax
cltd
idiv   %ecx
lea    (%rdx,%r15,1),%edi
call   1090 <data_numbuilt@plt>
mov    %eax,%ecx
add    %ebp,%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
mov    %edx,%ebx
jmp    1231 <Halicarnassus+0x81>
mov    %r15,%rdi
mov    %r14d,%r13d
lea    (%rbx,%rbx,1),%eax
movslq %eax,%rbp
mov    0x10(%rsp,%rbp,4),%esi
lea    0x1(%rbx,%rbx,1),%eax
movslq %eax,%r14
mov    0x10(%rsp,%r14,4),%edx
call   1080 <data_hasbuiltname@plt>
test   %eax,%eax
je     13b8 <Halicarnassus+0x208>
lea    0xcb8(%rip),%rdi
call   10a0 <postmessage@plt>
mov    %r13d,%r14d
mov    0x8(%rsp),%r13
test   %r12d,%r12d
jns    12cf <Halicarnassus+0x11f>
jmp    12c5 <Halicarnassus+0x115>
mov    0x10(%rsp,%rbp,4),%esi
mov    0x10(%rsp,%r14,4),%edx
mov    %r15d,%edi
call   10c0 <data_freebuild@plt>
mov    0x10(%rsp,%rbp,4),%edi
mov    0x10(%rsp,%r14,4),%esi
call   1040 <data_deletediscard@plt>
add    $0x268,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"No cards in the discard pile. Sucks to suck.\00"
@.str.1 = [34 x i8] c"Cannot have two of the same card!\00"
define void @Halicarnassus(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [150 x i32]
%6 = alloca i32
store i32 %0, i32* %2
%7 = call i32 (...) @data_numplayers()
store i32 %7, i32* %3
store i32 0, i32* %4
%8 = getelementptr inbounds [150 x i32], [150 x i32]* %5, i64 0, i64 0
%9 = call i32 @data_getdiscards(i32* %8)
store i32 0, i32* %6
br label %10
10: ; preds = %22, %1
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 1
store i32 %12, i32* %6
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds [150 x i32], [150 x i32]* %5, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 50
br label %20
20: ; preds = %17, %10
%21 = phi i1 [ false, %10 ], [ %19, %17 ]
br i1 %21, label %22, label %23
22: ; preds = %20
br label %10
23: ; preds = %20
%24 = load i32, i32* %6
%25 = sdiv i32 %24, 2
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @postmessage(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %162
30: ; preds = %23
br label %31
31: ; preds = %30, %161
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = load i32, i32* %2
%35 = call i32 @view_refresh(i32 %32, i32 %33, i32 %34, i32 1)
%36 = call i32 (...) @io_getkey()
switch i32 %36, label %101 [
i32 2, label %37
i32 3, label %40
i32 1, label %43
i32 0, label %46
i32 9, label %49
i32 104, label %55
i32 4, label %57
]
37: ; preds = %31
%38 = load i32, i32* %4
%39 = add nsw i32 %38, -1
store i32 %39, i32* %4
br label %102
40: ; preds = %31
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %102
43: ; preds = %31
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
store i32 0, i32* %4
br label %102
46: ; preds = %31
%47 = load i32, i32* %3
%48 = add nsw i32 %47, -1
store i32 %48, i32* %3
store i32 0, i32* %4
br label %102
49: ; preds = %31
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
%52 = call i32 (...) @data_numplayers()
%53 = add nsw i32 %52, 1
%54 = srem i32 %51, %53
store i32 %54, i32* %3
store i32 0, i32* %4
br label %102
55: ; preds = %31
%56 = call i32 (...) @posthelp()
br label %102
57: ; preds = %31
%58 = load i32, i32* %2
%59 = load i32, i32* %4
%60 = mul nsw i32 %59, 2
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [150 x i32], [150 x i32]* %5, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = load i32, i32* %4
%65 = mul nsw i32 %64, 2
%66 = add nsw i32 %65, 1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [150 x i32], [150 x i32]* %5, i64 0, i64 %67
%69 = load i32, i32* %68
%70 = call i32 @data_hasbuiltname(i32 %58, i32 %63, i32 %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %57
%73 = call i32 @postmessage(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %100
74: ; preds = %57
%75 = load i32, i32* %2
%76 = load i32, i32* %4
%77 = mul nsw i32 %76, 2
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [150 x i32], [150 x i32]* %5, i64 0, i64 %78
%80 = load i32, i32* %79
%81 = load i32, i32* %4
%82 = mul nsw i32 %81, 2
%83 = add nsw i32 %82, 1
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [150 x i32], [150 x i32]* %5, i64 0, i64 %84
%86 = load i32, i32* %85
%87 = call i32 @data_freebuild(i32 %75, i32 %80, i32 %86)
%88 = load i32, i32* %4
%89 = mul nsw i32 %88, 2
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [150 x i32], [150 x i32]* %5, i64 0, i64 %90
%92 = load i32, i32* %91
%93 = load i32, i32* %4
%94 = mul nsw i32 %93, 2
%95 = add nsw i32 %94, 1
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [150 x i32], [150 x i32]* %5, i64 0, i64 %96
%98 = load i32, i32* %97
%99 = call i32 @data_deletediscard(i32 %92, i32 %98)
br label %162
100: ; preds = %72
br label %102
101: ; preds = %31
br label %102
102: ; preds = %101, %100, %55, %49, %46, %43, %40, %37
%103 = load i32, i32* %3
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %107
105: ; preds = %102
%106 = call i32 (...) @data_numplayers()
store i32 %106, i32* %3
br label %107
107: ; preds = %105, %102
%108 = load i32, i32* %3
%109 = call i32 (...) @data_numplayers()
%110 = add nsw i32 %109, 1
%111 = srem i32 %108, %110
store i32 %111, i32* %3
%112 = load i32, i32* %3
%113 = call i32 (...) @data_numplayers()
%114 = icmp eq i32 %112, %113
br i1 %114, label %115, label %127
115: ; preds = %107
%116 = load i32, i32* %4
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %121
118: ; preds = %115
%119 = load i32, i32* %6
%120 = sub nsw i32 %119, 1
store i32 %120, i32* %4
br label %121
121: ; preds = %118, %115
%122 = load i32, i32* %4
%123 = load i32, i32* %6
%124 = icmp sge i32 %122, %123
br i1 %124, label %125, label %126
125: ; preds = %121
store i32 0, i32* %4
br label %126
126: ; preds = %125, %121
br label %161
127: ; preds = %107
%128 = load i32, i32* %4
%129 = icmp slt i32 %128, 0
br i1 %129, label %130, label %145
130: ; preds = %127
%131 = load i32, i32* %2
%132 = load i32, i32* %3
%133 = add nsw i32 %131, %132
%134 = call i32 (...) @data_numplayers()
%135 = srem i32 %133, %134
%136 = call i32 @wonder_numstages(i32 %135)
%137 = load i32, i32* %2
%138 = load i32, i32* %3
%139 = call i32 (...) @data_numplayers()
%140 = srem i32 %138, %139
%141 = add nsw i32 %137, %140
%142 = call i32 @data_numbuilt(i32 %141)
%143 = add nsw i32 %136, %142
%144 = sub nsw i32 %143, 1
store i32 %144, i32* %4
br label %145
145: ; preds = %130, %127
%146 = load i32, i32* %4
%147 = load i32, i32* %2
%148 = load i32, i32* %3
%149 = add nsw i32 %147, %148
%150 = call i32 (...) @data_numplayers()
%151 = srem i32 %149, %150
%152 = call i32 @wonder_numstages(i32 %151)
%153 = load i32, i32* %2
%154 = load i32, i32* %3
%155 = call i32 (...) @data_numplayers()
%156 = srem i32 %154, %155
%157 = add nsw i32 %153, %156
%158 = call i32 @data_numbuilt(i32 %157)
%159 = add nsw i32 %152, %158
%160 = srem i32 %146, %159
store i32 %160, i32* %4
br label %161
161: ; preds = %145, %126
br label %31
162: ; preds = %74, %28
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"No cards in the discard pile. Sucks to suck.\00"
@.str.1 = [34 x i8] c"Cannot have two of the same card!\00"
define void @Halicarnassus(i32 %0) {
%2 = alloca [150 x i32]
%3 = tail call i32 (...) @data_numplayers()
%4 = bitcast [150 x i32]* %2 to i8*
%5 = getelementptr inbounds [150 x i32], [150 x i32]* %2, i64 0, i64 0
%6 = call i32 @data_getdiscards(i32* %5)
br label %7
7: ; preds = %7, %1
%8 = phi i64 [ %9, %7 ], [ 0, %1 ]
%9 = add nuw nsw i64 %8, 1
%10 = getelementptr inbounds [150 x i32], [150 x i32]* %2, i64 0, i64 %8
%11 = load i32, i32* %10
%12 = icmp ne i32 %11, -1
%13 = icmp ult i64 %8, 49
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %7, label %15
15: ; preds = %7
%16 = trunc i64 %8 to i32
%17 = trunc i64 %9 to i32
%18 = lshr i32 %17, 1
%19 = icmp eq i32 %16, 0
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = add nsw i32 %18, -1
br label %24
22: ; preds = %15
%23 = call i32 @postmessage(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %109
24: ; preds = %84, %20
%25 = phi i32 [ %3, %20 ], [ %76, %84 ]
%26 = phi i32 [ 0, %20 ], [ %85, %84 ]
%27 = call i32 @view_refresh(i32 %25, i32 %26, i32 %0, i32 1)
%28 = call i32 (...) @io_getkey()
switch i32 %28, label %66 [
i32 2, label %29
i32 3, label %31
i32 1, label %33
i32 0, label %35
i32 9, label %37
i32 104, label %42
i32 4, label %44
]
29: ; preds = %24
%30 = add nsw i32 %26, -1
br label %66
31: ; preds = %24
%32 = add nsw i32 %26, 1
br label %66
33: ; preds = %24
%34 = add nsw i32 %25, 1
br label %66
35: ; preds = %24
%36 = add nsw i32 %25, -1
br label %66
37: ; preds = %24
%38 = add nsw i32 %25, 1
%39 = call i32 (...) @data_numplayers()
%40 = add nsw i32 %39, 1
%41 = srem i32 %38, %40
br label %66
42: ; preds = %24
%43 = call i32 (...) @posthelp()
br label %66
44: ; preds = %24
%45 = shl nsw i32 %26, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [150 x i32], [150 x i32]* %2, i64 0, i64 %46
%48 = load i32, i32* %47
%49 = or i32 %45, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [150 x i32], [150 x i32]* %2, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = call i32 @data_hasbuiltname(i32 %0, i32 %48, i32 %52)
%54 = icmp eq i32 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %44
%56 = call i32 @postmessage(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %66
57: ; preds = %44
%58 = getelementptr inbounds [150 x i32], [150 x i32]* %2, i64 0, i64 %46
%59 = getelementptr inbounds [150 x i32], [150 x i32]* %2, i64 0, i64 %50
%60 = load i32, i32* %58
%61 = load i32, i32* %59
%62 = call i32 @data_freebuild(i32 %0, i32 %60, i32 %61)
%63 = load i32, i32* %58
%64 = load i32, i32* %59
%65 = call i32 @data_deletediscard(i32 %63, i32 %64)
br label %109
66: ; preds = %24, %55, %42, %37, %35, %33, %31, %29
%67 = phi i32 [ %25, %24 ], [ %25, %55 ], [ %25, %42 ], [ %41, %37 ], [ %36, %35 ], [ %34, %33 ], [ %25, %31 ], [ %25, %29 ]
%68 = phi i32 [ %26, %24 ], [ %26, %55 ], [ %26, %42 ], [ 0, %37 ], [ 0, %35 ], [ 0, %33 ], [ %32, %31 ], [ %30, %29 ]
%69 = icmp slt i32 %67, 0
br i1 %69, label %70, label %72
70: ; preds = %66
%71 = call i32 (...) @data_numplayers()
br label %72
72: ; preds = %70, %66
%73 = phi i32 [ %71, %70 ], [ %67, %66 ]
%74 = call i32 (...) @data_numplayers()
%75 = add nsw i32 %74, 1
%76 = srem i32 %73, %75
%77 = call i32 (...) @data_numplayers()
%78 = icmp eq i32 %76, %77
%79 = icmp slt i32 %68, 0
br i1 %78, label %80, label %86
80: ; preds = %72
%81 = select i1 %79, i32 %21, i32 %68
%82 = icmp slt i32 %81, %18
%83 = select i1 %82, i32 %81, i32 0
br label %84
84: ; preds = %80, %98
%85 = phi i32 [ %83, %80 ], [ %108, %98 ]
br label %24
86: ; preds = %72
%87 = add nsw i32 %76, %0
br i1 %79, label %88, label %98
88: ; preds = %86
%89 = call i32 (...) @data_numplayers()
%90 = srem i32 %87, %89
%91 = call i32 @wonder_numstages(i32 %90)
%92 = call i32 (...) @data_numplayers()
%93 = srem i32 %76, %92
%94 = add nsw i32 %93, %0
%95 = call i32 @data_numbuilt(i32 %94)
%96 = add i32 %91, -1
%97 = add i32 %96, %95
br label %98
98: ; preds = %86, %88
%99 = phi i32 [ %97, %88 ], [ %68, %86 ]
%100 = call i32 (...) @data_numplayers()
%101 = srem i32 %87, %100
%102 = call i32 @wonder_numstages(i32 %101)
%103 = call i32 (...) @data_numplayers()
%104 = srem i32 %76, %103
%105 = add nsw i32 %104, %0
%106 = call i32 @data_numbuilt(i32 %105)
%107 = add nsw i32 %106, %102
%108 = srem i32 %99, %107
br label %84
109: ; preds = %57, %22
ret void
}