#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_iflag;
  int *c_cc;
  int /*<<< orphan*/ c_oflag;
  int /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ICANON;
int INPCK;
int ISTRIP;
int IXON;
int /*<<< orphan*/ OPOST;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void raw(void) {
  struct termios it;
  tcgetattr(fileno(stdin), &it);
  it.c_lflag &= ~(ICANON);
  it.c_lflag &= ~(ECHO);
  it.c_iflag &= ~(INPCK | ISTRIP | IXON);
  it.c_oflag &= ~(OPOST);
  it.c_cc[VMIN] = 1;
  it.c_cc[VTIME] = 0;
  tcsetattr(fileno(stdin), TCSANOW, &it);
}


x86 assembly (clang, -O0):
<raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    0x2e23(%rip),%rcx
or     (%rcx),%eax
mov    0x2e4a(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e0a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %eax,%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1050 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raw>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2eaa(%rip),%rbx
mov    (%rbx),%edi
call   1030 <fileno@plt>
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    0x2e66(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x14(%rsp)
mov    0x2e3f(%rip),%rax
mov    0x2e30(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e55(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2e1b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2dea(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    (%rbx),%edi
call   1030 <fileno@plt>
mov    0x2e02(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i32, i32 }
@stdin = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define void @raw() {
%1 = alloca %struct.termios
%2 = load i32, i32* @stdin
%3 = call i32 @fileno(i32 %2)
%4 = call i32 @tcgetattr(i32 %3, %struct.termios* %1)
%5 = load i32, i32* @ICANON
%6 = xor i32 %5, -1
%7 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 3
%8 = load i32, i32* %7
%9 = and i32 %8, %6
store i32 %9, i32* %7
%10 = load i32, i32* @ECHO
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 3
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* @INPCK
%16 = load i32, i32* @ISTRIP
%17 = or i32 %15, %16
%18 = load i32, i32* @IXON
%19 = or i32 %17, %18
%20 = xor i32 %19, -1
%21 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 0
%22 = load i32, i32* %21
%23 = and i32 %22, %20
store i32 %23, i32* %21
%24 = load i32, i32* @OPOST
%25 = xor i32 %24, -1
%26 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 2
%27 = load i32, i32* %26
%28 = and i32 %27, %25
store i32 %28, i32* %26
%29 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 1
%30 = load i32*, i32** %29
%31 = load i64, i64* @VMIN
%32 = getelementptr inbounds i32, i32* %30, i64 %31
store i32 1, i32* %32
%33 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 1
%34 = load i32*, i32** %33
%35 = load i64, i64* @VTIME
%36 = getelementptr inbounds i32, i32* %34, i64 %35
store i32 0, i32* %36
%37 = load i32, i32* @stdin
%38 = call i32 @fileno(i32 %37)
%39 = load i32, i32* @TCSANOW
%40 = call i32 @tcsetattr(i32 %38, i32 %39, %struct.termios* %1)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i32, i32 }
@stdin = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define void @raw() {
%1 = alloca %struct.termios
%2 = bitcast %struct.termios* %1 to i8*
%3 = load i32, i32* @stdin
%4 = tail call i32 @fileno(i32 %3)
%5 = call i32 @tcgetattr(i32 %4, %struct.termios* %1)
%6 = load i32, i32* @ICANON
%7 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 3
%8 = load i32, i32* %7
%9 = load i32, i32* @ECHO
%10 = or i32 %6, %9
%11 = xor i32 %10, -1
%12 = and i32 %8, %11
store i32 %12, i32* %7
%13 = load i32, i32* @INPCK
%14 = load i32, i32* @ISTRIP
%15 = or i32 %14, %13
%16 = load i32, i32* @IXON
%17 = or i32 %15, %16
%18 = xor i32 %17, -1
%19 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%20 = load i32, i32* %19
%21 = and i32 %20, %18
store i32 %21, i32* %19
%22 = load i32, i32* @OPOST
%23 = xor i32 %22, -1
%24 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
%25 = load i32, i32* %24
%26 = and i32 %25, %23
store i32 %26, i32* %24
%27 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%28 = load i32*, i32** %27
%29 = load i64, i64* @VMIN
%30 = getelementptr inbounds i32, i32* %28, i64 %29
store i32 1, i32* %30
%31 = load i64, i64* @VTIME
%32 = getelementptr inbounds i32, i32* %28, i64 %31
store i32 0, i32* %32
%33 = load i32, i32* @stdin
%34 = call i32 @fileno(i32 %33)
%35 = load i32, i32* @TCSANOW
%36 = call i32 @tcsetattr(i32 %34, i32 %35, %struct.termios* %1)
ret void
}