#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 *, ...);
void dropinv(int *inv, int r) {
  int i;
  char s[20];
  char t[20];
  nameitem(s, r);
  printf("Your bag is full! Do you want to drop something to keep %s?\n[0]: "
         "No\n[1]: Yes\n",
         s);
  getint(&i);
  if (i == 0) {
    printf("You don't keep the %s.\n", s);
  } else {
    i = 0;
    do {
      printf("What do you want to drop?\n");
      getint(&i);
      if ((i < 0) || (i >= 10)) {
        printf("You don't have that slot! Insert a number between 0 and %d!\n",
               10 - 1);
        i = 0;
      } else {
        int k;
        nameitem(t, *(inv + i));
        printf("Do you want to drop the %s?\n[0]: No\n[1]: Yes\n", t);
        getint(&k);
        if (k == 1) {
          printf("You dropped the %s to keep the %s.\n", s, t);
          *(inv + i) = r;
          i = -1;
          return;
        } else if (k != 0) {
          printf("You don't have all the day to decide...\n");
        }
      }
    } while (i != -1);
  }
  printf("What do you want to drop?\n");
}


x86 assembly (clang, -O0):
<dropinv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <nameitem@plt>
lea    -0x30(%rbp),%rsi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1040 <getint@plt>
cmpl   $0x0,-0x10(%rbp)
jne    1187 <dropinv+0x57>
lea    -0x30(%rbp),%rsi
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1277 <dropinv+0x147>
movl   $0x0,-0x10(%rbp)
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1040 <getint@plt>
cmpl   $0x0,-0x10(%rbp)
jl     11b9 <dropinv+0x89>
cmpl   $0xa,-0x10(%rbp)
jl     11d8 <dropinv+0xa8>
lea    0xec1(%rip),%rdi
mov    $0x9,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
jmp    1263 <dropinv+0x133>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <nameitem@plt>
lea    -0x50(%rbp),%rsi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x54(%rbp),%rdi
call   1040 <getint@plt>
cmpl   $0x1,-0x54(%rbp)
jne    1241 <dropinv+0x111>
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
movl   $0xffffffff,-0x10(%rbp)
jmp    1285 <dropinv+0x155>
cmpl   $0x0,-0x54(%rbp)
je     1259 <dropinv+0x129>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125e <dropinv+0x12e>
jmp    1263 <dropinv+0x133>
jmp    1268 <dropinv+0x138>
cmpl   $0xffffffff,-0x10(%rbp)
jne    118e <dropinv+0x5e>
jmp    1277 <dropinv+0x147>
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dropinv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <nameitem@plt>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rdi
call   1050 <getint@plt>
cmpl   $0x0,0x4(%rsp)
je     1239 <dropinv+0xf9>
mov    %ebp,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xf5c(%rip),%r13
lea    0x4(%rsp),%rbx
lea    0x30(%rsp),%rbp
lea    0xc(%rsp),%r12
jmp    11d4 <dropinv+0x94>
nopw   0x0(%rax,%rax,1)
xor    %r14d,%r14d
lea    0xeac(%rip),%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,0x4(%rsp)
cmp    $0xffffffff,%r14d
je     124c <dropinv+0x10c>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <getint@plt>
mov    0x4(%rsp),%eax
cmp    $0xa,%rax
jae    11b0 <dropinv+0x70>
mov    (%r15,%rax,4),%esi
mov    %rbp,%rdi
call   1060 <nameitem@plt>
lea    0xea2(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
call   1050 <getint@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     122c <dropinv+0xec>
cmp    $0x1,%eax
je     1267 <dropinv+0x127>
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%r14d
cmp    $0xffffffff,%r14d
jne    11d4 <dropinv+0x94>
jmp    124c <dropinv+0x10c>
lea    0xe0e(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
call   1030 <puts@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe63(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x30(%rsp),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0x4(%rsp),%rax
mov    0x8(%rsp),%ecx
mov    %ecx,(%r15,%rax,4)
jmp    1258 <dropinv+0x118>

LLVM IR (-O0):
@.str = [78 x i8] c"Your bag is full! Do you want to drop something to keep %s?\0A[0]: No\0A[1]: Yes\0A\00"
@.str.1 = [24 x i8] c"You don't keep the %s.\0A\00"
@.str.2 = [27 x i8] c"What do you want to drop?\0A\00"
@.str.3 = [61 x i8] c"You don't have that slot! Insert a number between 0 and %d!\0A\00"
@.str.4 = [46 x i8] c"Do you want to drop the %s?\0A[0]: No\0A[1]: Yes\0A\00"
@.str.5 = [36 x i8] c"You dropped the %s to keep the %s.\0A\00"
@.str.6 = [41 x i8] c"You don't have all the day to decide...\0A\00"
define void @dropinv(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* %4
%11 = call i32 @nameitem(i8* %9, i32 %10)
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @getint(i32* %5)
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %65
20: ; preds = %2
store i32 0, i32* %5
br label %21
21: ; preds = %61, %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @getint(i32* %5)
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i32, i32* %5
%28 = icmp sge i32 %27, 10
br i1 %28, label %29, label %31
29: ; preds = %26, %21
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i32 9)
store i32 0, i32* %5
br label %60
31: ; preds = %26
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%33 = load i32*, i32** %3
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @nameitem(i8* %32, i32 %37)
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = call i32 @getint(i32* %8)
%42 = load i32, i32* %8
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %53
44: ; preds = %31
%45 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %45, i8* %46)
%48 = load i32, i32* %4
%49 = load i32*, i32** %3
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
store i32 %48, i32* %52
store i32 -1, i32* %5
br label %67
53: ; preds = %31
%54 = load i32, i32* %8
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %53
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0))
br label %58
58: ; preds = %56, %53
br label %59
59: ; preds = %58
br label %60
60: ; preds = %59, %29
br label %61
61: ; preds = %60
%62 = load i32, i32* %5
%63 = icmp ne i32 %62, -1
br i1 %63, label %21, label %64
64: ; preds = %61
br label %65
65: ; preds = %64, %17
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %67
67: ; preds = %65, %44
ret void
}

LLVM IR (-O2):
@.str = [78 x i8] c"Your bag is full! Do you want to drop something to keep %s?\0A[0]: No\0A[1]: Yes\0A\00"
@.str.1 = [24 x i8] c"You don't keep the %s.\0A\00"
@.str.3 = [61 x i8] c"You don't have that slot! Insert a number between 0 and %d!\0A\00"
@.str.4 = [46 x i8] c"Do you want to drop the %s?\0A[0]: No\0A[1]: Yes\0A\00"
@.str.5 = [36 x i8] c"You dropped the %s to keep the %s.\0A\00"
@str.7 = [26 x i8] c"What do you want to drop?\00"
@str.8 = [40 x i8] c"You don't have all the day to decide...\00"
define void @dropinv(i32* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = alloca [20 x i8]
%5 = alloca [20 x i8]
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%10 = call i32 @nameitem(i8* %8, i32 %1)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0), i8* %8)
%12 = call i32 @getint(i32* %3)
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %46
17: ; preds = %2
store i32 0, i32* %3
%18 = bitcast i32* %6 to i8*
br label %19
19: ; preds = %43, %17
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
%21 = call i32 @getint(i32* %3)
%22 = load i32, i32* %3
%23 = icmp ugt i32 %22, 9
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i32 9)
store i32 0, i32* %3
br label %43
26: ; preds = %19
%27 = zext i32 %22 to i64
%28 = getelementptr inbounds i32, i32* %0, i64 %27
%29 = load i32, i32* %28
%30 = call i32 @nameitem(i8* %9, i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%32 = call i32 @getint(i32* %6)
%33 = load i32, i32* %6
switch i32 %33, label %34 [
i32 1, label %38
i32 0, label %36
]
34: ; preds = %26
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.8, i64 0, i64 0))
br label %36
36: ; preds = %26, %34
%37 = load i32, i32* %3
br label %43
38: ; preds = %26
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %8, i8* %9)
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %0, i64 %41
store i32 %1, i32* %42
br label %48
43: ; preds = %36, %24
%44 = phi i32 [ %37, %36 ], [ 0, %24 ]
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %19
46: ; preds = %43, %15
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
br label %48
48: ; preds = %38, %46
ret void
}