#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*/ drawbox(int **, char *, int);
char getchar();
int /*<<< orphan*/ isalpha(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *, int *);
char tolower(char);
int endgame(int b[][8 + 2], char h[], int *s) {
  int c, x, y;
  char input;
  printf("Do you want to guess now? (y/n) ");
  while (!isalpha(input = getchar()))
    ;
  if (tolower(input) != 'y') {
    drawbox(b, h, 1);
    return 0;
  }
  drawbox(b, h, 2);
  for (c = 0; c < 4; c++) {
    printf("What is the location of atom #%d? <x,y> ", c + 1);
    scanf("%d %*c %d", &x, &y);
    if (b[x][y] == 1) {
      puts("\nCorrect");
      b[x][y] = 10;
    } else {
      puts("\nIncorrect. Plus 5 points.");
      *s += 5;
    }
  }
  drawbox(b, h, 3);
  printf("\nYour final score : %d\nHere's the Blackbox.\n  ", *s);
  return 1;
}


x86 assembly (clang, -O0):
<endgame>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x2d(%rbp)
movsbl %al,%edi
call   1080 <isalpha@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b9 <endgame+0x49>
jmp    11be <endgame+0x4e>
jmp    1192 <endgame+0x22>
movsbl -0x2d(%rbp),%edi
call   1060 <tolower@plt>
movsbl %al,%eax
cmp    $0x79,%eax
je     11f1 <endgame+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1070 <drawbox@plt>
movl   $0x0,-0x4(%rbp)
jmp    12db <endgame+0x16b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x2,%edx
call   1070 <drawbox@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    12ae <endgame+0x13e>
mov    -0x24(%rbp),%esi
add    $0x1,%esi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1b(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1090 <scanf@plt>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
imul   $0x28,%rcx,%rcx
add    %rcx,%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1284 <endgame+0x114>
lea    0xdf4(%rip),%rdi
call   1030 <puts@plt>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
imul   $0x28,%rcx,%rcx
add    %rcx,%rax
movslq -0x2c(%rbp),%rcx
movl   $0xa,(%rax,%rcx,4)
jmp    129b <endgame+0x12b>
lea    0xdd2(%rip),%rdi
call   1030 <puts@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x5,%ecx
mov    %ecx,(%rax)
jmp    12a0 <endgame+0x130>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120a <endgame+0x9a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x3,%edx
call   1070 <drawbox@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endgame>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe79(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
movsbl %al,%ebp
mov    %ebp,%edi
call   1080 <isalpha@plt>
test   %eax,%eax
je     1190 <endgame+0x20>
mov    %ebp,%edi
call   1060 <tolower@plt>
cmp    $0x79,%al
jne    1224 <endgame+0xb4>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1070 <drawbox@plt>
lea    0xe5a(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe70(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1090 <scanf@plt>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,4),%rax
lea    (%rbx,%rax,8),%rax
cmpl   $0x1,(%rax,%rcx,4)
jne    123b <endgame+0xcb>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,4),%rax
lea    (%rbx,%rax,8),%rax
movl   $0xa,(%rax,%rcx,4)
jmp    124b <endgame+0xdb>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <drawbox@plt>
xor    %eax,%eax
jmp    13cd <endgame+0x25d>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
addl   $0x5,(%r15)
lea    0xdcf(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xde5(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1090 <scanf@plt>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,4),%rax
lea    (%rbx,%rax,8),%rax
cmpl   $0x1,(%rax,%rcx,4)
jne    12af <endgame+0x13f>
lea    0xdc4(%rip),%rdi
call   1030 <puts@plt>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,4),%rax
lea    (%rbx,%rax,8),%rax
movl   $0xa,(%rax,%rcx,4)
jmp    12bf <endgame+0x14f>
lea    0xda7(%rip),%rdi
call   1030 <puts@plt>
addl   $0x5,(%r15)
lea    0xd5b(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd71(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1090 <scanf@plt>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,4),%rax
lea    (%rbx,%rax,8),%rax
cmpl   $0x1,(%rax,%rcx,4)
jne    1323 <endgame+0x1b3>
lea    0xd50(%rip),%rdi
call   1030 <puts@plt>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,4),%rax
lea    (%rbx,%rax,8),%rax
movl   $0xa,(%rax,%rcx,4)
jmp    1333 <endgame+0x1c3>
lea    0xd33(%rip),%rdi
call   1030 <puts@plt>
addl   $0x5,(%r15)
lea    0xce7(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xcfd(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1090 <scanf@plt>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,4),%rax
lea    (%rbx,%rax,8),%rax
cmpl   $0x1,(%rax,%rcx,4)
jne    1397 <endgame+0x227>
lea    0xcdc(%rip),%rdi
call   1030 <puts@plt>
movslq 0x4(%rsp),%rax
movslq (%rsp),%rcx
lea    (%rax,%rax,4),%rax
lea    (%rbx,%rax,8),%rax
movl   $0xa,(%rax,%rcx,4)
jmp    13a7 <endgame+0x237>
lea    0xcbf(%rip),%rdi
call   1030 <puts@plt>
addl   $0x5,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1070 <drawbox@plt>
mov    (%r15),%esi
lea    0xcb7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Do you want to guess now? (y/n) \00"
@.str.1 = [41 x i8] c"What is the location of atom #%d? <x,y> \00"
@.str.2 = [10 x i8] c"%d %*c %d\00"
@.str.3 = [9 x i8] c"\0ACorrect\00"
@.str.4 = [27 x i8] c"\0AIncorrect. Plus 5 points.\00"
@.str.5 = [47 x i8] c"\0AYour final score : %d\0AHere's the Blackbox.\0A \00"
define i32 @endgame([10 x i32]* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca [10 x i32]*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
store [10 x i32]* %0, [10 x i32]** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %18, %3
%14 = call signext i8 (...) @getchar()
store i8 %14, i8* %11
%15 = call i32 @isalpha(i8 signext %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %19
18: ; preds = %13
br label %13
19: ; preds = %13
%20 = load i8, i8* %11
%21 = call signext i8 @tolower(i8 signext %20)
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 121
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load [10 x i32]*, [10 x i32]** %5
%26 = bitcast [10 x i32]* %25 to i32**
%27 = load i8*, i8** %6
%28 = call i32 @drawbox(i32** %26, i8* %27, i32 1)
store i32 0, i32* %4
br label %77
29: ; preds = %19
%30 = load [10 x i32]*, [10 x i32]** %5
%31 = bitcast [10 x i32]* %30 to i32**
%32 = load i8*, i8** %6
%33 = call i32 @drawbox(i32** %31, i8* %32, i32 2)
store i32 0, i32* %8
br label %34
34: ; preds = %66, %29
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 4
br i1 %36, label %37, label %69
37: ; preds = %34
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %9, i32* %10)
%42 = load [10 x i32]*, [10 x i32]** %5
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [10 x i32], [10 x i32]* %42, i64 %44
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %45, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %60
51: ; preds = %37
%52 = call i32 @puts(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%53 = load [10 x i32]*, [10 x i32]** %5
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [10 x i32], [10 x i32]* %53, i64 %55
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [10 x i32], [10 x i32]* %56, i64 0, i64 %58
store i32 10, i32* %59
br label %65
60: ; preds = %37
%61 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%62 = load i32*, i32** %7
%63 = load i32, i32* %62
%64 = add nsw i32 %63, 5
store i32 %64, i32* %62
br label %65
65: ; preds = %60, %51
br label %66
66: ; preds = %65
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %34
69: ; preds = %34
%70 = load [10 x i32]*, [10 x i32]** %5
%71 = bitcast [10 x i32]* %70 to i32**
%72 = load i8*, i8** %6
%73 = call i32 @drawbox(i32** %71, i8* %72, i32 3)
%74 = load i32*, i32** %7
%75 = load i32, i32* %74
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %75)
store i32 1, i32* %4
br label %77
77: ; preds = %69, %24
%78 = load i32, i32* %4
ret i32 %78
}

LLVM IR (-O2):
@.str = [33 x i8] c"Do you want to guess now? (y/n) \00"
@.str.1 = [41 x i8] c"What is the location of atom #%d? <x,y> \00"
@.str.2 = [10 x i8] c"%d %*c %d\00"
@.str.3 = [9 x i8] c"\0ACorrect\00"
@.str.4 = [27 x i8] c"\0AIncorrect. Plus 5 points.\00"
@.str.5 = [47 x i8] c"\0AYour final score : %d\0AHere's the Blackbox.\0A \00"
define i32 @endgame([10 x i32]* %0, i8* %1, i32* nocapture %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %9, %3
%10 = tail call signext i8 (...) @getchar()
%11 = tail call i32 @isalpha(i8 signext %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %9, label %13
13: ; preds = %9
%14 = tail call signext i8 @tolower(i8 signext %10)
%15 = icmp eq i8 %14, 121
%16 = bitcast [10 x i32]* %0 to i32**
br i1 %15, label %19, label %17
17: ; preds = %13
%18 = tail call i32 @drawbox(i32** %16, i8* %1, i32 1)
br label %108
19: ; preds = %13
%20 = tail call i32 @drawbox(i32** %16, i8* %1, i32 2)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 1)
%22 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5)
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %0, i64 %24, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %37
30: ; preds = %19
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %0, i64 %33, i64 %35
store i32 10, i32* %36
br label %41
37: ; preds = %19
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 5
store i32 %40, i32* %2
br label %41
41: ; preds = %30, %37
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 2)
%43 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5)
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %0, i64 %45, i64 %47
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, 1
br i1 %50, label %55, label %51
51: ; preds = %41
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 5
store i32 %54, i32* %2
br label %62
55: ; preds = %41
%56 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%57 = load i32, i32* %4
%58 = sext i32 %57 to i64
%59 = load i32, i32* %5
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [10 x i32], [10 x i32]* %0, i64 %58, i64 %60
store i32 10, i32* %61
br label %62
62: ; preds = %55, %51
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 3)
%64 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5)
%65 = load i32, i32* %4
%66 = sext i32 %65 to i64
%67 = load i32, i32* %5
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [10 x i32], [10 x i32]* %0, i64 %66, i64 %68
%70 = load i32, i32* %69
%71 = icmp eq i32 %70, 1
br i1 %71, label %76, label %72
72: ; preds = %62
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32, i32* %2
%75 = add nsw i32 %74, 5
store i32 %75, i32* %2
br label %83
76: ; preds = %62
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%78 = load i32, i32* %4
%79 = sext i32 %78 to i64
%80 = load i32, i32* %5
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [10 x i32], [10 x i32]* %0, i64 %79, i64 %81
store i32 10, i32* %82
br label %83
83: ; preds = %76, %72
%84 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 4)
%85 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5)
%86 = load i32, i32* %4
%87 = sext i32 %86 to i64
%88 = load i32, i32* %5
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [10 x i32], [10 x i32]* %0, i64 %87, i64 %89
%91 = load i32, i32* %90
%92 = icmp eq i32 %91, 1
br i1 %92, label %97, label %93
93: ; preds = %83
%94 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%95 = load i32, i32* %2
%96 = add nsw i32 %95, 5
store i32 %96, i32* %2
br label %104
97: ; preds = %83
%98 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%99 = load i32, i32* %4
%100 = sext i32 %99 to i64
%101 = load i32, i32* %5
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [10 x i32], [10 x i32]* %0, i64 %100, i64 %102
store i32 10, i32* %103
br label %104
104: ; preds = %97, %93
%105 = call i32 @drawbox(i32** %16, i8* %1, i32 3)
%106 = load i32, i32* %2
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %106)
br label %108
108: ; preds = %104, %17
%109 = phi i32 [ 0, %17 ], [ 1, %104 ]
ret i32 %109
}