#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 */
typedef int /*<<< orphan*/ s;

/* Variables and functions */
int /*<<< orphan*/ getint(int *);
int magicconsume(int *, int *, int, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ nameenemy(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *);
void remotevision(int *aces, int *inv, int *map, int *nomag) {
  char s[20];
  memset(s, 0, sizeof(s));
  sprintf(s, "RemoteVision");
  int v = magicconsume(aces, inv, 1, s);
  if (v < 0)
    return;
  int k;
  int r;
  for (k = 0; k < v; k++) {
    r = -1;
    do {
      printf("You can peek into any chamber. You can do this %d times.\n",
             v - k);
      getint(&r);
      if ((r < 0) || (r > 11))
        r = -1;
      else {
        if (*(map + r) == -1)
          printf("There are stairs here.\n");
        else if (*(map + r) <= 0)
          printf("It's empty.\n");
        else {
          nameenemy(s, *(map + r));
          int v = *(map + r);
          v = v % 13;
          if ((v < 1) || (v > 10))
            v = 10;
          else
            v = v + 1;
          printf("There is a %s with %d HP.\n", s, v);
        }
      }
    } while (r == -1);
  }
  if (nomag)
    *nomag = 1;
}


x86 assembly (clang, -O0):
<remotevision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x40(%rbp),%rcx
mov    $0x1,%edx
call   1040 <magicconsume@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    11c0 <remotevision+0x60>
jmp    1310 <remotevision+0x1b0>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    12fb <remotevision+0x19b>
movl   $0xffffffff,-0x4c(%rbp)
mov    -0x44(%rbp),%esi
sub    -0x48(%rbp),%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x4c(%rbp),%rdi
call   1060 <getint@plt>
cmpl   $0x0,-0x4c(%rbp)
jl     120b <remotevision+0xab>
cmpl   $0xb,-0x4c(%rbp)
jle    1217 <remotevision+0xb7>
movl   $0xffffffff,-0x4c(%rbp)
jmp    12d9 <remotevision+0x179>
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
jne    123c <remotevision+0xdc>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d4 <remotevision+0x174>
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jg     1261 <remotevision+0x101>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12cf <remotevision+0x16f>
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1080 <nameenemy@plt>
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x50(%rbp)
mov    -0x50(%rbp),%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
mov    %edx,-0x50(%rbp)
cmpl   $0x1,-0x50(%rbp)
jl     12a5 <remotevision+0x145>
cmpl   $0xa,-0x50(%rbp)
jle    12b1 <remotevision+0x151>
movl   $0xa,-0x50(%rbp)
jmp    12ba <remotevision+0x15a>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
lea    -0x40(%rbp),%rsi
mov    -0x50(%rbp),%edx
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d4 <remotevision+0x174>
jmp    12d9 <remotevision+0x179>
jmp    12de <remotevision+0x17e>
cmpl   $0xffffffff,-0x4c(%rbp)
je     11da <remotevision+0x7a>
jmp    12ed <remotevision+0x18d>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11c7 <remotevision+0x67>
cmpq   $0x0,-0x20(%rbp)
je     1310 <remotevision+0x1b0>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remotevision>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
movabs $0x695665746f6d6552,%rax
65 56 69
mov    %rax,0x10(%rsp)
movabs $0x6e6f6973695665,%rax
mov    %rax,0x15(%rsp)
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <magicconsume@plt>
test   %eax,%eax
js     12d2 <remotevision+0x172>
mov    %r12,0x8(%rsp)
je     12c2 <remotevision+0x162>
mov    %eax,%r13d
lea    0xe31(%rip),%r12
mov    %rsp,%rbp
lea    0x10(%rsp),%r14
xor    %r15d,%r15d
mov    %eax,0x4(%rsp)
jmp    1202 <remotevision+0xa2>
nopl   (%rax)
add    $0x1,%r15d
mov    0x4(%rsp),%r13d
cmp    %r13d,%r15d
je     12c2 <remotevision+0x162>
movl   $0xffffffff,(%rsp)
sub    %r15d,%r13d
jmp    1221 <remotevision+0xc1>
xchg   %ax,%ax
movl   $0xffffffff,(%rsp)
mov    $0xffffffff,%eax
cmp    $0xffffffff,%eax
jne    11f0 <remotevision+0x90>
mov    %r12,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1070 <getint@plt>
mov    (%rsp),%eax
cmp    $0xc,%rax
jae    1210 <remotevision+0xb0>
mov    (%rbx,%rax,4),%esi
cmp    $0xffffffff,%esi
je     129c <remotevision+0x13c>
test   %esi,%esi
jle    12a5 <remotevision+0x145>
mov    %r14,%rdi
call   1080 <nameenemy@plt>
movslq (%rsp),%rax
movslq (%rbx,%rax,4),%rax
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%edx
lea    (%rcx,%rdx,4),%ecx
sub    %ecx,%eax
lea    -0xb(%rax),%ecx
mov    $0xa,%edx
cmp    $0xfffffff6,%ecx
jb     1289 <remotevision+0x129>
add    $0x1,%eax
mov    %eax,%edx
lea    0xdb7(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12b1 <remotevision+0x151>
lea    0xdcb(%rip),%rdi
jmp    12ac <remotevision+0x14c>
lea    0xdb6(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%eax
cmp    $0xffffffff,%eax
je     1221 <remotevision+0xc1>
jmp    11f0 <remotevision+0x90>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     12d2 <remotevision+0x172>
movl   $0x1,(%rax)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"RemoteVision\00"
@.str.1 = [58 x i8] c"You can peek into any chamber. You can do this %d times.\0A\00"
@.str.2 = [24 x i8] c"There are stairs here.\0A\00"
@.str.3 = [13 x i8] c"It's empty.\0A\00"
@.str.4 = [27 x i8] c"There is a %s with %d HP.\0A\00"
define void @remotevision(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [20 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 20)
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%17 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%18 = load i32*, i32** %5
%19 = load i32*, i32** %6
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%21 = call i32 @magicconsume(i32* %18, i32* %19, i32 1, i8* %20)
store i32 %21, i32* %10
%22 = load i32, i32* %10
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %4
br label %104
25: ; preds = %4
store i32 0, i32* %11
br label %26
26: ; preds = %96, %25
%27 = load i32, i32* %11
%28 = load i32, i32* %10
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %99
30: ; preds = %26
store i32 -1, i32* %12
br label %31
31: ; preds = %92, %30
%32 = load i32, i32* %10
%33 = load i32, i32* %11
%34 = sub nsw i32 %32, %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = call i32 @getint(i32* %12)
%37 = load i32, i32* %12
%38 = icmp slt i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %31
%40 = load i32, i32* %12
%41 = icmp sgt i32 %40, 11
br i1 %41, label %42, label %43
42: ; preds = %39, %31
store i32 -1, i32* %12
br label %91
43: ; preds = %39
%44 = load i32*, i32** %7
%45 = load i32, i32* %12
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %90
52: ; preds = %43
%53 = load i32*, i32** %7
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
%58 = icmp sle i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %52
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %89
61: ; preds = %52
%62 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%63 = load i32*, i32** %7
%64 = load i32, i32* %12
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32, i32* %66
%68 = call i32 @nameenemy(i8* %62, i32 %67)
%69 = load i32*, i32** %7
%70 = load i32, i32* %12
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i32, i32* %69, i64 %71
%73 = load i32, i32* %72
store i32 %73, i32* %13
%74 = load i32, i32* %13
%75 = srem i32 %74, 13
store i32 %75, i32* %13
%76 = load i32, i32* %13
%77 = icmp slt i32 %76, 1
br i1 %77, label %81, label %78
78: ; preds = %61
%79 = load i32, i32* %13
%80 = icmp sgt i32 %79, 10
br i1 %80, label %81, label %82
81: ; preds = %78, %61
store i32 10, i32* %13
br label %85
82: ; preds = %78
%83 = load i32, i32* %13
%84 = add nsw i32 %83, 1
store i32 %84, i32* %13
br label %85
85: ; preds = %82, %81
%86 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%87 = load i32, i32* %13
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %86, i32 %87)
br label %89
89: ; preds = %85, %59
br label %90
90: ; preds = %89, %50
br label %91
91: ; preds = %90, %42
br label %92
92: ; preds = %91
%93 = load i32, i32* %12
%94 = icmp eq i32 %93, -1
br i1 %94, label %31, label %95
95: ; preds = %92
br label %96
96: ; preds = %95
%97 = load i32, i32* %11
%98 = add nsw i32 %97, 1
store i32 %98, i32* %11
br label %26
99: ; preds = %26
%100 = load i32*, i32** %8
%101 = icmp ne i32* %100, null
br i1 %101, label %102, label %104
102: ; preds = %99
%103 = load i32*, i32** %8
store i32 1, i32* %103
br label %104
104: ; preds = %24, %102, %99
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"RemoteVision\00"
@.str.1 = [58 x i8] c"You can peek into any chamber. You can do this %d times.\0A\00"
@.str.4 = [27 x i8] c"There is a %s with %d HP.\0A\00"
@str = [12 x i8] c"It's empty.\00"
@str.5 = [23 x i8] c"There are stairs here.\00"
define void @remotevision(i32* %0, i32* %1, i32* nocapture %2, i32* writeonly %3) {
%5 = alloca [20 x i8]
%6 = alloca i32
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 20)
%9 = call i32 @magicconsume(i32* %0, i32* %1, i32 1, i8* %7)
%10 = icmp slt i32 %9, 0
br i1 %10, label %58, label %11
11: ; preds = %4
%12 = bitcast i32* %6 to i8*
%13 = icmp eq i32 %9, 0
br i1 %13, label %54, label %14
14: ; preds = %11, %51
%15 = phi i32 [ %52, %51 ], [ 0, %11 ]
store i32 -1, i32* %6
%16 = sub nsw i32 %9, %15
br label %17
17: ; preds = %48, %14
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%19 = call i32 @getint(i32* %6)
%20 = load i32, i32* %6
%21 = icmp ugt i32 %20, 11
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 -1, i32* %6
br label %48
23: ; preds = %17
%24 = zext i32 %20 to i64
%25 = getelementptr inbounds i32, i32* %2, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
br label %46
30: ; preds = %23
%31 = icmp slt i32 %26, 1
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %46
34: ; preds = %30
%35 = call i32 @nameenemy(i8* %7, i32 %26)
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %2, i64 %37
%39 = load i32, i32* %38
%40 = srem i32 %39, 13
%41 = add nsw i32 %40, -11
%42 = icmp ult i32 %41, -10
%43 = add nsw i32 %40, 1
%44 = select i1 %42, i32 10, i32 %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %7, i32 %44)
br label %46
46: ; preds = %28, %34, %32
%47 = load i32, i32* %6
br label %48
48: ; preds = %46, %22
%49 = phi i32 [ %47, %46 ], [ -1, %22 ]
%50 = icmp eq i32 %49, -1
br i1 %50, label %17, label %51
51: ; preds = %48
%52 = add nuw nsw i32 %15, 1
%53 = icmp eq i32 %52, %9
br i1 %53, label %54, label %14
54: ; preds = %51, %11
%55 = icmp eq i32* %3, null
br i1 %55, label %57, label %56
56: ; preds = %54
store i32 1, i32* %3
br label %57
57: ; preds = %56, %54
br label %58
58: ; preds = %4, %57
ret void
}