#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 COLS;
int ERR;
scalar_t__ LINES;
int /*<<< orphan*/ clear();
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getch();
int getchar();
int /*<<< orphan*/ initcurses();
int /*<<< orphan*/ initdollars();
int /*<<< orphan*/ initsnake();
int /*<<< orphan*/ mvprintw(int, int, char *);
int /*<<< orphan*/ napms(int);
int /*<<< orphan*/ refresh();
void endsnake() {
  int key;
  int center_y;
  refresh();
  napms(1000);
  while (!getch() == ERR) {
  }
  center_y = (int)LINES / 2;
  mvprintw(center_y - 1, COLS / 2 - 19,
           "You've hit your head against something!");
  mvprintw(center_y, COLS / 2 - 17, "Please press a key to continue dying");
  refresh();
  getchar();
  mvprintw(center_y + 2, COLS / 2 - 7, "You have died.");
  refresh();
  getchar();
  clear();
  mvprintw(center_y, COLS / 2 - 17, "Would you like to play again? (Y/N)");
  refresh();
  key = getchar();
  if (key == 'N' || key == 'n') {
    endwin();
    exit(0);
  } else {
    clear();
    endwin();
    initcurses();
    initsnake();
    initdollars();
  }
}


x86 assembly (clang, -O0):
<endsnake>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <refresh@plt>
mov    $0x3e8,%edi
call   10b0 <napms@plt>
mov    $0x0,%al
call   1080 <getch@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    0x2e04(%rip),%rcx
cmp    (%rcx),%eax
jne    11f1 <endsnake+0x41>
jmp    11c9 <endsnake+0x19>
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
sub    $0x13,%esi
lea    0xdd7(%rip),%rdx
call   10d0 <mvprintw@plt>
mov    -0x8(%rbp),%edi
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
sub    $0x11,%esi
lea    0xdda(%rip),%rdx
call   10d0 <mvprintw@plt>
mov    $0x0,%al
call   1070 <refresh@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    -0x8(%rbp),%edi
add    $0x2,%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
sub    $0x7,%esi
lea    0xdc9(%rip),%rdx
call   10d0 <mvprintw@plt>
mov    $0x0,%al
call   1070 <refresh@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    $0x0,%al
call   10c0 <clear@plt>
mov    -0x8(%rbp),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
sub    $0x11,%esi
lea    0xd9e(%rip),%rdx
call   10d0 <mvprintw@plt>
mov    $0x0,%al
call   1070 <refresh@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x4e,-0x4(%rbp)
je     12e8 <endsnake+0x138>
cmpl   $0x6e,-0x4(%rbp)
jne    12f6 <endsnake+0x146>
mov    $0x0,%al
call   1090 <endwin@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10c0 <clear@plt>
mov    $0x0,%al
call   1090 <endwin@plt>
mov    $0x0,%al
call   1050 <initcurses@plt>
mov    $0x0,%al
call   1030 <initsnake@plt>
mov    $0x0,%al
call   1060 <initdollars@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endsnake>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <refresh@plt>
mov    $0x3e8,%edi
call   10b0 <napms@plt>
mov    0x2e1c(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <getch@plt>
xor    %ecx,%ecx
test   %eax,%eax
sete   %cl
cmp    %ecx,(%rbx)
je     11d0 <endsnake+0x20>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
lea    -0x1(%rbx),%edi
mov    0x2dda(%rip),%r14
mov    (%r14),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
add    $0xffffffed,%esi
lea    0xdec(%rip),%rdx
call   10d0 <mvprintw@plt>
mov    (%r14),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
add    $0xffffffef,%esi
lea    0xdf9(%rip),%rdx
mov    %ebx,%edi
call   10d0 <mvprintw@plt>
xor    %eax,%eax
call   1070 <refresh@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
lea    0x2(%rbx),%edi
mov    (%r14),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
add    $0xfffffff9,%esi
lea    0xdf0(%rip),%rdx
call   10d0 <mvprintw@plt>
xor    %eax,%eax
call   1070 <refresh@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %eax,%eax
call   10c0 <clear@plt>
mov    (%r14),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
add    $0xffffffef,%esi
lea    0xdcf(%rip),%rdx
mov    %ebx,%edi
call   10d0 <mvprintw@plt>
xor    %eax,%eax
call   1070 <refresh@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
and    $0xffffffdf,%eax
cmp    $0x4e,%eax
je     12d4 <endsnake+0x124>
xor    %eax,%eax
call   10c0 <clear@plt>
xor    %eax,%eax
call   1090 <endwin@plt>
xor    %eax,%eax
call   1050 <initcurses@plt>
xor    %eax,%eax
call   1030 <initsnake@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <initdollars@plt>
xor    %eax,%eax
call   1090 <endwin@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@ERR = global i32 0
@LINES = global i64 0
@COLS = global i32 0
@.str = [40 x i8] c"You've hit your head against something!\00"
@.str.1 = [37 x i8] c"Please press a key to continue dying\00"
@.str.2 = [15 x i8] c"You have died.\00"
@.str.3 = [36 x i8] c"Would you like to play again? (Y/N)\00"
define void @endsnake() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @refresh()
%4 = call i32 @napms(i32 1000)
br label %5
5: ; preds = %12, %0
%6 = call i32 (...) @getch()
%7 = icmp ne i32 %6, 0
%8 = xor i1 %7, true
%9 = zext i1 %8 to i32
%10 = load i32, i32* @ERR
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %5
br label %5
13: ; preds = %5
%14 = load i64, i64* @LINES
%15 = trunc i64 %14 to i32
%16 = sdiv i32 %15, 2
store i32 %16, i32* %2
%17 = load i32, i32* %2
%18 = sub nsw i32 %17, 1
%19 = load i32, i32* @COLS
%20 = sdiv i32 %19, 2
%21 = sub nsw i32 %20, 19
%22 = call i32 @mvprintw(i32 %18, i32 %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* %2
%24 = load i32, i32* @COLS
%25 = sdiv i32 %24, 2
%26 = sub nsw i32 %25, 17
%27 = call i32 @mvprintw(i32 %23, i32 %26, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 (...) @refresh()
%29 = call i32 (...) @getchar()
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 2
%32 = load i32, i32* @COLS
%33 = sdiv i32 %32, 2
%34 = sub nsw i32 %33, 7
%35 = call i32 @mvprintw(i32 %31, i32 %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 (...) @refresh()
%37 = call i32 (...) @getchar()
%38 = call i32 (...) @clear()
%39 = load i32, i32* %2
%40 = load i32, i32* @COLS
%41 = sdiv i32 %40, 2
%42 = sub nsw i32 %41, 17
%43 = call i32 @mvprintw(i32 %39, i32 %42, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 (...) @refresh()
%45 = call i32 (...) @getchar()
store i32 %45, i32* %1
%46 = load i32, i32* %1
%47 = icmp eq i32 %46, 78
br i1 %47, label %51, label %48
48: ; preds = %13
%49 = load i32, i32* %1
%50 = icmp eq i32 %49, 110
br i1 %50, label %51, label %54
51: ; preds = %48, %13
%52 = call i32 (...) @endwin()
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %48
%55 = call i32 (...) @clear()
%56 = call i32 (...) @endwin()
%57 = call i32 (...) @initcurses()
%58 = call i32 (...) @initsnake()
%59 = call i32 (...) @initdollars()
br label %60
60: ; preds = %54
ret void
}

LLVM IR (-O2):
@ERR = global i32 0
@LINES = global i64 0
@COLS = global i32 0
@.str = [40 x i8] c"You've hit your head against something!\00"
@.str.1 = [37 x i8] c"Please press a key to continue dying\00"
@.str.2 = [15 x i8] c"You have died.\00"
@.str.3 = [36 x i8] c"Would you like to play again? (Y/N)\00"
define void @endsnake() {
%1 = tail call i32 (...) @refresh()
%2 = tail call i32 @napms(i32 1000)
br label %3
3: ; preds = %3, %0
%4 = tail call i32 (...) @getch()
%5 = icmp eq i32 %4, 0
%6 = zext i1 %5 to i32
%7 = load i32, i32* @ERR
%8 = icmp eq i32 %7, %6
br i1 %8, label %3, label %9
9: ; preds = %3
%10 = load i64, i64* @LINES
%11 = trunc i64 %10 to i32
%12 = sdiv i32 %11, 2
%13 = add nsw i32 %12, -1
%14 = load i32, i32* @COLS
%15 = sdiv i32 %14, 2
%16 = add nsw i32 %15, -19
%17 = tail call i32 @mvprintw(i32 %13, i32 %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @COLS
%19 = sdiv i32 %18, 2
%20 = add nsw i32 %19, -17
%21 = tail call i32 @mvprintw(i32 %12, i32 %20, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 (...) @refresh()
%23 = tail call i32 (...) @getchar()
%24 = add nsw i32 %12, 2
%25 = load i32, i32* @COLS
%26 = sdiv i32 %25, 2
%27 = add nsw i32 %26, -7
%28 = tail call i32 @mvprintw(i32 %24, i32 %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 (...) @refresh()
%30 = tail call i32 (...) @getchar()
%31 = tail call i32 (...) @clear()
%32 = load i32, i32* @COLS
%33 = sdiv i32 %32, 2
%34 = add nsw i32 %33, -17
%35 = tail call i32 @mvprintw(i32 %12, i32 %34, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%36 = tail call i32 (...) @refresh()
%37 = tail call i32 (...) @getchar()
%38 = and i32 %37, -33
%39 = icmp eq i32 %38, 78
br i1 %39, label %40, label %43
40: ; preds = %9
%41 = tail call i32 (...) @endwin()
%42 = tail call i32 @exit(i32 0)
unreachable
43: ; preds = %9
%44 = tail call i32 (...) @clear()
%45 = tail call i32 (...) @endwin()
%46 = tail call i32 (...) @initcurses()
%47 = tail call i32 (...) @initsnake()
%48 = tail call i32 (...) @initdollars()
ret void
}