#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 */
struct termio {
  int c_lflag;
  int *c_cc;
};

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ TCGETA;
int /*<<< orphan*/ TCSETA;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int /*<<< orphan*/, int /*<<< orphan*/,
                         struct termio *);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char inkey(void) {
  char c;
  struct termio param_ant, params;
  ioctl(0, TCGETA, &param_ant);
  params = param_ant;
  params.c_lflag &= ~(ICANON | ECHO);
  params.c_cc[4] = 1;
  ioctl(0, TCSETA, &params);
  fflush(stdin);
  fflush(stderr);
  fflush(stdout);
  read(0, &c, 1);
  ioctl(0, TCSETA, &param_ant);
  return c;
}


x86 assembly (clang, -O0):
<inkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    0x2e6c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x1,0x10(%rax)
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x28(%rbp),%rdx
call   1030 <ioctl@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %edi,%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inkey>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
lea    0x28(%rsp),%r14
xor    %edi,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
movups 0x28(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
mov    0x2e50(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    %ecx,0x10(%rsp)
mov    0x18(%rsp),%rax
movl   $0x1,0x10(%rax)
mov    0x2e34(%rip),%rbx
mov    (%rbx),%esi
lea    0x10(%rsp),%rdx
xor    %edi,%edi
call   1030 <ioctl@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <read@plt>
mov    (%rbx),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    0xf(%rsp),%al
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termio = type { i32, i32* }
@TCGETA = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSETA = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@stdout = global i32 0
define signext i8 @inkey() {
%1 = alloca i8
%2 = alloca %struct.termio
%3 = alloca %struct.termio
%4 = load i32, i32* @TCGETA
%5 = call i32 @ioctl(i32 0, i32 %4, %struct.termio* %2)
%6 = bitcast %struct.termio* %3 to i8*
%7 = bitcast %struct.termio* %2 to i8*
%8 = load i32, i32* @ICANON
%9 = load i32, i32* @ECHO
%10 = or i32 %8, %9
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termio, %struct.termio* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = getelementptr inbounds %struct.termio, %struct.termio* %3, i32 0, i32 1
%16 = load i32*, i32** %15
%17 = getelementptr inbounds i32, i32* %16, i64 4
store i32 1, i32* %17
%18 = load i32, i32* @TCSETA
%19 = call i32 @ioctl(i32 0, i32 %18, %struct.termio* %3)
%20 = load i32, i32* @stdin
%21 = call i32 @fflush(i32 %20)
%22 = load i32, i32* @stderr
%23 = call i32 @fflush(i32 %22)
%24 = load i32, i32* @stdout
%25 = call i32 @fflush(i32 %24)
%26 = call i32 @read(i32 0, i8* %1, i32 1)
%27 = load i32, i32* @TCSETA
%28 = call i32 @ioctl(i32 0, i32 %27, %struct.termio* %2)
%29 = load i8, i8* %1
ret i8 %29
}

LLVM IR (-O2):
%struct.termio = type { i32, i32* }
@TCGETA = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSETA = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@stdout = global i32 0
define signext i8 @inkey() {
%1 = alloca i8
%2 = alloca %struct.termio
%3 = alloca %struct.termio
%4 = bitcast %struct.termio* %2 to i8*
%5 = bitcast %struct.termio* %3 to i8*
%6 = load i32, i32* @TCGETA
%7 = call i32 @ioctl(i32 0, i32 %6, %struct.termio* %2)
%8 = load i32, i32* @ICANON
%9 = load i32, i32* @ECHO
%10 = or i32 %9, %8
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termio, %struct.termio* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = getelementptr inbounds %struct.termio, %struct.termio* %3, i64 0, i32 1
%16 = load i32*, i32** %15
%17 = getelementptr inbounds i32, i32* %16, i64 4
store i32 1, i32* %17
%18 = load i32, i32* @TCSETA
%19 = call i32 @ioctl(i32 0, i32 %18, %struct.termio* %3)
%20 = load i32, i32* @stdin
%21 = call i32 @fflush(i32 %20)
%22 = load i32, i32* @stderr
%23 = call i32 @fflush(i32 %22)
%24 = load i32, i32* @stdout
%25 = call i32 @fflush(i32 %24)
%26 = call i32 @read(i32 0, i8* %1, i32 1)
%27 = load i32, i32* @TCSETA
%28 = call i32 @ioctl(i32 0, i32 %27, %struct.termio* %2)
%29 = load i8, i8* %1
ret i8 %29
}