#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*/ getint(int *);
int /*<<< orphan*/ nameitem(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int magicconsume(int *aces, int *inv, int cost, char *name) {
  int value = 0;
  int k;
  int a = 1;
  if (*(aces + 2) == 1)
    a = 2;
  int offmag[10];
  for (k = 0; k < 10; k++) {
    offmag[k] = 0;
  }
  char s[20];
  int p = -1;
  do {
    printf("'What magic potion do you want to use?'\n");
    getint(&k);
    if ((k < 0) || (k >= 10) || (*(inv + k) == 0)) {
      printf("Nothing here. Abort the cast?'\n[0]: No\n[1]: Yes\n");
      getint(&k);
      if (k == 1)
        return -1;
    } else if ((*(inv + k) > 35) || (*(inv + k) < 26)) {
      printf(
          "'That's not a magic potion! Abort the cast?'\n[0]: No\n[1]: Yes\n");
      getint(&k);
      if (k == 1)
        return -1;
    } else {
      value += (*(inv + k) % 13 + 1) * a;
      p++;
      offmag[p] = k;
    }
    if (value < cost)
      printf("'You have to use (at least) %d magic potions and you are using "
             "%d potions.'\n",
             cost, value);
    else {
      printf("'Do you want to use %d potions:", value);
      for (k = 0; k <= p; k++) {
        nameitem(s, offmag[k]);
        if (k == p) {
          printf(" %s?\n", s);
        } else
          printf(" %s,", s);
      }
      k = -1;
      do {
        printf("'Do you want to cast %s?'\n[0]: No\n[1]: Yes\n", name);
        getint(&k);
        if (k == 0) {
          printf("'Abort the cast?'\n[0]: No\n[1]: Yes\n");
          getint(&k);
          if (k == 1)
            return -1;
          printf(
              "'Do you want to use different potions?'\n[0]: No\n[1]: Yes\n");
          if (k == 0)
            return -1;
          for (k = 0; k < 10; k++) {
            offmag[k] = 0;
          }
          p = -1;
        } else if (k == 1) {
          for (k = 0; k <= p; k++) {
            *(inv + offmag[k]) = 0;
          }
          return value;
        }
      } while (k < 0);
    }
  } while (value < cost);
}


x86 assembly (clang, -O0):
<magicconsume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x1,0x8(%rax)
jne    116d <magicconsume+0x3d>
movl   $0x2,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0xa,-0x30(%rbp)
jge    1198 <magicconsume+0x68>
movslq -0x30(%rbp),%rax
movl   $0x0,-0x60(%rbp,%rax,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1174 <magicconsume+0x44>
movl   $0xffffffff,-0x84(%rbp)
ff ff ff
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <getint@plt>
cmpl   $0x0,-0x30(%rbp)
jl     11df <magicconsume+0xaf>
cmpl   $0xa,-0x30(%rbp)
jge    11df <magicconsume+0xaf>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1211 <magicconsume+0xe1>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <getint@plt>
cmpl   $0x1,-0x30(%rbp)
jne    120c <magicconsume+0xdc>
movl   $0xffffffff,-0x4(%rbp)
jmp    1481 <magicconsume+0x351>
jmp    12ab <magicconsume+0x17b>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
cmpl   $0x23,(%rax,%rcx,4)
jg     1235 <magicconsume+0x105>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
cmpl   $0x1a,(%rax,%rcx,4)
jge    1267 <magicconsume+0x137>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <getint@plt>
cmpl   $0x1,-0x30(%rbp)
jne    1262 <magicconsume+0x132>
movl   $0xffffffff,-0x4(%rbp)
jmp    1481 <magicconsume+0x351>
jmp    12a6 <magicconsume+0x176>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x1,%eax
imul   -0x34(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
mov    -0x30(%rbp),%ecx
movslq -0x84(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
jmp    12ab <magicconsume+0x17b>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12d0 <magicconsume+0x1a0>
mov    -0x1c(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1470 <magicconsume+0x340>
mov    -0x2c(%rbp),%esi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x84(%rbp),%eax
jg     1353 <magicconsume+0x223>
lea    -0x80(%rbp),%rdi
movslq -0x30(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
call   1050 <nameitem@plt>
mov    -0x30(%rbp),%eax
cmp    -0x84(%rbp),%eax
jne    132e <magicconsume+0x1fe>
lea    -0x80(%rbp),%rsi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1340 <magicconsume+0x210>
lea    -0x80(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1345 <magicconsume+0x215>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    12e8 <magicconsume+0x1b8>
movl   $0xffffffff,-0x30(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <getint@plt>
cmpl   $0x0,-0x30(%rbp)
jne    140a <magicconsume+0x2da>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <getint@plt>
cmpl   $0x1,-0x30(%rbp)
jne    13ac <magicconsume+0x27c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1481 <magicconsume+0x351>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x30(%rbp)
jne    13d0 <magicconsume+0x2a0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1481 <magicconsume+0x351>
movl   $0x0,-0x30(%rbp)
cmpl   $0xa,-0x30(%rbp)
jge    13fb <magicconsume+0x2cb>
movslq -0x30(%rbp),%rax
movl   $0x0,-0x60(%rbp,%rax,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13d7 <magicconsume+0x2a7>
movl   $0xffffffff,-0x84(%rbp)
ff ff ff
jmp    145c <magicconsume+0x32c>
cmpl   $0x1,-0x30(%rbp)
jne    1457 <magicconsume+0x327>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x84(%rbp),%eax
jg     144c <magicconsume+0x31c>
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
movslq -0x60(%rbp,%rcx,4),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    141b <magicconsume+0x2eb>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1481 <magicconsume+0x351>
jmp    145c <magicconsume+0x32c>
jmp    1461 <magicconsume+0x331>
cmpl   $0x0,-0x30(%rbp)
jl     135a <magicconsume+0x22a>
jmp    1470 <magicconsume+0x340>
jmp    1475 <magicconsume+0x345>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     11a2 <magicconsume+0x72>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<magicconsume>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rcx,%r14
mov    %rsi,%rbx
xor    %eax,%eax
cmpl   $0x1,0x8(%rdi)
sete   %al
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
add    $0x1,%eax
mov    %eax,0xc(%rsp)
movl   $0xa,(%rsp)
mov    $0xffffffff,%ebp
lea    0x40(%rsp),%r15
lea    0xee1(%rip),%r13
xor    %r12d,%r12d
mov    %edx,0x8(%rsp)
jmp    11be <magicconsume+0x7e>
nopl   0x0(%rax,%rax,1)
lea    0xe59(%rip),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%edx
cmp    %edx,%r12d
jge    137e <magicconsume+0x23e>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1050 <getint@plt>
mov    (%rsp),%eax
cmp    $0x9,%rax
ja     1200 <magicconsume+0xc0>
mov    (%rbx,%rax,4),%ecx
test   %ecx,%ecx
je     1200 <magicconsume+0xc0>
lea    -0x24(%rcx),%edx
cmp    $0xfffffff5,%edx
ja     1334 <magicconsume+0x1f4>
lea    0xf33(%rip),%rdi
jmp    1207 <magicconsume+0xc7>
nopw   0x0(%rax,%rax,1)
lea    0xf5f(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1050 <getint@plt>
cmpl   $0x1,(%rsp)
je     137e <magicconsume+0x23e>
mov    0x8(%rsp),%esi
cmp    %esi,%r12d
jl     11a0 <magicconsume+0x60>
lea    0xe1b(%rip),%rdi
mov    %r12d,0x4(%rsp)
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%rsp)
test   %ebp,%ebp
lea    0xe1c(%rip),%r12
js     128f <magicconsume+0x14f>
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nop
cltq
mov    0x10(%rsp,%rax,4),%esi
mov    %r15,%rdi
call   1060 <nameitem@plt>
cmp    %ebp,(%rsp)
mov    %r13,%rdi
cmove  %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%ecx
lea    0x1(%rcx),%eax
mov    %eax,(%rsp)
cmp    %ebp,%ecx
jl     1260 <magicconsume+0x120>
movl   $0xffffffff,(%rsp)
cs nopw 0x0(%rax,%rax,1)
lea    0xdd1(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%rdi
call   1050 <getint@plt>
mov    (%rsp),%eax
test   %eax,%eax
je     12cf <magicconsume+0x18f>
cmp    $0x1,%eax
je     1362 <magicconsume+0x222>
test   %eax,%eax
js     12a0 <magicconsume+0x160>
jmp    132a <magicconsume+0x1ea>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rdi
call   1050 <getint@plt>
mov    $0xffffffff,%ebp
cmpl   $0x1,(%rsp)
je     13f8 <magicconsume+0x2b8>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,(%rsp)
je     13f8 <magicconsume+0x2b8>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
movl   $0xa,(%rsp)
mov    $0xffffffff,%ebp
mov    0x4(%rsp),%r12d
jmp    11b1 <magicconsume+0x71>
movzbl %cl,%ecx
imul   $0x4f,%ecx,%edx
shr    $0xa,%edx
lea    (%rdx,%rdx,2),%esi
lea    (%rdx,%rsi,4),%edx
sub    %dl,%cl
add    $0x1,%cl
movzbl %cl,%ecx
imul   0xc(%rsp),%ecx
add    %ecx,%r12d
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %eax,0x14(%rsp,%rcx,4)
jmp    121e <magicconsume+0xde>
test   %ebp,%ebp
js     13f4 <magicconsume+0x2b4>
mov    %ebp,%ecx
add    $0x1,%rcx
mov    %ecx,%eax
and    $0x3,%eax
cmp    $0x3,%ebp
jae    1385 <magicconsume+0x245>
xor    %edx,%edx
jmp    13c9 <magicconsume+0x289>
mov    $0xffffffff,%ebp
jmp    13f8 <magicconsume+0x2b8>
and    $0xfffffffc,%ecx
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
movslq 0x10(%rsp,%rdx,4),%rsi
movl   $0x0,(%rbx,%rsi,4)
movslq 0x14(%rsp,%rdx,4),%rsi
movl   $0x0,(%rbx,%rsi,4)
movslq 0x18(%rsp,%rdx,4),%rsi
movl   $0x0,(%rbx,%rsi,4)
movslq 0x1c(%rsp,%rdx,4),%rsi
movl   $0x0,(%rbx,%rsi,4)
add    $0x4,%rdx
cmp    %rdx,%rcx
jne    1390 <magicconsume+0x250>
test   %rax,%rax
je     13f4 <magicconsume+0x2b4>
lea    (%rsp,%rdx,4),%rcx
add    $0x10,%rcx
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movslq (%rcx,%rdx,4),%rsi
movl   $0x0,(%rbx,%rsi,4)
add    $0x1,%rdx
cmp    %rdx,%rax
jne    13e0 <magicconsume+0x2a0>
mov    0x4(%rsp),%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"'What magic potion do you want to use?'\0A\00"
@.str.1 = [49 x i8] c"Nothing here. Abort the cast?'\0A[0]: No\0A[1]: Yes\0A\00"
@.str.2 = [63 x i8] c"'That's not a magic potion! Abort the cast?'\0A[0]: No\0A[1]: Yes\0A\00"
@.str.3 = [77 x i8] c"'You have to use (at least) %d magic potions and you are using %d potions.'\0A\00"
@.str.4 = [32 x i8] c"'Do you want to use %d potions:\00"
@.str.5 = [6 x i8] c" %s?\0A\00"
@.str.6 = [5 x i8] c" %s,\00"
@.str.7 = [44 x i8] c"'Do you want to cast %s?'\0A[0]: No\0A[1]: Yes\0A\00"
@.str.8 = [36 x i8] c"'Abort the cast?'\0A[0]: No\0A[1]: Yes\0A\00"
@.str.9 = [58 x i8] c"'Do you want to use different potions?'\0A[0]: No\0A[1]: Yes\0A\00"
define i32 @magicconsume(i32* %0, i32* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [10 x i32]
%14 = alloca [20 x i8]
%15 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
store i32 0, i32* %10
store i32 1, i32* %12
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i64 2
%18 = load i32, i32* %17
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 2, i32* %12
br label %21
21: ; preds = %20, %4
store i32 0, i32* %11
br label %22
22: ; preds = %29, %21
%23 = load i32, i32* %11
%24 = icmp slt i32 %23, 10
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i32, i32* %11
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 %27
store i32 0, i32* %28
br label %29
29: ; preds = %25
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 1
store i32 %31, i32* %11
br label %22
32: ; preds = %22
store i32 -1, i32* %15
br label %33
33: ; preds = %188, %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%35 = call i32 @getint(i32* %11)
%36 = load i32, i32* %11
%37 = icmp slt i32 %36, 0
br i1 %37, label %48, label %38
38: ; preds = %33
%39 = load i32, i32* %11
%40 = icmp sge i32 %39, 10
br i1 %40, label %48, label %41
41: ; preds = %38
%42 = load i32*, i32** %7
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %55
48: ; preds = %41, %38, %33
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @getint(i32* %11)
%51 = load i32, i32* %11
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %54
53: ; preds = %48
store i32 -1, i32* %5
br label %192
54: ; preds = %48
br label %95
55: ; preds = %41
%56 = load i32*, i32** %7
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = load i32, i32* %59
%61 = icmp sgt i32 %60, 35
br i1 %61, label %69, label %62
62: ; preds = %55
%63 = load i32*, i32** %7
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = icmp slt i32 %67, 26
br i1 %68, label %69, label %76
69: ; preds = %62, %55
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%71 = call i32 @getint(i32* %11)
%72 = load i32, i32* %11
%73 = icmp eq i32 %72, 1
br i1 %73, label %74, label %75
74: ; preds = %69
store i32 -1, i32* %5
br label %192
75: ; preds = %69
br label %94
76: ; preds = %62
%77 = load i32*, i32** %7
%78 = load i32, i32* %11
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
%81 = load i32, i32* %80
%82 = srem i32 %81, 13
%83 = add nsw i32 %82, 1
%84 = load i32, i32* %12
%85 = mul nsw i32 %83, %84
%86 = load i32, i32* %10
%87 = add nsw i32 %86, %85
store i32 %87, i32* %10
%88 = load i32, i32* %15
%89 = add nsw i32 %88, 1
store i32 %89, i32* %15
%90 = load i32, i32* %11
%91 = load i32, i32* %15
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 %92
store i32 %90, i32* %93
br label %94
94: ; preds = %76, %75
br label %95
95: ; preds = %94, %54
%96 = load i32, i32* %10
%97 = load i32, i32* %8
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %103
99: ; preds = %95
%100 = load i32, i32* %8
%101 = load i32, i32* %10
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.3, i64 0, i64 0), i32 %100, i32 %101)
br label %187
103: ; preds = %95
%104 = load i32, i32* %10
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %104)
store i32 0, i32* %11
br label %106
106: ; preds = %127, %103
%107 = load i32, i32* %11
%108 = load i32, i32* %15
%109 = icmp sle i32 %107, %108
br i1 %109, label %110, label %130
110: ; preds = %106
%111 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%112 = load i32, i32* %11
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 %113
%115 = load i32, i32* %114
%116 = call i32 @nameitem(i8* %111, i32 %115)
%117 = load i32, i32* %11
%118 = load i32, i32* %15
%119 = icmp eq i32 %117, %118
br i1 %119, label %120, label %123
120: ; preds = %110
%121 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%122 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %121)
br label %126
123: ; preds = %110
%124 = getelementptr inbounds [20 x i8], [20 x i8]* %14, i64 0, i64 0
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %124)
br label %126
126: ; preds = %123, %120
br label %127
127: ; preds = %126
%128 = load i32, i32* %11
%129 = add nsw i32 %128, 1
store i32 %129, i32* %11
br label %106
130: ; preds = %106
store i32 -1, i32* %11
br label %131
131: ; preds = %183, %130
%132 = load i8*, i8** %9
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i8* %132)
%134 = call i32 @getint(i32* %11)
%135 = load i32, i32* %11
%136 = icmp eq i32 %135, 0
br i1 %136, label %137, label %160
137: ; preds = %131
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0))
%139 = call i32 @getint(i32* %11)
%140 = load i32, i32* %11
%141 = icmp eq i32 %140, 1
br i1 %141, label %142, label %143
142: ; preds = %137
store i32 -1, i32* %5
br label %192
143: ; preds = %137
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.9, i64 0, i64 0))
%145 = load i32, i32* %11
%146 = icmp eq i32 %145, 0
br i1 %146, label %147, label %148
147: ; preds = %143
store i32 -1, i32* %5
br label %192
148: ; preds = %143
store i32 0, i32* %11
br label %149
149: ; preds = %156, %148
%150 = load i32, i32* %11
%151 = icmp slt i32 %150, 10
br i1 %151, label %152, label %159
152: ; preds = %149
%153 = load i32, i32* %11
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 %154
store i32 0, i32* %155
br label %156
156: ; preds = %152
%157 = load i32, i32* %11
%158 = add nsw i32 %157, 1
store i32 %158, i32* %11
br label %149
159: ; preds = %149
store i32 -1, i32* %15
br label %182
160: ; preds = %131
%161 = load i32, i32* %11
%162 = icmp eq i32 %161, 1
br i1 %162, label %163, label %181
163: ; preds = %160
store i32 0, i32* %11
br label %164
164: ; preds = %176, %163
%165 = load i32, i32* %11
%166 = load i32, i32* %15
%167 = icmp sle i32 %165, %166
br i1 %167, label %168, label %179
168: ; preds = %164
%169 = load i32*, i32** %7
%170 = load i32, i32* %11
%171 = sext i32 %170 to i64
%172 = getelementptr inbounds [10 x i32], [10 x i32]* %13, i64 0, i64 %171
%173 = load i32, i32* %172
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds i32, i32* %169, i64 %174
store i32 0, i32* %175
br label %176
176: ; preds = %168
%177 = load i32, i32* %11
%178 = add nsw i32 %177, 1
store i32 %178, i32* %11
br label %164
179: ; preds = %164
%180 = load i32, i32* %10
store i32 %180, i32* %5
br label %192
181: ; preds = %160
br label %182
182: ; preds = %181, %159
br label %183
183: ; preds = %182
%184 = load i32, i32* %11
%185 = icmp slt i32 %184, 0
br i1 %185, label %131, label %186
186: ; preds = %183
br label %187
187: ; preds = %186, %99
br label %188
188: ; preds = %187
%189 = load i32, i32* %10
%190 = load i32, i32* %8
%191 = icmp slt i32 %189, %190
br i1 %191, label %33, label %192
192: ; preds = %53, %74, %142, %147, %179, %188
%193 = load i32, i32* %5
ret i32 %193
}

LLVM IR (-O2):
@.str.3 = [77 x i8] c"'You have to use (at least) %d magic potions and you are using %d potions.'\0A\00"
@.str.4 = [32 x i8] c"'Do you want to use %d potions:\00"
@.str.5 = [6 x i8] c" %s?\0A\00"
@.str.6 = [5 x i8] c" %s,\00"
@.str.7 = [44 x i8] c"'Do you want to cast %s?'\0A[0]: No\0A[1]: Yes\0A\00"
@str = [40 x i8] c"'What magic potion do you want to use?'\00"
@str.10 = [35 x i8] c"'Abort the cast?'\0A[0]: No\0A[1]: Yes\00"
@str.11 = [57 x i8] c"'Do you want to use different potions?'\0A[0]: No\0A[1]: Yes\00"
@str.12 = [62 x i8] c"'That's not a magic potion! Abort the cast?'\0A[0]: No\0A[1]: Yes\00"
@str.13 = [48 x i8] c"Nothing here. Abort the cast?'\0A[0]: No\0A[1]: Yes\00"
define i32 @magicconsume(i32* nocapture %0, i32* nocapture %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca [10 x i32]
%7 = bitcast [10 x i32]* %6 to i8*
%8 = alloca [20 x i8]
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds i32, i32* %0, i64 2
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 1
%13 = select i1 %12, i32 2, i32 1
store i32 10, i32* %5
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
br label %15
15: ; preds = %123, %4
%16 = phi i32 [ 0, %4 ], [ %51, %123 ]
%17 = phi i32 [ -1, %4 ], [ %124, %123 ]
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%19 = call i32 @getint(i32* %5)
%20 = load i32, i32* %5
%21 = icmp ugt i32 %20, 9
br i1 %21, label %27, label %22
22: ; preds = %15
%23 = zext i32 %20 to i64
%24 = getelementptr inbounds i32, i32* %1, i64 %23
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22, %15
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.13, i64 0, i64 0))
%29 = call i32 @getint(i32* %5)
%30 = load i32, i32* %5
%31 = icmp eq i32 %30, 1
br i1 %31, label %138, label %50
32: ; preds = %22
%33 = add i32 %25, -36
%34 = icmp ult i32 %33, -10
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.12, i64 0, i64 0))
%37 = call i32 @getint(i32* %5)
%38 = load i32, i32* %5
%39 = icmp eq i32 %38, 1
br i1 %39, label %138, label %50
40: ; preds = %32
%41 = trunc i32 %25 to i8
%42 = urem i8 %41, 13
%43 = add nuw nsw i8 %42, 1
%44 = zext i8 %43 to i32
%45 = mul nuw nsw i32 %13, %44
%46 = add nsw i32 %45, %16
%47 = add nsw i32 %17, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %48
store i32 %20, i32* %49
br label %50
50: ; preds = %40, %35, %27
%51 = phi i32 [ %16, %27 ], [ %16, %35 ], [ %46, %40 ]
%52 = phi i32 [ %17, %27 ], [ %17, %35 ], [ %47, %40 ]
%53 = icmp slt i32 %51, %2
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.3, i64 0, i64 0), i32 %2, i32 %51)
br label %123
56: ; preds = %50
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 %51)
store i32 0, i32* %5
%58 = icmp slt i32 %52, 0
br i1 %58, label %72, label %59
59: ; preds = %56, %59
%60 = phi i32 [ %70, %59 ], [ 0, %56 ]
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %61
%63 = load i32, i32* %62
%64 = call i32 @nameitem(i8* %14, i32 %63)
%65 = load i32, i32* %5
%66 = icmp eq i32 %65, %52
%67 = select i1 %66, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0)
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %67, i8* %14)
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
%71 = icmp slt i32 %69, %52
br i1 %71, label %59, label %72
72: ; preds = %59, %56
store i32 -1, i32* %5
br label %73
73: ; preds = %121, %72
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.7, i64 0, i64 0), i8* %3)
%75 = call i32 @getint(i32* %5)
%76 = load i32, i32* %5
switch i32 %76, label %121 [
i32 0, label %86
i32 1, label %77
]
77: ; preds = %73
br i1 %58, label %138, label %78
78: ; preds = %77
%79 = add nuw i32 %52, 1
%80 = zext i32 %79 to i64
%81 = add nsw i64 %80, -1
%82 = and i64 %80, 3
%83 = icmp ult i64 %81, 3
br i1 %83, label %125, label %84
84: ; preds = %78
%85 = and i64 %80, 4294967292
br label %96
86: ; preds = %73
%87 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.10, i64 0, i64 0))
%88 = call i32 @getint(i32* %5)
%89 = load i32, i32* %5
%90 = icmp eq i32 %89, 1
br i1 %90, label %138, label %91
91: ; preds = %86
%92 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.11, i64 0, i64 0))
%93 = load i32, i32* %5
%94 = icmp eq i32 %93, 0
br i1 %94, label %138, label %95
95: ; preds = %91
store i32 10, i32* %5
br label %123
96: ; preds = %96, %84
%97 = phi i64 [ 0, %84 ], [ %118, %96 ]
%98 = phi i64 [ 0, %84 ], [ %119, %96 ]
%99 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %97
%100 = load i32, i32* %99
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i32, i32* %1, i64 %101
store i32 0, i32* %102
%103 = or i64 %97, 1
%104 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %103
%105 = load i32, i32* %104
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds i32, i32* %1, i64 %106
store i32 0, i32* %107
%108 = or i64 %97, 2
%109 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %108
%110 = load i32, i32* %109
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i32, i32* %1, i64 %111
store i32 0, i32* %112
%113 = or i64 %97, 3
%114 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %113
%115 = load i32, i32* %114
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32, i32* %1, i64 %116
store i32 0, i32* %117
%118 = add nuw nsw i64 %97, 4
%119 = add i64 %98, 4
%120 = icmp eq i64 %119, %85
br i1 %120, label %125, label %96
121: ; preds = %73
%122 = icmp slt i32 %76, 0
br i1 %122, label %73, label %123
123: ; preds = %121, %95, %54
%124 = phi i32 [ %52, %54 ], [ -1, %95 ], [ %52, %121 ]
br i1 %53, label %15, label %138
125: ; preds = %96, %78
%126 = phi i64 [ 0, %78 ], [ %118, %96 ]
%127 = icmp eq i64 %82, 0
br i1 %127, label %138, label %128
128: ; preds = %125, %128
%129 = phi i64 [ %135, %128 ], [ %126, %125 ]
%130 = phi i64 [ %136, %128 ], [ 0, %125 ]
%131 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 %129
%132 = load i32, i32* %131
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds i32, i32* %1, i64 %133
store i32 0, i32* %134
%135 = add nuw nsw i64 %129, 1
%136 = add i64 %130, 1
%137 = icmp eq i64 %136, %82
br i1 %137, label %138, label %128
138: ; preds = %123, %91, %86, %35, %27, %125, %128, %77
%139 = phi i32 [ %51, %77 ], [ %51, %128 ], [ %51, %125 ], [ -1, %27 ], [ -1, %35 ], [ -1, %86 ], [ -1, %91 ], [ -1, %123 ]
ret i32 %139
}