#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 /*<<< orphan*/ getc(int /*<<< orphan*/);
int /*<<< orphan*/ read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
unsigned char _accacia_getch() {
  unsigned char c;
  struct termios attr, oldattr;
  getc(stdout);
  tcgetattr(STDIN_FILENO, &attr);
  oldattr = attr;
  attr.c_lflag = ~(ICANON | ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &attr);
  read(STDIN_FILENO, &c, 1);
  tcsetattr(STDIN_FILENO, TCSANOW, &oldattr);
  return (c);
}


x86 assembly (clang, -O0):
<_accacia_getch>:
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    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_accacia_getch>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1060 <getc@plt>
mov    0x2e6a(%rip),%rbx
mov    (%rbx),%edi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x10(%rsp),%eax
mov    %eax,0x18(%rsp)
mov    0x2e44(%rip),%rax
mov    0x2e5d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
mov    %ecx,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2e52(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
mov    (%rbx),%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    (%rbx),%edi
mov    (%r15),%esi
lea    0x18(%rsp),%rdx
call   1050 <tcsetattr@plt>
mov    0xf(%rsp),%al
add    $0x20,%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 zeroext i8 @_accacia_getch() {
%1 = alloca i8
%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 = load i32, i32* @STDIN_FILENO
%19 = call i32 @read(i32 %18, i8* %1, i32 1)
%20 = load i32, i32* @STDIN_FILENO
%21 = load i32, i32* @TCSANOW
%22 = call i32 @tcsetattr(i32 %20, i32 %21, %struct.termios* %3)
%23 = load i8, i8* %1
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 zeroext i8 @_accacia_getch() {
%1 = alloca i8
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %2 to i8*
%5 = bitcast %struct.termios* %3 to i8*
%6 = load i32, i32* @stdout
%7 = tail call i32 @getc(i32 %6)
%8 = load i32, i32* @STDIN_FILENO
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %2)
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%12 = load i32, i32* %10
store i32 %12, i32* %11
%13 = load i32, i32* @ICANON
%14 = load i32, i32* @ECHO
%15 = or i32 %14, %13
%16 = xor i32 %15, -1
store i32 %16, i32* %10
%17 = load i32, i32* @STDIN_FILENO
%18 = load i32, i32* @TCSANOW
%19 = call i32 @tcsetattr(i32 %17, i32 %18, %struct.termios* %2)
%20 = load i32, i32* @STDIN_FILENO
%21 = call i32 @read(i32 %20, i8* %1, i32 1)
%22 = load i32, i32* @STDIN_FILENO
%23 = load i32, i32* @TCSANOW
%24 = call i32 @tcsetattr(i32 %22, i32 %23, %struct.termios* %3)
%25 = load i8, i8* %1
ret i8 %25
}