#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;
};

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void init_raw(bool init) {
  static struct termios oldterm, newterm;
  if (init) {
    tcgetattr(STDIN_FILENO, &oldterm);
    newterm = oldterm;
    newterm.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newterm);
  } else {
    tcsetattr(STDIN_FILENO, TCSANOW, &oldterm);
  }
}


x86 assembly (clang, -O0):
<init_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     119a <init_raw+0x7a>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    0x2eef(%rip),%rsi
call   1030 <tcgetattr@plt>
mov    0x2ee4(%rip),%eax
mov    %eax,0x2ee2(%rip)
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    0x2e7a(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    0x2ec7(%rip),%eax
mov    %eax,0x2ec1(%rip)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0x2ea8(%rip),%rdx
call   1040 <tcsetattr@plt>
jmp    11b8 <init_raw+0x98>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
lea    0x2e81(%rip),%rdx
call   1040 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_raw>:
push   %rbx
mov    %edi,%eax
mov    0x2ea6(%rip),%rbx
mov    (%rbx),%edi
test   %eax,%eax
je     1174 <init_raw+0x54>
lea    0x2efd(%rip),%rsi
call   1030 <tcgetattr@plt>
mov    0x2e85(%rip),%rax
mov    0x2e96(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    0x2ede(%rip),%ecx
mov    %ecx,0x2edc(%rip)
lea    0x2ed5(%rip),%rdx
mov    (%rbx),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
pop    %rbx
jmp    1040 <tcsetattr@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0x2eb0(%rip),%rdx
pop    %rbx
jmp    1040 <tcsetattr@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@init_raw.oldterm = internal global %struct.termios zeroinitializer
@init_raw.newterm = internal global %struct.termios zeroinitializer
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define void @init_raw(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp ne i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %1
%6 = load i32, i32* @STDIN_FILENO
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* @init_raw.oldterm)
%8 = load i32, i32* @ICANON
%9 = load i32, i32* @ECHO
%10 = or i32 %8, %9
%11 = xor i32 %10, -1
%12 = load i32, i32* getelementptr inbounds (%struct.termios, %struct.termios* @init_raw.newterm, i32 0, i32 0)
%13 = and i32 %12, %11
store i32 %13, i32* getelementptr inbounds (%struct.termios, %struct.termios* @init_raw.newterm, i32 0, i32 0)
%14 = load i32, i32* @STDIN_FILENO
%15 = load i32, i32* @TCSANOW
%16 = call i32 @tcsetattr(i32 %14, i32 %15, %struct.termios* @init_raw.newterm)
br label %21
17: ; preds = %1
%18 = load i32, i32* @STDIN_FILENO
%19 = load i32, i32* @TCSANOW
%20 = call i32 @tcsetattr(i32 %18, i32 %19, %struct.termios* @init_raw.oldterm)
br label %21
21: ; preds = %17, %5
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@init_raw.oldterm = internal global %struct.termios zeroinitializer
@init_raw.newterm = internal global %struct.termios zeroinitializer
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define void @init_raw(i32 %0) {
%2 = icmp eq i32 %0, 0
%3 = load i32, i32* @STDIN_FILENO
br i1 %2, label %15, label %4
4: ; preds = %1
%5 = tail call i32 @tcgetattr(i32 %3, %struct.termios* @init_raw.oldterm)
%6 = load i32, i32* getelementptr inbounds (%struct.termios, %struct.termios* @init_raw.oldterm, i64 0, i32 0)
%7 = load i32, i32* @ICANON
%8 = load i32, i32* @ECHO
%9 = or i32 %8, %7
%10 = xor i32 %9, -1
%11 = and i32 %6, %10
store i32 %11, i32* getelementptr inbounds (%struct.termios, %struct.termios* @init_raw.newterm, i64 0, i32 0)
%12 = load i32, i32* @STDIN_FILENO
%13 = load i32, i32* @TCSANOW
%14 = tail call i32 @tcsetattr(i32 %12, i32 %13, %struct.termios* @init_raw.newterm)
br label %18
15: ; preds = %1
%16 = load i32, i32* @TCSANOW
%17 = tail call i32 @tcsetattr(i32 %3, i32 %16, %struct.termios* @init_raw.oldterm)
br label %18
18: ; preds = %15, %4
ret void
}