#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int waitForReturn(void) {
  char line[100];
  printf("press <enter> to continue, <esc> to break, q to quit: ");
  fflush(stdout);
  if (fgets(line, 100, stdin) == NULL) {
    printf("\n");
    exit(0);
  }
  if (line[0] == 'q') {
    exit(0);
  }
  if (line[0] == 0x1B) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<waitForReturn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    1196 <waitForReturn+0x56>
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
movsbl -0x70(%rbp),%eax
cmp    $0x71,%eax
jne    11aa <waitForReturn+0x6a>
xor    %edi,%edi
call   1060 <exit@plt>
movsbl -0x70(%rbp),%eax
cmp    $0x1b,%eax
jne    11c3 <waitForReturn+0x83>
movl   $0x1,-0x4(%rbp)
jmp    11ca <waitForReturn+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitForReturn>:
sub    $0x68,%rsp
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11a2 <waitForReturn+0x52>
mov    $0x1,%eax
mov    (%rsp),%cl
cmp    $0x1b,%cl
je     119d <waitForReturn+0x4d>
cmp    $0x71,%cl
je     11ac <waitForReturn+0x5c>
xor    %eax,%eax
add    $0x68,%rsp
ret
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [55 x i8] c"press <enter> to continue, <esc> to break, q to quit: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @waitForReturn() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdout
%5 = call i32 @fflush(i32 %4)
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %6, i32 100, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %0
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 113
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %13
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 27
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %1
br label %27
26: ; preds = %20
store i32 0, i32* %1
br label %27
27: ; preds = %26, %25
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@.str = [55 x i8] c"press <enter> to continue, <esc> to break, q to quit: \00"
@stdout = global i32 0
@stdin = global i32 0
define i32 @waitForReturn() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %2, i32 100, i32 %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @putchar(i32 10)
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = load i8, i8* %2
switch i8 %13, label %16 [
i8 113, label %14
i8 27, label %17
]
14: ; preds = %12
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %12
br label %17
17: ; preds = %12, %16
%18 = phi i32 [ 0, %16 ], [ 1, %12 ]
ret i32 %18
}