#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 */
scalar_t__ EAGAIN;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ Yamete(char *);
scalar_t__ errno;
int read(int /*<<< orphan*/, char *, int);
char ReadKey() {
  int n;
  char c;
  while ((n = read(STDIN_FILENO, &c, 1)) != 1) {
    if (n == -1 && errno != EAGAIN) {
      Yamete("read");
    }
  }
  return c;
}


x86 assembly (clang, -O0):
<ReadKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x1,%eax
je     1180 <ReadKey+0x60>
cmpl   $0xffffffff,-0x4(%rbp)
jne    117b <ReadKey+0x5b>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%rax
je     117b <ReadKey+0x5b>
lea    0xe8a(%rip),%rdi
call   1040 <Yamete@plt>
jmp    1128 <ReadKey+0x8>
movsbl -0x5(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadKey>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%r15
lea    0xf(%rsp),%rbx
mov    0x2ea0(%rip),%r12
mov    0x2e81(%rip),%r13
lea    0xeb2(%rip),%r14
jmp    1155 <ReadKey+0x35>
cmp    $0x1,%eax
je     117e <ReadKey+0x5e>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0xffffffff,%eax
jne    1150 <ReadKey+0x30>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1155 <ReadKey+0x35>
mov    %r14,%rdi
call   1040 <Yamete@plt>
jmp    1155 <ReadKey+0x35>
mov    0xf(%rsp),%al
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [5 x i8] c"read\00"
define signext i8 @ReadKey() {
%1 = alloca i32
%2 = alloca i8
br label %3
3: ; preds = %16, %0
%4 = load i32, i32* @STDIN_FILENO
%5 = call i32 @read(i32 %4, i8* %2, i32 1)
store i32 %5, i32* %1
%6 = icmp ne i32 %5, 1
br i1 %6, label %7, label %17
7: ; preds = %3
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i64, i64* @errno
%12 = load i64, i64* @EAGAIN
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @Yamete(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %10, %7
br label %3
17: ; preds = %3
%18 = load i8, i8* %2
ret i8 %18
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@.str = [5 x i8] c"read\00"
define signext i8 @ReadKey() {
%1 = alloca i8
br label %2
2: ; preds = %5, %0
%3 = load i32, i32* @STDIN_FILENO
%4 = call i32 @read(i32 %3, i8* %1, i32 1)
switch i32 %4, label %5 [
i32 1, label %12
i32 -1, label %6
]
5: ; preds = %2, %10, %6
br label %2
6: ; preds = %2
%7 = load i64, i64* @errno
%8 = load i64, i64* @EAGAIN
%9 = icmp eq i64 %7, %8
br i1 %9, label %5, label %10
10: ; preds = %6
%11 = tail call i32 @Yamete(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %5
12: ; preds = %2
%13 = load i8, i8* %1
ret i8 %13
}