#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*/ checkpositiveace(int *);
int /*<<< orphan*/ checkpositiveinv(int *);
int leastvalueinv(int *);
int min(int, int);
int /*<<< orphan*/ nameitem(char *, int);
int /*<<< orphan*/ printf(char *, ...);
void removeleast(int *hpmax, int *hpnow, int *aces, int *inv) {
  if (!checkpositiveinv(inv)) {
    if (!checkpositiveace(aces)) {
      printf("'Your bag is empty!'\nThe black priestess disappears!\n");
      return;
    }
    if (*(aces + 3) == 1) {
      *(aces + 3) = 0;
      printf("'I'm sorry, but I have to take your Bracelet of Armok.'\nThe "
             "black priestess disappears!\n");
      return;
    }
    if (*(aces + 2) == 1) {
      *(aces + 2) = 0;
      printf("'I'm sorry, but I have to take your Scepter of Leynos.'\nThe "
             "black priestess disappears!\n");
      return;
    }
    if (*(aces) == 1) {
      *(aces) = 0;
      printf("'I'm sorry, but I have to take your Ruby of Gaza.'\nThe black "
             "priestess disappears!\n");
      *hpmax = *hpmax - 5;
      *hpnow = min(*hpmax, *hpnow);
      return;
    }
    if (*(aces + 1) == 1) {
      *(aces + 1) = 0;
      printf("'I'm sorry, but I have to take your Bag of Meres.'\nThe black "
             "priestess disappears!\n");
      return;
    }
  }
  int p = leastvalueinv(inv);
  char s[20];
  nameitem(s, *(inv + p));
  printf("'I'm sorry, but I have to take your %s.'\nThe black priestess "
         "disappears!\n",
         s);
  *(inv + p) = 0;
}


x86 assembly (clang, -O0):
<removeleast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <checkpositiveinv@plt>
cmp    $0x0,%eax
jne    128a <removeleast+0x12a>
mov    -0x18(%rbp),%rdi
call   1050 <checkpositiveace@plt>
cmp    $0x0,%eax
jne    11af <removeleast+0x4f>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12cb <removeleast+0x16b>
mov    -0x18(%rbp),%rax
cmpl   $0x1,0xc(%rax)
jne    11db <removeleast+0x7b>
mov    -0x18(%rbp),%rax
movl   $0x0,0xc(%rax)
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12cb <removeleast+0x16b>
mov    -0x18(%rbp),%rax
cmpl   $0x1,0x8(%rax)
jne    1207 <removeleast+0xa7>
mov    -0x18(%rbp),%rax
movl   $0x0,0x8(%rax)
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12cb <removeleast+0x16b>
mov    -0x18(%rbp),%rax
cmpl   $0x1,(%rax)
jne    1259 <removeleast+0xf9>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0x5,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
call   1040 <min@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    12cb <removeleast+0x16b>
mov    -0x18(%rbp),%rax
cmpl   $0x1,0x4(%rax)
jne    1285 <removeleast+0x125>
mov    -0x18(%rbp),%rax
movl   $0x0,0x4(%rax)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12cb <removeleast+0x16b>
jmp    128a <removeleast+0x12a>
mov    -0x20(%rbp),%rdi
call   1080 <leastvalueinv@plt>
mov    %eax,-0x24(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1060 <nameitem@plt>
lea    -0x40(%rbp),%rsi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeleast>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rcx,%rdi
call   1080 <checkpositiveinv@plt>
test   %eax,%eax
je     11d2 <removeleast+0x62>
mov    %rbx,%rdi
call   1090 <leastvalueinv@plt>
movslq %eax,%r15
mov    (%rbx,%r15,4),%esi
mov    %rsp,%r14
mov    %r14,%rdi
call   1070 <nameitem@plt>
lea    0xe4c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%rbx,%r15,4)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   1060 <checkpositiveace@plt>
test   %eax,%eax
je     11f6 <removeleast+0x86>
cmpl   $0x1,0xc(%r15)
jne    11ff <removeleast+0x8f>
movl   $0x0,0xc(%r15)
lea    0xf89(%rip),%rdi
jmp    1265 <removeleast+0xf5>
lea    0xe4d(%rip),%rdi
jmp    1265 <removeleast+0xf5>
cmpl   $0x1,0x8(%r15)
jne    1217 <removeleast+0xa7>
movl   $0x0,0x8(%r15)
lea    0xf10(%rip),%rdi
jmp    1265 <removeleast+0xf5>
cmpl   $0x1,(%r15)
jne    124b <removeleast+0xdb>
movl   $0x0,(%r15)
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
mov    (%r12),%edi
add    $0xfffffffb,%edi
mov    %edi,(%r12)
mov    (%r14),%esi
call   1050 <min@plt>
mov    %eax,(%r14)
jmp    11c6 <removeleast+0x56>
cmpl   $0x1,0x4(%r15)
jne    1193 <removeleast+0x23>
movl   $0x0,0x4(%r15)
lea    0xe1a(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"'Your bag is empty!'\0AThe black priestess disappears!\0A\00"
@.str.1 = [89 x i8] c"'I'm sorry, but I have to take your Bracelet of Armok.'\0AThe black priestess disappears!\0A\00"
@.str.2 = [89 x i8] c"'I'm sorry, but I have to take your Scepter of Leynos.'\0AThe black priestess disappears!\0A\00"
@.str.3 = [84 x i8] c"'I'm sorry, but I have to take your Ruby of Gaza.'\0AThe black priestess disappears!\0A\00"
@.str.4 = [84 x i8] c"'I'm sorry, but I have to take your Bag of Meres.'\0AThe black priestess disappears!\0A\00"
@.str.5 = [74 x i8] c"'I'm sorry, but I have to take your %s.'\0AThe black priestess disappears!\0A\00"
define void @removeleast(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 [20 x i8]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%11 = load i32*, i32** %8
%12 = call i32 @checkpositiveinv(i32* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %65, label %14
14: ; preds = %4
%15 = load i32*, i32** %7
%16 = call i32 @checkpositiveace(i32* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
br label %81
20: ; preds = %14
%21 = load i32*, i32** %7
%22 = getelementptr inbounds i32, i32* %21, i64 3
%23 = load i32, i32* %22
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32*, i32** %7
%27 = getelementptr inbounds i32, i32* %26, i64 3
store i32 0, i32* %27
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.1, i64 0, i64 0))
br label %81
29: ; preds = %20
%30 = load i32*, i32** %7
%31 = getelementptr inbounds i32, i32* %30, i64 2
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32*, i32** %7
%36 = getelementptr inbounds i32, i32* %35, i64 2
store i32 0, i32* %36
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.2, i64 0, i64 0))
br label %81
38: ; preds = %29
%39 = load i32*, i32** %7
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %55
42: ; preds = %38
%43 = load i32*, i32** %7
store i32 0, i32* %43
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.3, i64 0, i64 0))
%45 = load i32*, i32** %5
%46 = load i32, i32* %45
%47 = sub nsw i32 %46, 5
%48 = load i32*, i32** %5
store i32 %47, i32* %48
%49 = load i32*, i32** %5
%50 = load i32, i32* %49
%51 = load i32*, i32** %6
%52 = load i32, i32* %51
%53 = call i32 @min(i32 %50, i32 %52)
%54 = load i32*, i32** %6
store i32 %53, i32* %54
br label %81
55: ; preds = %38
%56 = load i32*, i32** %7
%57 = getelementptr inbounds i32, i32* %56, i64 1
%58 = load i32, i32* %57
%59 = icmp eq i32 %58, 1
br i1 %59, label %60, label %64
60: ; preds = %55
%61 = load i32*, i32** %7
%62 = getelementptr inbounds i32, i32* %61, i64 1
store i32 0, i32* %62
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.4, i64 0, i64 0))
br label %81
64: ; preds = %55
br label %65
65: ; preds = %64, %4
%66 = load i32*, i32** %8
%67 = call i32 @leastvalueinv(i32* %66)
store i32 %67, i32* %9
%68 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%69 = load i32*, i32** %8
%70 = load i32, i32* %9
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %69, i64 %71
%73 = load i32, i32* %72
%74 = call i32 @nameitem(i8* %68, i32 %73)
%75 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0), i8* %75)
%77 = load i32*, i32** %8
%78 = load i32, i32* %9
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i32, i32* %77, i64 %79
store i32 0, i32* %80
br label %81
81: ; preds = %65, %60, %42, %34, %25, %18
ret void
}

LLVM IR (-O2):
@.str.5 = [74 x i8] c"'I'm sorry, but I have to take your %s.'\0AThe black priestess disappears!\0A\00"
@str = [53 x i8] c"'Your bag is empty!'\0AThe black priestess disappears!\00"
@str.6 = [83 x i8] c"'I'm sorry, but I have to take your Bag of Meres.'\0AThe black priestess disappears!\00"
@str.7 = [83 x i8] c"'I'm sorry, but I have to take your Ruby of Gaza.'\0AThe black priestess disappears!\00"
@str.8 = [88 x i8] c"'I'm sorry, but I have to take your Scepter of Leynos.'\0AThe black priestess disappears!\00"
@str.9 = [88 x i8] c"'I'm sorry, but I have to take your Bracelet of Armok.'\0AThe black priestess disappears!\00"
define void @removeleast(i32* nocapture %0, i32* nocapture %1, i32* %2, i32* %3) {
%5 = alloca [20 x i8]
%6 = tail call i32 @checkpositiveinv(i32* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %40
8: ; preds = %4
%9 = tail call i32 @checkpositiveace(i32* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
br label %48
13: ; preds = %8
%14 = getelementptr inbounds i32, i32* %2, i64 3
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %13
store i32 0, i32* %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @str.9, i64 0, i64 0))
br label %48
19: ; preds = %13
%20 = getelementptr inbounds i32, i32* %2, i64 2
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %19
store i32 0, i32* %20
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @str.8, i64 0, i64 0))
br label %48
25: ; preds = %19
%26 = load i32, i32* %2
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %34
28: ; preds = %25
store i32 0, i32* %2
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str.7, i64 0, i64 0))
%30 = load i32, i32* %0
%31 = add nsw i32 %30, -5
store i32 %31, i32* %0
%32 = load i32, i32* %1
%33 = tail call i32 @min(i32 %31, i32 %32)
store i32 %33, i32* %1
br label %48
34: ; preds = %25
%35 = getelementptr inbounds i32, i32* %2, i64 1
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %40
38: ; preds = %34
store i32 0, i32* %35
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([83 x i8], [83 x i8]* @str.6, i64 0, i64 0))
br label %48
40: ; preds = %34, %4
%41 = tail call i32 @leastvalueinv(i32* %3)
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i32, i32* %3, i64 %43
%45 = load i32, i32* %44
%46 = call i32 @nameitem(i8* %42, i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.5, i64 0, i64 0), i8* %42)
store i32 0, i32* %44
br label %48
48: ; preds = %40, %38, %28, %23, %17, %11
ret void
}