#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 termios {
  int c_lflag;
};

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int _accacia_getch();
int /*<<< orphan*/ getc(int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
char _accacia_getkey() {
  int res;
  struct termios attr, oldattr;
  getc(stdout);
  tcgetattr(STDIN_FILENO, &attr);
  oldattr = attr;
  attr.c_lflag = ~(ICANON | ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &attr);
  res = _accacia_getch();
  tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
  return (res);
}


x86 assembly (clang, -O0):
<_accacia_getkey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
call   1060 <getc@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    0x2e62(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    $0x0,%al
call   1030 <_accacia_getch@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0x4(%rbp),%eax
movsbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_accacia_getkey>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1060 <getc@plt>
mov    0x2e6a(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1040 <tcgetattr@plt>
mov    (%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x2e46(%rip),%rax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
mov    %ecx,(%rsp)
mov    (%r14),%edi
mov    0x2e54(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
xor    %eax,%eax
call   1030 <_accacia_getch@plt>
mov    %eax,%ebx
mov    (%r14),%edi
mov    (%r15),%esi
lea    0x8(%rsp),%rdx
call   1050 <tcsetattr@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdout = global i32 0
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define signext i8 @_accacia_getkey() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = load i32, i32* @stdout
%5 = call i32 @getc(i32 %4)
%6 = load i32, i32* @STDIN_FILENO
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %2)
%8 = bitcast %struct.termios* %3 to i8*
%9 = bitcast %struct.termios* %2 to i8*
%10 = load i32, i32* @ICANON
%11 = load i32, i32* @ECHO
%12 = or i32 %10, %11
%13 = xor i32 %12, -1
%14 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @STDIN_FILENO
%16 = load i32, i32* @TCSANOW
%17 = call i32 @tcsetattr(i32 %15, i32 %16, %struct.termios* %2)
%18 = call i32 (...) @_accacia_getch()
store i32 %18, i32* %1
%19 = load i32, i32* @STDIN_FILENO
%20 = load i32, i32* @TCSANOW
%21 = call i32 @tcsetattr(i32 %19, i32 %20, %struct.termios* %3)
%22 = load i32, i32* %1
%23 = trunc i32 %22 to i8
ret i8 %23
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdout = global i32 0
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define signext i8 @_accacia_getkey() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %1 to i8*
%4 = bitcast %struct.termios* %2 to i8*
%5 = load i32, i32* @stdout
%6 = tail call i32 @getc(i32 %5)
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %1)
%9 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = load i32, i32* %9
store i32 %11, i32* %10
%12 = load i32, i32* @ICANON
%13 = load i32, i32* @ECHO
%14 = or i32 %13, %12
%15 = xor i32 %14, -1
store i32 %15, i32* %9
%16 = load i32, i32* @STDIN_FILENO
%17 = load i32, i32* @TCSANOW
%18 = call i32 @tcsetattr(i32 %16, i32 %17, %struct.termios* %1)
%19 = call i32 (...) @_accacia_getch()
%20 = load i32, i32* @STDIN_FILENO
%21 = load i32, i32* @TCSANOW
%22 = call i32 @tcsetattr(i32 %20, i32 %21, %struct.termios* %2)
%23 = trunc i32 %19 to i8
ret i8 %23
}