#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__ checkpositiveace(int *);
int /*<<< orphan*/ checkpositiveinv(int *);
int min(int, int);
int mostvalueinv(int *);
int /*<<< orphan*/ nameitem(char *, int);
int /*<<< orphan*/ printf(char *, ...);
void removemost(int *hpmax, int *hpnow, int *aces, int *inv) {
  if (checkpositiveace(aces)) {
    if (*(aces + 1) == 1) {
      *(aces + 1) = 0;
      printf("'Nice, I will take your Bag of Meres.'\nThe black priestess "
             "disappears!\n");
      return;
    }
    if (*(aces) == 1) {
      *(aces) = 0;
      printf("'Nice, I will take your Ruby of Gaza.'\nThe black priestess "
             "disappears!\n");
      *hpmax = *hpmax - 5;
      *hpnow = min(*hpmax, *hpnow);
      return;
    }
    if (*(aces + 2) == 1) {
      *(aces + 2) = 0;
      printf("'Nice, I will take your Scepter of Leynos.'\nThe black priestess "
             "disappears!\n");
      return;
    }
    if (*(aces + 3) == 1) {
      *(aces + 3) = 0;
      printf("'Nice, I will take your Bracelet of Armok.'\nThe black priestess "
             "disappears!\n");
      return;
    }
  }
  if (!checkpositiveinv(inv)) {
    printf("'Damn, your bag is empty!'\nThe black priestess disappears!\n");
    return;
  }
  int p = mostvalueinv(inv);
  if (p = 0) {
    printf(
        "'I can't take anything from you!'\nThe black priestess disappears!\n");
    return;
  }
  char s[20];
  nameitem(s, *(inv + p));
  printf("'Not bad, I will take your %s.'\nThe black priestess disappears!\n",
         s);
  *(inv + p) = 0;
}


x86 assembly (clang, -O0):
<removemost>:
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    -0x18(%rbp),%rdi
call   1050 <checkpositiveace@plt>
cmp    $0x0,%rax
je     1266 <removemost+0x106>
mov    -0x18(%rbp),%rax
cmpl   $0x1,0x4(%rax)
jne    11b7 <removemost+0x57>
mov    -0x18(%rbp),%rax
movl   $0x0,0x4(%rax)
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f5 <removemost+0x195>
mov    -0x18(%rbp),%rax
cmpl   $0x1,(%rax)
jne    1209 <removemost+0xa9>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
lea    0xe73(%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    12f5 <removemost+0x195>
mov    -0x18(%rbp),%rax
cmpl   $0x1,0x8(%rax)
jne    1235 <removemost+0xd5>
mov    -0x18(%rbp),%rax
movl   $0x0,0x8(%rax)
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f5 <removemost+0x195>
mov    -0x18(%rbp),%rax
cmpl   $0x1,0xc(%rax)
jne    1261 <removemost+0x101>
mov    -0x18(%rbp),%rax
movl   $0x0,0xc(%rax)
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f5 <removemost+0x195>
jmp    1266 <removemost+0x106>
mov    -0x20(%rbp),%rdi
call   1070 <checkpositiveinv@plt>
cmp    $0x0,%eax
jne    128b <removemost+0x12b>
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f5 <removemost+0x195>
mov    -0x20(%rbp),%rdi
call   1080 <mostvalueinv@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    12ad <removemost+0x14d>
jmp    12c0 <removemost+0x160>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f5 <removemost+0x195>
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    0xeca(%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):
<removemost>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdx,%rdi
call   1060 <checkpositiveace@plt>
test   %rax,%rax
je     1208 <removemost+0x98>
cmpl   $0x1,0x4(%rbx)
jne    11ad <removemost+0x3d>
movl   $0x0,0x4(%rbx)
lea    0xfb3(%rip),%rdi
jmp    1255 <removemost+0xe5>
cmpl   $0x1,(%rbx)
jne    11dc <removemost+0x6c>
movl   $0x0,(%rbx)
lea    0xf55(%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    1242 <removemost+0xd2>
cmpl   $0x1,0x8(%rbx)
jne    11f2 <removemost+0x82>
movl   $0x0,0x8(%rbx)
lea    0xed8(%rip),%rdi
jmp    1255 <removemost+0xe5>
cmpl   $0x1,0xc(%rbx)
jne    1208 <removemost+0x98>
movl   $0x0,0xc(%rbx)
lea    0xe76(%rip),%rdi
jmp    1255 <removemost+0xe5>
mov    %r15,%rdi
call   1080 <checkpositiveinv@plt>
test   %eax,%eax
je     124e <removemost+0xde>
mov    %r15,%rdi
call   1090 <mostvalueinv@plt>
mov    (%r15),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <nameitem@plt>
lea    0xdcf(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%r15)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdec(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <puts@plt>

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

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