#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 char chtype;

/* Variables and functions */
int /*<<< orphan*/ FALSE;
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ cbreak();
char getch();
int /*<<< orphan*/ halfdelay(int);
int /*<<< orphan*/ nocbreak();
int /*<<< orphan*/ nodelay(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdscr;
int WaitForUser(void) {
  chtype ch;
  nodelay(stdscr, TRUE);
  halfdelay(50);
  ch = getch();
  nodelay(stdscr, FALSE);
  nocbreak();
  cbreak();
  return (ch == '\033') ? ch : 0;
}


x86 assembly (clang, -O0):
<WaitForUser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%edi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
call   1050 <nodelay@plt>
mov    $0x32,%edi
call   1040 <halfdelay@plt>
mov    $0x0,%al
call   1060 <getch@plt>
mov    %al,-0x1(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1050 <nodelay@plt>
mov    $0x0,%al
call   1070 <nocbreak@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
movsbl -0x1(%rbp),%eax
cmp    $0x1b,%eax
jne    11c1 <WaitForUser+0x71>
movsbl -0x1(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    11cb <WaitForUser+0x7b>
xor    %eax,%eax
mov    %eax,-0x8(%rbp)
jmp    11cb <WaitForUser+0x7b>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WaitForUser>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e8d(%rip),%r14
mov    (%r14),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
call   1050 <nodelay@plt>
mov    $0x32,%edi
call   1040 <halfdelay@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <getch@plt>
mov    %eax,%ebx
mov    (%r14),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1050 <nodelay@plt>
xor    %eax,%eax
call   1070 <nocbreak@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
cmp    $0x1b,%bl
mov    $0x1b,%eax
cmovne %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdscr = global i32 0
@TRUE = global i32 0
@FALSE = global i32 0
define i32 @WaitForUser() {
%1 = alloca i8
%2 = load i32, i32* @stdscr
%3 = load i32, i32* @TRUE
%4 = call i32 @nodelay(i32 %2, i32 %3)
%5 = call i32 @halfdelay(i32 50)
%6 = call signext i8 (...) @getch()
store i8 %6, i8* %1
%7 = load i32, i32* @stdscr
%8 = load i32, i32* @FALSE
%9 = call i32 @nodelay(i32 %7, i32 %8)
%10 = call i32 (...) @nocbreak()
%11 = call i32 (...) @cbreak()
%12 = load i8, i8* %1
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 27
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = load i8, i8* %1
%17 = sext i8 %16 to i32
br label %19
18: ; preds = %0
br label %19
19: ; preds = %18, %15
%20 = phi i32 [ %17, %15 ], [ 0, %18 ]
ret i32 %20
}

LLVM IR (-O2):
@stdscr = global i32 0
@TRUE = global i32 0
@FALSE = global i32 0
define i32 @WaitForUser() {
%1 = load i32, i32* @stdscr
%2 = load i32, i32* @TRUE
%3 = tail call i32 @nodelay(i32 %1, i32 %2)
%4 = tail call i32 @halfdelay(i32 50)
%5 = tail call signext i8 (...) @getch()
%6 = load i32, i32* @stdscr
%7 = load i32, i32* @FALSE
%8 = tail call i32 @nodelay(i32 %6, i32 %7)
%9 = tail call i32 (...) @nocbreak()
%10 = tail call i32 (...) @cbreak()
%11 = icmp eq i8 %5, 27
%12 = select i1 %11, i32 27, i32 0
ret i32 %12
}