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

/* Variables and functions */
int BRKINT;
int ECHO;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNBRK;
int IGNCR;
int INLCR;
int INPCK;
int ISIG;
int ISTRIP;
int IXON;
int /*<<< orphan*/ OPOST;
int PARMRK;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void set_raw_input(int fd, struct termios *old_term) {
  struct termios tnew;
  tcgetattr(STDIN_FILENO, &tnew);
  if (old_term)
    *old_term = tnew;
  tnew.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO);
  tnew.c_iflag &= ~(BRKINT | ICRNL | IGNBRK | IGNCR | INLCR | INPCK | ISTRIP |
                    IXON | PARMRK);
  tnew.c_oflag &= ~OPOST;
  tcsetattr(STDIN_FILENO, TCSAFLUSH, &tnew);
}


x86 assembly (clang, -O0):
<set_raw_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmpq   $0x0,-0x10(%rbp)
je     115d <set_raw_input+0x3d>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%ecx
mov    %ecx,0x8(%rax)
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    0x2e3b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e22(%rip),%rcx
or     (%rcx),%eax
mov    0x2e31(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    0x2e46(%rip),%rcx
or     (%rcx),%eax
mov    0x2dd5(%rip),%rcx
or     (%rcx),%eax
mov    0x2e1c(%rip),%rcx
or     (%rcx),%eax
mov    0x2e23(%rip),%rcx
or     (%rcx),%eax
mov    0x2dca(%rip),%rcx
or     (%rcx),%eax
mov    0x2db9(%rip),%rcx
or     (%rcx),%eax
mov    0x2de8(%rip),%rcx
or     (%rcx),%eax
mov    0x2e17(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_raw_input>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x2e3f(%rip),%r14
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
test   %rbx,%rbx
je     1152 <set_raw_input+0x32>
mov    0x10(%rsp),%eax
mov    %eax,0x8(%rbx)
mov    0x8(%rsp),%rax
mov    %rax,(%rbx)
mov    0x2e0f(%rip),%rax
mov    0x2e48(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e2d(%rip),%rax
or     (%rax),%ecx
mov    0x2e3c(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2e1d(%rip),%rax
mov    0x2e56(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2de3(%rip),%rax
or     (%rax),%ecx
mov    0x2e2a(%rip),%rax
or     (%rax),%ecx
mov    0x2e31(%rip),%rax
or     (%rax),%ecx
mov    0x2dd8(%rip),%rax
or     (%rax),%ecx
mov    0x2dc7(%rip),%rax
or     (%rax),%ecx
mov    0x2df6(%rip),%rax
or     (%rax),%ecx
mov    0x2e25(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0xc(%rsp)
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x10(%rsp)
mov    (%r14),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
call   1040 <tcsetattr@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@ECHO = global i32 0
@BRKINT = global i32 0
@ICRNL = global i32 0
@IGNBRK = global i32 0
@IGNCR = global i32 0
@INLCR = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@PARMRK = global i32 0
@OPOST = global i32 0
@TCSAFLUSH = global i32 0
define void @set_raw_input(i32 %0, %struct.termios* %1) {
%3 = alloca i32
%4 = alloca %struct.termios*
%5 = alloca %struct.termios
store i32 %0, i32* %3
store %struct.termios* %1, %struct.termios** %4
%6 = load i32, i32* @STDIN_FILENO
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %5)
%8 = load %struct.termios*, %struct.termios** %4
%9 = icmp ne %struct.termios* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load %struct.termios*, %struct.termios** %4
%12 = bitcast %struct.termios* %11 to i8*
%13 = bitcast %struct.termios* %5 to i8*
br label %14
14: ; preds = %10, %2
%15 = load i32, i32* @ICANON
%16 = load i32, i32* @ISIG
%17 = or i32 %15, %16
%18 = load i32, i32* @IEXTEN
%19 = or i32 %17, %18
%20 = load i32, i32* @ECHO
%21 = or i32 %19, %20
%22 = xor i32 %21, -1
%23 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @BRKINT
%27 = load i32, i32* @ICRNL
%28 = or i32 %26, %27
%29 = load i32, i32* @IGNBRK
%30 = or i32 %28, %29
%31 = load i32, i32* @IGNCR
%32 = or i32 %30, %31
%33 = load i32, i32* @INLCR
%34 = or i32 %32, %33
%35 = load i32, i32* @INPCK
%36 = or i32 %34, %35
%37 = load i32, i32* @ISTRIP
%38 = or i32 %36, %37
%39 = load i32, i32* @IXON
%40 = or i32 %38, %39
%41 = load i32, i32* @PARMRK
%42 = or i32 %40, %41
%43 = xor i32 %42, -1
%44 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
%45 = load i32, i32* %44
%46 = and i32 %45, %43
store i32 %46, i32* %44
%47 = load i32, i32* @OPOST
%48 = xor i32 %47, -1
%49 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
%50 = load i32, i32* %49
%51 = and i32 %50, %48
store i32 %51, i32* %49
%52 = load i32, i32* @STDIN_FILENO
%53 = load i32, i32* @TCSAFLUSH
%54 = call i32 @tcsetattr(i32 %52, i32 %53, %struct.termios* %5)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@ECHO = global i32 0
@BRKINT = global i32 0
@ICRNL = global i32 0
@IGNBRK = global i32 0
@IGNCR = global i32 0
@INLCR = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@PARMRK = global i32 0
@OPOST = global i32 0
@TCSAFLUSH = global i32 0
define void @set_raw_input(i32 %0, %struct.termios* writeonly %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = load i32, i32* @STDIN_FILENO
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %3)
%7 = icmp eq %struct.termios* %1, null
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = bitcast %struct.termios* %1 to i8*
br label %10
10: ; preds = %8, %2
%11 = load i32, i32* @ICANON
%12 = load i32, i32* @ISIG
%13 = or i32 %12, %11
%14 = load i32, i32* @IEXTEN
%15 = or i32 %13, %14
%16 = load i32, i32* @ECHO
%17 = or i32 %15, %16
%18 = xor i32 %17, -1
%19 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%20 = load i32, i32* %19
%21 = and i32 %20, %18
store i32 %21, i32* %19
%22 = load i32, i32* @BRKINT
%23 = load i32, i32* @ICRNL
%24 = or i32 %23, %22
%25 = load i32, i32* @IGNBRK
%26 = or i32 %24, %25
%27 = load i32, i32* @IGNCR
%28 = or i32 %26, %27
%29 = load i32, i32* @INLCR
%30 = or i32 %28, %29
%31 = load i32, i32* @INPCK
%32 = or i32 %30, %31
%33 = load i32, i32* @ISTRIP
%34 = or i32 %32, %33
%35 = load i32, i32* @IXON
%36 = or i32 %34, %35
%37 = load i32, i32* @PARMRK
%38 = or i32 %36, %37
%39 = xor i32 %38, -1
%40 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%41 = load i32, i32* %40
%42 = and i32 %41, %39
store i32 %42, i32* %40
%43 = load i32, i32* @OPOST
%44 = xor i32 %43, -1
%45 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%46 = load i32, i32* %45
%47 = and i32 %46, %44
store i32 %47, i32* %45
%48 = load i32, i32* @STDIN_FILENO
%49 = load i32, i32* @TCSAFLUSH
%50 = call i32 @tcsetattr(i32 %48, i32 %49, %struct.termios* %3)
ret void
}