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

/* Variables and functions */
int BRKINT;
int /*<<< orphan*/ CLOCAL;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int ECHO;
int ECHOCTL;
int ICANON;
int ICRNL;
int IEXTEN;
int INPCK;
int ISIG;
int ISTRIP;
int IXON;
int /*<<< orphan*/ OPOST;
int /*<<< orphan*/ PARENB;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ get_tty_mode(struct termios *, int);
void get_tty_raw(struct termios *tty, int fd) {
  assert(tty != NULL);
  get_tty_mode(tty, fd);
  tty->c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
  tty->c_oflag &= ~(OPOST);
  tty->c_cflag &= ~CSIZE;
  tty->c_cflag |= CS8;
  tty->c_cflag &= ~PARENB;
  tty->c_cflag |= CLOCAL;
  tty->c_lflag &= ~(ECHO | ECHOCTL | ICANON | IEXTEN | ISIG);
  tty->c_cc[VMIN] = 1;
  tty->c_cc[VTIME] = 0;
  return;
}


x86 assembly (clang, -O0):
<get_tty_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <get_tty_mode@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8b(%rip),%rax
or     (%rax),%ecx
mov    0x2e1a(%rip),%rax
or     (%rax),%ecx
mov    0x2e09(%rip),%rax
or     (%rax),%ecx
mov    0x2e58(%rip),%rax
or     (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x8(%rbp),%rax
and    (%rax),%ecx
mov    %ecx,(%rax)
mov    0x2e4c(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x8(%rbp),%rax
and    0x14(%rax),%ecx
mov    %ecx,0x14(%rax)
mov    0x2df6(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x8(%rbp),%rax
and    0x10(%rax),%ecx
mov    %ecx,0x10(%rax)
mov    0x2df0(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
or     0x10(%rax),%ecx
mov    %ecx,0x10(%rax)
mov    0x2dfd(%rip),%rax
mov    (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x8(%rbp),%rax
and    0x10(%rax),%ecx
mov    %ecx,0x10(%rax)
mov    0x2d77(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
or     0x10(%rax),%ecx
mov    %ecx,0x10(%rax)
mov    0x2dcc(%rip),%rax
mov    (%rax),%ecx
mov    0x2de3(%rip),%rax
or     (%rax),%ecx
mov    0x2d62(%rip),%rax
or     (%rax),%ecx
mov    0x2d81(%rip),%rax
or     (%rax),%ecx
mov    0x2da0(%rip),%rax
or     (%rax),%ecx
xor    $0xffffffff,%ecx
mov    -0x8(%rbp),%rax
and    0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d6a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d21(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tty_raw>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <get_tty_mode@plt>
mov    0x2e69(%rip),%rax
mov    0x2e9a(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e27(%rip),%rax
or     (%rax),%ecx
mov    0x2e16(%rip),%rax
or     (%rax),%ecx
mov    0x2e65(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rbx)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x14(%rbx)
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x10(%rbx),%eax
mov    0x2e14(%rip),%rcx
or     (%rcx),%eax
mov    0x2e2b(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2dae(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x10(%rbx)
mov    0x2e0a(%rip),%rax
mov    0x2e23(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2da0(%rip),%rax
or     (%rax),%ecx
mov    0x2dbf(%rip),%rax
or     (%rax),%ecx
mov    0x2dde(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rbx)
mov    0x8(%rbx),%rax
mov    0x2db4(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d73(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32*, i32, i32 }
@BRKINT = global i32 0
@ICRNL = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CLOCAL = global i32 0
@ECHO = global i32 0
@ECHOCTL = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
define void @get_tty_raw(%struct.termios* %0, i32 %1) {
%3 = alloca %struct.termios*
%4 = alloca i32
store %struct.termios* %0, %struct.termios** %3
store i32 %1, i32* %4
%5 = load %struct.termios*, %struct.termios** %3
%6 = icmp ne %struct.termios* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load %struct.termios*, %struct.termios** %3
%10 = load i32, i32* %4
%11 = call i32 @get_tty_mode(%struct.termios* %9, i32 %10)
%12 = load i32, i32* @BRKINT
%13 = load i32, i32* @ICRNL
%14 = or i32 %12, %13
%15 = load i32, i32* @INPCK
%16 = or i32 %14, %15
%17 = load i32, i32* @ISTRIP
%18 = or i32 %16, %17
%19 = load i32, i32* @IXON
%20 = or i32 %18, %19
%21 = xor i32 %20, -1
%22 = load %struct.termios*, %struct.termios** %3
%23 = getelementptr inbounds %struct.termios, %struct.termios* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = and i32 %24, %21
store i32 %25, i32* %23
%26 = load i32, i32* @OPOST
%27 = xor i32 %26, -1
%28 = load %struct.termios*, %struct.termios** %3
%29 = getelementptr inbounds %struct.termios, %struct.termios* %28, i32 0, i32 4
%30 = load i32, i32* %29
%31 = and i32 %30, %27
store i32 %31, i32* %29
%32 = load i32, i32* @CSIZE
%33 = xor i32 %32, -1
%34 = load %struct.termios*, %struct.termios** %3
%35 = getelementptr inbounds %struct.termios, %struct.termios* %34, i32 0, i32 3
%36 = load i32, i32* %35
%37 = and i32 %36, %33
store i32 %37, i32* %35
%38 = load i32, i32* @CS8
%39 = load %struct.termios*, %struct.termios** %3
%40 = getelementptr inbounds %struct.termios, %struct.termios* %39, i32 0, i32 3
%41 = load i32, i32* %40
%42 = or i32 %41, %38
store i32 %42, i32* %40
%43 = load i32, i32* @PARENB
%44 = xor i32 %43, -1
%45 = load %struct.termios*, %struct.termios** %3
%46 = getelementptr inbounds %struct.termios, %struct.termios* %45, i32 0, i32 3
%47 = load i32, i32* %46
%48 = and i32 %47, %44
store i32 %48, i32* %46
%49 = load i32, i32* @CLOCAL
%50 = load %struct.termios*, %struct.termios** %3
%51 = getelementptr inbounds %struct.termios, %struct.termios* %50, i32 0, i32 3
%52 = load i32, i32* %51
%53 = or i32 %52, %49
store i32 %53, i32* %51
%54 = load i32, i32* @ECHO
%55 = load i32, i32* @ECHOCTL
%56 = or i32 %54, %55
%57 = load i32, i32* @ICANON
%58 = or i32 %56, %57
%59 = load i32, i32* @IEXTEN
%60 = or i32 %58, %59
%61 = load i32, i32* @ISIG
%62 = or i32 %60, %61
%63 = xor i32 %62, -1
%64 = load %struct.termios*, %struct.termios** %3
%65 = getelementptr inbounds %struct.termios, %struct.termios* %64, i32 0, i32 1
%66 = load i32, i32* %65
%67 = and i32 %66, %63
store i32 %67, i32* %65
%68 = load %struct.termios*, %struct.termios** %3
%69 = getelementptr inbounds %struct.termios, %struct.termios* %68, i32 0, i32 2
%70 = load i32*, i32** %69
%71 = load i64, i64* @VMIN
%72 = getelementptr inbounds i32, i32* %70, i64 %71
store i32 1, i32* %72
%73 = load %struct.termios*, %struct.termios** %3
%74 = getelementptr inbounds %struct.termios, %struct.termios* %73, i32 0, i32 2
%75 = load i32*, i32** %74
%76 = load i64, i64* @VTIME
%77 = getelementptr inbounds i32, i32* %75, i64 %76
store i32 0, i32* %77
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32*, i32, i32 }
@BRKINT = global i32 0
@ICRNL = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CLOCAL = global i32 0
@ECHO = global i32 0
@ECHOCTL = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
define void @get_tty_raw(%struct.termios* %0, i32 %1) {
%3 = icmp ne %struct.termios* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @get_tty_mode(%struct.termios* %0, i32 %1)
%7 = load i32, i32* @BRKINT
%8 = load i32, i32* @ICRNL
%9 = or i32 %8, %7
%10 = load i32, i32* @INPCK
%11 = or i32 %9, %10
%12 = load i32, i32* @ISTRIP
%13 = or i32 %11, %12
%14 = load i32, i32* @IXON
%15 = or i32 %13, %14
%16 = xor i32 %15, -1
%17 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%18 = load i32, i32* %17
%19 = and i32 %18, %16
store i32 %19, i32* %17
%20 = load i32, i32* @OPOST
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 4
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* @CSIZE
%26 = xor i32 %25, -1
%27 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 3
%28 = load i32, i32* %27
%29 = and i32 %28, %26
%30 = load i32, i32* @CS8
%31 = or i32 %30, %29
%32 = load i32, i32* @PARENB
%33 = xor i32 %32, -1
%34 = and i32 %31, %33
%35 = load i32, i32* @CLOCAL
%36 = or i32 %35, %34
store i32 %36, i32* %27
%37 = load i32, i32* @ECHO
%38 = load i32, i32* @ECHOCTL
%39 = or i32 %38, %37
%40 = load i32, i32* @ICANON
%41 = or i32 %39, %40
%42 = load i32, i32* @IEXTEN
%43 = or i32 %41, %42
%44 = load i32, i32* @ISIG
%45 = or i32 %43, %44
%46 = xor i32 %45, -1
%47 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 1
%48 = load i32, i32* %47
%49 = and i32 %48, %46
store i32 %49, i32* %47
%50 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 2
%51 = load i32*, i32** %50
%52 = load i64, i64* @VMIN
%53 = getelementptr inbounds i32, i32* %51, i64 %52
store i32 1, i32* %53
%54 = load i64, i64* @VTIME
%55 = getelementptr inbounds i32, i32* %51, i64 %54
store i32 0, i32* %55
ret void
}