#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 /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ TCSANOW;
char getchar();
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
char get_char() {
  static struct termios old, new;
  char result;
  tcgetattr(0, &old);
  new = old;
  new.c_lflag &= ~ICANON;
  new.c_lflag &= ~ECHO;
  tcsetattr(0, TCSANOW, &new);
  result = getchar();
  tcsetattr(0, TCSANOW, &old);
  return result;
}


x86 assembly (clang, -O0):
<get_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
lea    0x2efb(%rip),%rsi
call   1040 <tcgetattr@plt>
mov    0x2ef0(%rip),%eax
mov    %eax,0x2eee(%rip)
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    0x2edc(%rip),%eax
mov    %eax,0x2ed6(%rip)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    0x2ec4(%rip),%eax
mov    %eax,0x2ebe(%rip)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0x2eac(%rip),%rdx
call   1050 <tcsetattr@plt>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x1(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    0x2e87(%rip),%rdx
call   1050 <tcsetattr@plt>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_char>:
push   %r15
push   %r14
push   %rbx
lea    0x2f00(%rip),%r14
xor    %edi,%edi
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    0x2e8a(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x2edc(%rip),%eax
mov    %eax,0x2eda(%rip)
lea    0x2ed3(%rip),%rdx
mov    0x2e74(%rip),%r15
mov    (%r15),%esi
xor    %edi,%edi
call   1050 <tcsetattr@plt>
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%ebx
mov    (%r15),%esi
xor    %edi,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@get_char.old = internal global %struct.termios zeroinitializer
@get_char.new = internal global %struct.termios zeroinitializer
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define signext i8 @get_char() {
%1 = alloca i8
%2 = call i32 @tcgetattr(i32 0, %struct.termios* @get_char.old)
%3 = load i32, i32* @ICANON
%4 = xor i32 %3, -1
%5 = load i32, i32* getelementptr inbounds (%struct.termios, %struct.termios* @get_char.new, i32 0, i32 0)
%6 = and i32 %5, %4
store i32 %6, i32* getelementptr inbounds (%struct.termios, %struct.termios* @get_char.new, i32 0, i32 0)
%7 = load i32, i32* @ECHO
%8 = xor i32 %7, -1
%9 = load i32, i32* getelementptr inbounds (%struct.termios, %struct.termios* @get_char.new, i32 0, i32 0)
%10 = and i32 %9, %8
store i32 %10, i32* getelementptr inbounds (%struct.termios, %struct.termios* @get_char.new, i32 0, i32 0)
%11 = load i32, i32* @TCSANOW
%12 = call i32 @tcsetattr(i32 0, i32 %11, %struct.termios* @get_char.new)
%13 = call signext i8 (...) @getchar()
store i8 %13, i8* %1
%14 = load i32, i32* @TCSANOW
%15 = call i32 @tcsetattr(i32 0, i32 %14, %struct.termios* @get_char.old)
%16 = load i8, i8* %1
ret i8 %16
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@get_char.old = internal global %struct.termios zeroinitializer
@get_char.new = internal global %struct.termios zeroinitializer
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define signext i8 @get_char() {
%1 = tail call i32 @tcgetattr(i32 0, %struct.termios* @get_char.old)
%2 = load i32, i32* getelementptr inbounds (%struct.termios, %struct.termios* @get_char.old, i64 0, i32 0)
%3 = load i32, i32* @ICANON
%4 = load i32, i32* @ECHO
%5 = or i32 %3, %4
%6 = xor i32 %5, -1
%7 = and i32 %2, %6
store i32 %7, i32* getelementptr inbounds (%struct.termios, %struct.termios* @get_char.new, i64 0, i32 0)
%8 = load i32, i32* @TCSANOW
%9 = tail call i32 @tcsetattr(i32 0, i32 %8, %struct.termios* @get_char.new)
%10 = tail call signext i8 (...) @getchar()
%11 = load i32, i32* @TCSANOW
%12 = tail call i32 @tcsetattr(i32 0, i32 %11, %struct.termios* @get_char.old)
ret i8 %10
}