#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__ gemcount(int *);
int /*<<< orphan*/ gemoffer(int *, int *, int *, int *, int *, int *, int *,
                            int *, int *, int *, int *, int *);
int /*<<< orphan*/ getint(int *);
int /*<<< orphan*/ goodsoffer(int *, int *, int *, int *, int *, int *, int *,
                              int *, int *, int *, int *, int *);
int illusion(int *, int *);
int magiccount(int *, int *);
int /*<<< orphan*/ nameitem(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stealingspirit(int *, int *, int *, int *, int *, int *,
                                  int *, int *, int *, int *, int *, int *,
                                  int *, int *, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ treasure(int *, int *, int *, int *, int *, int *, int *,
                            int *, int *, int *, int *, int *,
                            int /*<<< orphan*/, int, int /*<<< orphan*/);
scalar_t__ valueinv(int *, int *);
scalar_t__ valueitem(int);
void exchange(int *hpmax, int *hpnow, int *aces, int *inv, int *slave,
              int *future, int *map, int *loot, int *vision, int *end, int *pos,
              int *floor, int *start, int *antimag, int type) {
  char s[20];
  int i;
  nameitem(s, *(loot + *pos));
  if (*(aces + 1) == 1) {
    printf("You put out enough gems from your bag of Meres and buy the %s.\n",
           s);
    treasure(hpmax, hpnow, aces, inv, slave, future, map, loot, vision, end,
             pos, antimag, 0, 1, 0);
    return;
  }
  if ((type == 1) && (magiccount(aces, inv) > 3)) {
    printf("Do you want to use an Illusion spell?\n[0]: No\n[1]: Yes\n");
    getint(&i);
    if (i == 1)
      i = illusion(aces, inv);
    if (i == 1) {
      printf("You give nothing to the adventurer, but you receive the "
             "treasure!\n");
      treasure(hpmax, hpnow, aces, inv, slave, future, map, loot, vision, end,
               pos, antimag, 0, 1, 0);
    }
  }
  if (magiccount(aces, inv) > 5) {
    printf("Do you want to use a StealingSpirit spell?\n[0]: No\n[1]: Yes\n");
    getint(&i);
    if (i == 1) {
      stealingspirit(hpmax, hpnow, aces, inv, slave, future, map, loot, vision,
                     end, pos, floor, start, antimag, NULL, NULL, NULL);
      if (type == 0) {
        printf("The merchant disappears!\n");
      }
    }
  }
  if (valueitem(*(loot + *pos)) > valueinv(inv, slave)) {
    printf("'You don't have enough goods to trade!'\n");
    *(loot + *pos) = -1;
    *(vision + *pos) = 2;
    return;
  }
  if ((type == 1) && (valueitem(*(loot + *pos)) > gemcount(inv))) {
    printf("'You don't have enough gems to trade!'\n");
    *(loot + *pos) = -1;
    *(vision + *pos) = 2;
    return;
  }
  if (type == 0) {
    goodsoffer(hpmax, hpnow, aces, inv, slave, future, map, loot, vision, end,
               pos, antimag);
    return;
  }
  gemoffer(hpmax, hpnow, aces, inv, slave, future, map, loot, vision, end, pos,
           antimag);
}


x86 assembly (clang, -O0):
<exchange>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    0x50(%rbp),%eax
mov    0x48(%rbp),%rax
mov    0x40(%rbp),%rax
mov    0x38(%rbp),%rax
mov    0x30(%rbp),%rax
mov    0x28(%rbp),%rax
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rcx,-0x48(%rbp)
mov    %r8,-0x50(%rbp)
mov    %r9,-0x58(%rbp)
lea    -0x70(%rbp),%rdi
mov    0x18(%rbp),%rax
mov    0x30(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,4),%esi
call   10a0 <nameitem@plt>
mov    -0x40(%rbp),%rax
cmpl   $0x1,0x4(%rax)
jne    12b8 <exchange+0xf8>
lea    -0x70(%rbp),%rsi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    -0x58(%rbp),%r9
mov    0x10(%rbp),%r15
mov    0x18(%rbp),%r14
mov    0x20(%rbp),%rbx
mov    0x28(%rbp),%r11
mov    0x30(%rbp),%r10
mov    0x48(%rbp),%rax
xor    %r12d,%r12d
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
movl   $0x0,0x30(%rsp)
movl   $0x1,0x38(%rsp)
movl   $0x0,0x40(%rsp)
call   1030 <treasure@plt>
jmp    1610 <exchange+0x450>
cmpl   $0x1,0x50(%rbp)
jne    1393 <exchange+0x1d3>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1070 <magiccount@plt>
cmp    $0x3,%eax
jle    1393 <exchange+0x1d3>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x74(%rbp),%rdi
call   1060 <getint@plt>
cmpl   $0x1,-0x74(%rbp)
jne    1309 <exchange+0x149>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10c0 <illusion@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x1,-0x74(%rbp)
jne    138e <exchange+0x1ce>
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    -0x58(%rbp),%r9
mov    0x10(%rbp),%r15
mov    0x18(%rbp),%r14
mov    0x20(%rbp),%rbx
mov    0x28(%rbp),%r11
mov    0x30(%rbp),%r10
mov    0x48(%rbp),%rax
xor    %r12d,%r12d
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
movl   $0x0,0x30(%rsp)
movl   $0x1,0x38(%rsp)
movl   $0x0,0x40(%rsp)
call   1030 <treasure@plt>
jmp    1393 <exchange+0x1d3>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1070 <magiccount@plt>
cmp    $0x5,%eax
jle    1475 <exchange+0x2b5>
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x74(%rbp),%rdi
call   1060 <getint@plt>
cmpl   $0x1,-0x74(%rbp)
jne    1470 <exchange+0x2b0>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    -0x58(%rbp),%r9
mov    0x10(%rbp),%r13
mov    0x18(%rbp),%r12
mov    0x20(%rbp),%r15
mov    0x28(%rbp),%r14
mov    0x30(%rbp),%rbx
mov    0x38(%rbp),%r11
mov    0x40(%rbp),%r10
mov    0x48(%rbp),%rax
mov    %rax,-0x80(%rbp)
xor    %eax,%eax
mov    -0x80(%rbp),%rax
mov    %r13,(%rsp)
mov    %r12,0x8(%rsp)
mov    %r15,0x10(%rsp)
mov    %r14,0x18(%rsp)
mov    %rbx,0x20(%rsp)
mov    %r11,0x28(%rsp)
mov    %r10,0x30(%rsp)
mov    %rax,0x38(%rsp)
movq   $0x0,0x40(%rsp)
movq   $0x0,0x48(%rsp)
movq   $0x0,0x50(%rsp)
call   10e0 <stealingspirit@plt>
cmpl   $0x0,0x50(%rbp)
jne    146b <exchange+0x2ab>
lea    0xc94(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1470 <exchange+0x2b0>
jmp    1475 <exchange+0x2b5>
mov    0x18(%rbp),%rax
mov    0x30(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,4),%edi
call   10d0 <valueitem@plt>
mov    %rax,-0x88(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   1040 <valueinv@plt>
mov    %rax,%rcx
mov    -0x88(%rbp),%rax
cmp    %rcx,%rax
jle    14e6 <exchange+0x326>
lea    0xc5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x18(%rbp),%rax
mov    0x30(%rbp),%rcx
movslq (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x20(%rbp),%rax
mov    0x30(%rbp),%rcx
movslq (%rcx),%rcx
movl   $0x2,(%rax,%rcx,4)
jmp    1610 <exchange+0x450>
cmpl   $0x1,0x50(%rbp)
jne    155d <exchange+0x39d>
mov    0x18(%rbp),%rax
mov    0x30(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,4),%edi
call   10d0 <valueitem@plt>
mov    %rax,-0x90(%rbp)
mov    -0x48(%rbp),%rdi
call   1080 <gemcount@plt>
mov    %rax,%rcx
mov    -0x90(%rbp),%rax
cmp    %rcx,%rax
jle    155d <exchange+0x39d>
lea    0xc0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x18(%rbp),%rax
mov    0x30(%rbp),%rcx
movslq (%rcx),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    0x20(%rbp),%rax
mov    0x30(%rbp),%rcx
movslq (%rcx),%rcx
movl   $0x2,(%rax,%rcx,4)
jmp    1610 <exchange+0x450>
cmpl   $0x0,0x50(%rbp)
jne    15be <exchange+0x3fe>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    -0x58(%rbp),%r9
mov    0x10(%rbp),%r15
mov    0x18(%rbp),%r14
mov    0x20(%rbp),%rbx
mov    0x28(%rbp),%r11
mov    0x30(%rbp),%r10
mov    0x48(%rbp),%rax
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1090 <goodsoffer@plt>
jmp    1610 <exchange+0x450>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x48(%rbp),%rcx
mov    -0x50(%rbp),%r8
mov    -0x58(%rbp),%r9
mov    0x10(%rbp),%r15
mov    0x18(%rbp),%r14
mov    0x20(%rbp),%rbx
mov    0x28(%rbp),%r11
mov    0x30(%rbp),%r10
mov    0x48(%rbp),%rax
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   10b0 <gemoffer@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<exchange>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,%r13
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rbp
mov    0x90(%rsp),%rax
mov    0x78(%rsp),%rcx
movslq (%rax),%rax
mov    (%rcx,%rax,4),%esi
lea    0x20(%rsp),%rdi
call   10b0 <nameitem@plt>
cmpl   $0x1,0x4(%rbx)
jne    127a <exchange+0xaa>
lea    0xde6(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
sub    $0x8,%rsp
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r14,%r8
mov    %r13,%r9
push   $0x0
push   $0x1
push   $0x0
push   0xc8(%rsp)
push   0xb8(%rsp)
push   0xb8(%rsp)
push   0xb8(%rsp)
push   0xb8(%rsp)
push   0xb8(%rsp)
call   1030 <treasure@plt>
add    $0x50,%rsp
jmp    1551 <exchange+0x381>
mov    %rbp,0x8(%rsp)
mov    %r15,0x10(%rsp)
mov    %r13,0x18(%rsp)
cmpl   $0x1,0xb0(%rsp)
01
mov    %r14,%r15
mov    0x78(%rsp),%rbp
mov    0x80(%rsp),%r14
mov    0x88(%rsp),%r13
jne    1345 <exchange+0x175>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <magiccount@plt>
cmp    $0x4,%eax
jl     1345 <exchange+0x175>
lea    0xe1a(%rip),%rdi
call   1040 <puts@plt>
lea    0x4(%rsp),%rdi
call   1070 <getint@plt>
cmpl   $0x1,0x4(%rsp)
jne    1345 <exchange+0x175>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10d0 <illusion@plt>
mov    %eax,0x4(%rsp)
cmp    $0x1,%eax
jne    1345 <exchange+0x175>
lea    0xe20(%rip),%rdi
call   1040 <puts@plt>
sub    $0x8,%rsp
mov    0x10(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    0x20(%rsp),%r9
push   $0x0
push   $0x1
push   $0x0
push   0xc8(%rsp)
push   0xb8(%rsp)
push   %r13
push   %r14
push   %rbp
push   0xb8(%rsp)
call   1030 <treasure@plt>
add    $0x50,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <magiccount@plt>
cmp    $0x6,%eax
jl     1415 <exchange+0x245>
lea    0xd2f(%rip),%rdi
call   1040 <puts@plt>
lea    0x4(%rsp),%rdi
call   1070 <getint@plt>
cmpl   $0x1,0x4(%rsp)
jne    1415 <exchange+0x245>
mov    0xa0(%rsp),%rax
mov    0x98(%rsp),%rcx
sub    $0x60,%rsp
xorps  %xmm0,%xmm0
movups %xmm0,0x40(%rsp)
mov    0x108(%rsp),%rdx
mov    %rdx,0x38(%rsp)
mov    %rax,0x30(%rsp)
mov    %rcx,0x28(%rsp)
mov    0xf0(%rsp),%rax
mov    %rax,0x20(%rsp)
mov    %r13,0x18(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbp,0x8(%rsp)
mov    0xd0(%rsp),%rax
mov    %rax,(%rsp)
movq   $0x0,0x50(%rsp)
mov    0x68(%rsp),%rdi
mov    0x70(%rsp),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
mov    0x78(%rsp),%r9
call   10f0 <stealingspirit@plt>
add    $0x60,%rsp
cmpl   $0x0,0xb0(%rsp)
jne    1415 <exchange+0x245>
lea    0xcbb(%rip),%rdi
call   1040 <puts@plt>
mov    0x90(%rsp),%r13
movslq 0x0(%r13),%rax
mov    0x0(%rbp,%rax,4),%edi
call   10e0 <valueitem@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <valueinv@plt>
cmp    %rax,%r14
jle    145b <exchange+0x28b>
lea    0xc23(%rip),%rdi
call   1040 <puts@plt>
movslq 0x0(%r13),%rax
movl   $0xffffffff,0x0(%rbp,%rax,4)
ff
movslq 0x0(%r13),%rax
jmp    14cd <exchange+0x2fd>
mov    0xb0(%rsp),%eax
cmp    $0x1,%eax
jne    14de <exchange+0x30e>
mov    0x90(%rsp),%r14
movslq (%r14),%rax
mov    %rbp,%r13
mov    0x0(%rbp,%rax,4),%edi
call   10e0 <valueitem@plt>
mov    %rax,%rbp
mov    %r12,%rdi
call   1090 <gemcount@plt>
cmp    %rax,%rbp
mov    0x70(%rsp),%r10
mov    0x88(%rsp),%rbp
mov    0xa8(%rsp),%rax
mov    0x18(%rsp),%r9
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
jle    1511 <exchange+0x341>
lea    0xb87(%rip),%rdi
call   1040 <puts@plt>
movslq (%r14),%rax
movl   $0xffffffff,0x0(%r13,%rax,4)
ff ff
movslq (%r14),%rax
mov    0x80(%rsp),%rcx
movl   $0x2,(%rcx,%rax,4)
jmp    1551 <exchange+0x381>
test   %eax,%eax
mov    %rbp,%r13
mov    0x70(%rsp),%r10
mov    0x90(%rsp),%r14
mov    0x88(%rsp),%rbp
mov    0xa8(%rsp),%rax
mov    0x18(%rsp),%r9
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
je     1530 <exchange+0x360>
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
push   %rax
push   %r14
push   %rbp
push   0x98(%rsp)
push   %r13
push   %r10
call   10c0 <gemoffer@plt>
jmp    154d <exchange+0x37d>
mov    %rbx,%rdx
mov    %r12,%rcx
mov    %r15,%r8
push   %rax
push   %r14
push   %rbp
push   0x98(%rsp)
push   %r13
push   %r10
call   10a0 <goodsoffer@plt>
add    $0x30,%rsp
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [64 x i8] c"You put out enough gems from your bag of Meres and buy the %s.\0A\00"
@.str.1 = [56 x i8] c"Do you want to use an Illusion spell?\0A[0]: No\0A[1]: Yes\0A\00"
@.str.2 = [67 x i8] c"You give nothing to the adventurer, but you receive the treasure!\0A\00"
@.str.3 = [61 x i8] c"Do you want to use a StealingSpirit spell?\0A[0]: No\0A[1]: Yes\0A\00"
@.str.4 = [26 x i8] c"The merchant disappears!\0A\00"
@.str.5 = [41 x i8] c"'You don't have enough goods to trade!'\0A\00"
@.str.6 = [40 x i8] c"'You don't have enough gems to trade!'\0A\00"
define void @exchange(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32 %14) {
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32*
%19 = alloca i32*
%20 = alloca i32*
%21 = alloca i32*
%22 = alloca i32*
%23 = alloca i32*
%24 = alloca i32*
%25 = alloca i32*
%26 = alloca i32*
%27 = alloca i32*
%28 = alloca i32*
%29 = alloca i32*
%30 = alloca i32
%31 = alloca [20 x i8]
%32 = alloca i32
store i32* %0, i32** %16
store i32* %1, i32** %17
store i32* %2, i32** %18
store i32* %3, i32** %19
store i32* %4, i32** %20
store i32* %5, i32** %21
store i32* %6, i32** %22
store i32* %7, i32** %23
store i32* %8, i32** %24
store i32* %9, i32** %25
store i32* %10, i32** %26
store i32* %11, i32** %27
store i32* %12, i32** %28
store i32* %13, i32** %29
store i32 %14, i32* %30
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %31, i64 0, i64 0
%34 = load i32*, i32** %23
%35 = load i32*, i32** %26
%36 = load i32, i32* %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %34, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @nameitem(i8* %33, i32 %39)
%41 = load i32*, i32** %18
%42 = getelementptr inbounds i32, i32* %41, i64 1
%43 = load i32, i32* %42
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %61
45: ; preds = %15
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %31, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %46)
%48 = load i32*, i32** %16
%49 = load i32*, i32** %17
%50 = load i32*, i32** %18
%51 = load i32*, i32** %19
%52 = load i32*, i32** %20
%53 = load i32*, i32** %21
%54 = load i32*, i32** %22
%55 = load i32*, i32** %23
%56 = load i32*, i32** %24
%57 = load i32*, i32** %25
%58 = load i32*, i32** %26
%59 = load i32*, i32** %29
%60 = call i32 @treasure(i32* %48, i32* %49, i32* %50, i32* %51, i32* %52, i32* %53, i32* %54, i32* %55, i32* %56, i32* %57, i32* %58, i32* %59, i32 0, i32 1, i32 0)
br label %210
61: ; preds = %15
%62 = load i32, i32* %30
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %97
64: ; preds = %61
%65 = load i32*, i32** %18
%66 = load i32*, i32** %19
%67 = call i32 @magiccount(i32* %65, i32* %66)
%68 = icmp sgt i32 %67, 3
br i1 %68, label %69, label %97
69: ; preds = %64
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%71 = call i32 @getint(i32* %32)
%72 = load i32, i32* %32
%73 = icmp eq i32 %72, 1
br i1 %73, label %74, label %78
74: ; preds = %69
%75 = load i32*, i32** %18
%76 = load i32*, i32** %19
%77 = call i32 @illusion(i32* %75, i32* %76)
store i32 %77, i32* %32
br label %78
78: ; preds = %74, %69
%79 = load i32, i32* %32
%80 = icmp eq i32 %79, 1
br i1 %80, label %81, label %96
81: ; preds = %78
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.2, i64 0, i64 0))
%83 = load i32*, i32** %16
%84 = load i32*, i32** %17
%85 = load i32*, i32** %18
%86 = load i32*, i32** %19
%87 = load i32*, i32** %20
%88 = load i32*, i32** %21
%89 = load i32*, i32** %22
%90 = load i32*, i32** %23
%91 = load i32*, i32** %24
%92 = load i32*, i32** %25
%93 = load i32*, i32** %26
%94 = load i32*, i32** %29
%95 = call i32 @treasure(i32* %83, i32* %84, i32* %85, i32* %86, i32* %87, i32* %88, i32* %89, i32* %90, i32* %91, i32* %92, i32* %93, i32* %94, i32 0, i32 1, i32 0)
br label %96
96: ; preds = %81, %78
br label %97
97: ; preds = %96, %64, %61
%98 = load i32*, i32** %18
%99 = load i32*, i32** %19
%100 = call i32 @magiccount(i32* %98, i32* %99)
%101 = icmp sgt i32 %100, 5
br i1 %101, label %102, label %129
102: ; preds = %97
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0))
%104 = call i32 @getint(i32* %32)
%105 = load i32, i32* %32
%106 = icmp eq i32 %105, 1
br i1 %106, label %107, label %128
107: ; preds = %102
%108 = load i32*, i32** %16
%109 = load i32*, i32** %17
%110 = load i32*, i32** %18
%111 = load i32*, i32** %19
%112 = load i32*, i32** %20
%113 = load i32*, i32** %21
%114 = load i32*, i32** %22
%115 = load i32*, i32** %23
%116 = load i32*, i32** %24
%117 = load i32*, i32** %25
%118 = load i32*, i32** %26
%119 = load i32*, i32** %27
%120 = load i32*, i32** %28
%121 = load i32*, i32** %29
%122 = call i32 @stealingspirit(i32* %108, i32* %109, i32* %110, i32* %111, i32* %112, i32* %113, i32* %114, i32* %115, i32* %116, i32* %117, i32* %118, i32* %119, i32* %120, i32* %121, i32* null, i32* null, i32* null)
%123 = load i32, i32* %30
%124 = icmp eq i32 %123, 0
br i1 %124, label %125, label %127
125: ; preds = %107
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %127
127: ; preds = %125, %107
br label %128
128: ; preds = %127, %102
br label %129
129: ; preds = %128, %97
%130 = load i32*, i32** %23
%131 = load i32*, i32** %26
%132 = load i32, i32* %131
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i32, i32* %130, i64 %133
%135 = load i32, i32* %134
%136 = call i64 @valueitem(i32 %135)
%137 = load i32*, i32** %19
%138 = load i32*, i32** %20
%139 = call i64 @valueinv(i32* %137, i32* %138)
%140 = icmp sgt i64 %136, %139
br i1 %140, label %141, label %153
141: ; preds = %129
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%143 = load i32*, i32** %23
%144 = load i32*, i32** %26
%145 = load i32, i32* %144
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i32, i32* %143, i64 %146
store i32 -1, i32* %147
%148 = load i32*, i32** %24
%149 = load i32*, i32** %26
%150 = load i32, i32* %149
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds i32, i32* %148, i64 %151
store i32 2, i32* %152
br label %210
153: ; preds = %129
%154 = load i32, i32* %30
%155 = icmp eq i32 %154, 1
br i1 %155, label %156, label %179
156: ; preds = %153
%157 = load i32*, i32** %23
%158 = load i32*, i32** %26
%159 = load i32, i32* %158
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds i32, i32* %157, i64 %160
%162 = load i32, i32* %161
%163 = call i64 @valueitem(i32 %162)
%164 = load i32*, i32** %19
%165 = call i64 @gemcount(i32* %164)
%166 = icmp sgt i64 %163, %165
br i1 %166, label %167, label %179
167: ; preds = %156
%168 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
%169 = load i32*, i32** %23
%170 = load i32*, i32** %26
%171 = load i32, i32* %170
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i32, i32* %169, i64 %172
store i32 -1, i32* %173
%174 = load i32*, i32** %24
%175 = load i32*, i32** %26
%176 = load i32, i32* %175
%177 = sext i32 %176 to i64
%178 = getelementptr inbounds i32, i32* %174, i64 %177
store i32 2, i32* %178
br label %210
179: ; preds = %156, %153
%180 = load i32, i32* %30
%181 = icmp eq i32 %180, 0
br i1 %181, label %182, label %196
182: ; preds = %179
%183 = load i32*, i32** %16
%184 = load i32*, i32** %17
%185 = load i32*, i32** %18
%186 = load i32*, i32** %19
%187 = load i32*, i32** %20
%188 = load i32*, i32** %21
%189 = load i32*, i32** %22
%190 = load i32*, i32** %23
%191 = load i32*, i32** %24
%192 = load i32*, i32** %25
%193 = load i32*, i32** %26
%194 = load i32*, i32** %29
%195 = call i32 @goodsoffer(i32* %183, i32* %184, i32* %185, i32* %186, i32* %187, i32* %188, i32* %189, i32* %190, i32* %191, i32* %192, i32* %193, i32* %194)
br label %210
196: ; preds = %179
%197 = load i32*, i32** %16
%198 = load i32*, i32** %17
%199 = load i32*, i32** %18
%200 = load i32*, i32** %19
%201 = load i32*, i32** %20
%202 = load i32*, i32** %21
%203 = load i32*, i32** %22
%204 = load i32*, i32** %23
%205 = load i32*, i32** %24
%206 = load i32*, i32** %25
%207 = load i32*, i32** %26
%208 = load i32*, i32** %29
%209 = call i32 @gemoffer(i32* %197, i32* %198, i32* %199, i32* %200, i32* %201, i32* %202, i32* %203, i32* %204, i32* %205, i32* %206, i32* %207, i32* %208)
br label %210
210: ; preds = %196, %182, %167, %141, %45
ret void
}

LLVM IR (-O2):
@.str = [64 x i8] c"You put out enough gems from your bag of Meres and buy the %s.\0A\00"
@str = [39 x i8] c"'You don't have enough gems to trade!'\00"
@str.7 = [40 x i8] c"'You don't have enough goods to trade!'\00"
@str.8 = [60 x i8] c"Do you want to use a StealingSpirit spell?\0A[0]: No\0A[1]: Yes\00"
@str.9 = [25 x i8] c"The merchant disappears!\00"
@str.10 = [55 x i8] c"Do you want to use an Illusion spell?\0A[0]: No\0A[1]: Yes\00"
@str.11 = [66 x i8] c"You give nothing to the adventurer, but you receive the treasure!\00"
define void @exchange(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32 %14) {
%16 = alloca [20 x i8]
%17 = alloca i32
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%19 = bitcast i32* %17 to i8*
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %7, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @nameitem(i8* %18, i32 %23)
%25 = getelementptr inbounds i32, i32* %2, i64 1
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %15
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i8* %18)
%30 = call i32 @treasure(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %13, i32 0, i32 1, i32 0)
br label %99
31: ; preds = %15
%32 = icmp eq i32 %14, 1
br i1 %32, label %33, label %47
33: ; preds = %31
%34 = call i32 @magiccount(i32* %2, i32* %3)
%35 = icmp sgt i32 %34, 3
br i1 %35, label %36, label %47
36: ; preds = %33
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.10, i64 0, i64 0))
%38 = call i32 @getint(i32* %17)
%39 = load i32, i32* %17
%40 = icmp eq i32 %39, 1
br i1 %40, label %41, label %47
41: ; preds = %36
%42 = call i32 @illusion(i32* %2, i32* %3)
store i32 %42, i32* %17
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.11, i64 0, i64 0))
%46 = call i32 @treasure(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %13, i32 0, i32 1, i32 0)
br label %47
47: ; preds = %36, %41, %44, %33, %31
%48 = call i32 @magiccount(i32* %2, i32* %3)
%49 = icmp sgt i32 %48, 5
br i1 %49, label %50, label %60
50: ; preds = %47
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.8, i64 0, i64 0))
%52 = call i32 @getint(i32* %17)
%53 = load i32, i32* %17
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %60
55: ; preds = %50
%56 = call i32 @stealingspirit(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %11, i32* %12, i32* %13, i32* null, i32* null, i32* null)
%57 = icmp eq i32 %14, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.9, i64 0, i64 0))
br label %60
60: ; preds = %50, %58, %55, %47
%61 = load i32, i32* %10
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %7, i64 %62
%64 = load i32, i32* %63
%65 = call i64 @valueitem(i32 %64)
%66 = call i64 @valueinv(i32* %3, i32* %4)
%67 = icmp sgt i64 %65, %66
br i1 %67, label %68, label %76
68: ; preds = %60
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.7, i64 0, i64 0))
%70 = load i32, i32* %10
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %7, i64 %71
store i32 -1, i32* %72
%73 = load i32, i32* %10
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %8, i64 %74
store i32 2, i32* %75
br label %99
76: ; preds = %60
br i1 %32, label %77, label %93
77: ; preds = %76
%78 = load i32, i32* %10
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %7, i64 %79
%81 = load i32, i32* %80
%82 = call i64 @valueitem(i32 %81)
%83 = call i64 @gemcount(i32* %3)
%84 = icmp sgt i64 %82, %83
br i1 %84, label %85, label %97
85: ; preds = %77
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%87 = load i32, i32* %10
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i32, i32* %7, i64 %88
store i32 -1, i32* %89
%90 = load i32, i32* %10
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i32, i32* %8, i64 %91
store i32 2, i32* %92
br label %99
93: ; preds = %76
%94 = icmp eq i32 %14, 0
br i1 %94, label %95, label %97
95: ; preds = %93
%96 = call i32 @goodsoffer(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %13)
br label %99
97: ; preds = %77, %93
%98 = call i32 @gemoffer(i32* %0, i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i32* %10, i32* %13)
br label %99
99: ; preds = %97, %95, %85, %68, %28
ret void
}