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

/* Variables and functions */
int ECHO;
int ECHOE;
int ECHOK;
int ECHONL;
int ICANON;
int ICRNL;
int IGNCR;
int IGNPAR;
int INLCR;
int ISIG;
int ISTRIP;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int /*<<< orphan*/ TCSADRAIN;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int tty_raw(void) {
  struct termios ti;
  int ret = 0;
  ti.c_iflag |= IGNPAR;
  ti.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
  ti.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
  ti.c_oflag &= ~OPOST;
  ti.c_cc[VMIN] = 1;
  ti.c_cc[VTIME] = 0;
  ret = tcsetattr(fileno(stdout), TCSADRAIN, &ti);
  return ret;
}


x86 assembly (clang, -O0):
<tty_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x1c(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    0x2e92(%rip),%rcx
or     (%rcx),%eax
mov    0x2e79(%rip),%rcx
or     (%rcx),%eax
mov    0x2e88(%rip),%rcx
or     (%rcx),%eax
mov    0x2e57(%rip),%rcx
or     (%rcx),%eax
mov    0x2e1e(%rip),%rcx
or     (%rcx),%eax
mov    0x2e5d(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    0x2dba(%rip),%rcx
or     (%rcx),%eax
mov    0x2e19(%rip),%rcx
or     (%rcx),%eax
mov    0x2e08(%rip),%rcx
or     (%rcx),%eax
mov    0x2dd7(%rip),%rcx
or     (%rcx),%eax
mov    0x2db6(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2dbe(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x2d69(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %eax,%edi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <tcsetattr@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i32 }
@IGNPAR = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@IXANY = global i32 0
@IXOFF = global i32 0
@ISIG = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHONL = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@stdout = global i32 0
@TCSADRAIN = global i32 0
define i32 @tty_raw() {
%1 = alloca %struct.termios
%2 = alloca i32
store i32 0, i32* %2
%3 = load i32, i32* @IGNPAR
%4 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 0
%5 = load i32, i32* %4
%6 = or i32 %5, %3
store i32 %6, i32* %4
%7 = load i32, i32* @ISTRIP
%8 = load i32, i32* @INLCR
%9 = or i32 %7, %8
%10 = load i32, i32* @IGNCR
%11 = or i32 %9, %10
%12 = load i32, i32* @ICRNL
%13 = or i32 %11, %12
%14 = load i32, i32* @IXON
%15 = or i32 %13, %14
%16 = load i32, i32* @IXANY
%17 = or i32 %15, %16
%18 = load i32, i32* @IXOFF
%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* @ISIG
%25 = load i32, i32* @ICANON
%26 = or i32 %24, %25
%27 = load i32, i32* @ECHO
%28 = or i32 %26, %27
%29 = load i32, i32* @ECHOE
%30 = or i32 %28, %29
%31 = load i32, i32* @ECHOK
%32 = or i32 %30, %31
%33 = load i32, i32* @ECHONL
%34 = or i32 %32, %33
%35 = xor i32 %34, -1
%36 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 1
%37 = load i32, i32* %36
%38 = and i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* @OPOST
%40 = xor i32 %39, -1
%41 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 3
%42 = load i32, i32* %41
%43 = and i32 %42, %40
store i32 %43, i32* %41
%44 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 2
%45 = load i32*, i32** %44
%46 = load i64, i64* @VMIN
%47 = getelementptr inbounds i32, i32* %45, i64 %46
store i32 1, i32* %47
%48 = getelementptr inbounds %struct.termios, %struct.termios* %1, i32 0, i32 2
%49 = load i32*, i32** %48
%50 = load i64, i64* @VTIME
%51 = getelementptr inbounds i32, i32* %49, i64 %50
store i32 0, i32* %51
%52 = load i32, i32* @stdout
%53 = call i32 @fileno(i32 %52)
%54 = load i32, i32* @TCSADRAIN
%55 = call i32 @tcsetattr(i32 %53, i32 %54, %struct.termios* %1)
store i32 %55, i32* %2
%56 = load i32, i32* %2
ret i32 %56
}

LLVM IR (-O2):