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

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ ICRNL;
int ISIG;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void SetTerminal(int fd) {
  struct termios t;
  tcgetattr(STDIN_FILENO, &t);
  t.c_lflag &= ~(ECHO | ICANON | ISIG);
  t.c_lflag &= ~(ECHO | ICANON);
  t.c_iflag &= ~ICRNL;
  t.c_cc[VTIME] = 0;
  t.c_cc[VMIN] = 1;
  tcflush(fd, TCIFLUSH);
  tcsetattr(fd, TCSANOW, &t);
}


x86 assembly (clang, -O0):
<SetTerminal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%eax
mov    0x2e43(%rip),%rcx
or     (%rcx),%eax
mov    0x2e6a(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    0x2e1f(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e07(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2e0a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    -0x4(%rbp),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetTerminal>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%r14
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e84(%rip),%rax
mov    0x2e45(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e6a(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e2f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <tcflush@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%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 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@ICRNL = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define void @SetTerminal(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* @STDIN_FILENO
%5 = call i32 @tcgetattr(i32 %4, %struct.termios* %3)
%6 = load i32, i32* @ECHO
%7 = load i32, i32* @ICANON
%8 = or i32 %6, %7
%9 = load i32, i32* @ISIG
%10 = or i32 %8, %9
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* @ECHO
%16 = load i32, i32* @ICANON
%17 = or i32 %15, %16
%18 = xor i32 %17, -1
%19 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = and i32 %20, %18
store i32 %21, i32* %19
%22 = load i32, i32* @ICRNL
%23 = xor i32 %22, -1
%24 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 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* %3, i32 0, i32 1
%28 = load i32*, i32** %27
%29 = load i64, i64* @VTIME
%30 = getelementptr inbounds i32, i32* %28, i64 %29
store i32 0, i32* %30
%31 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%32 = load i32*, i32** %31
%33 = load i64, i64* @VMIN
%34 = getelementptr inbounds i32, i32* %32, i64 %33
store i32 1, i32* %34
%35 = load i32, i32* %2
%36 = load i32, i32* @TCIFLUSH
%37 = call i32 @tcflush(i32 %35, i32 %36)
%38 = load i32, i32* %2
%39 = load i32, i32* @TCSANOW
%40 = call i32 @tcsetattr(i32 %38, i32 %39, %struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i32 }
@STDIN_FILENO = global i32 0
@ECHO = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@ICRNL = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define void @SetTerminal(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = load i32, i32* @STDIN_FILENO
%5 = call i32 @tcgetattr(i32 %4, %struct.termios* %2)
%6 = load i32, i32* @ECHO
%7 = load i32, i32* @ICANON
%8 = or i32 %7, %6
%9 = load i32, i32* @ISIG
%10 = or i32 %8, %9
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* @ICRNL
%16 = xor i32 %15, -1
%17 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%18 = load i32, i32* %17
%19 = and i32 %18, %16
store i32 %19, i32* %17
%20 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%21 = load i32*, i32** %20
%22 = load i64, i64* @VTIME
%23 = getelementptr inbounds i32, i32* %21, i64 %22
store i32 0, i32* %23
%24 = load i64, i64* @VMIN
%25 = getelementptr inbounds i32, i32* %21, i64 %24
store i32 1, i32* %25
%26 = load i32, i32* @TCIFLUSH
%27 = call i32 @tcflush(i32 %0, i32 %26)
%28 = load i32, i32* @TCSANOW
%29 = call i32 @tcsetattr(i32 %0, i32 %28, %struct.termios* %2)
ret void
}