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

/* Variables and functions */
#define STDIN_FILENO 129
#define STDOUT_FILENO 128
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfmakeraw(struct termios *);
scalar_t__ errno;
scalar_t__ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void console_make_raw(int fd, struct termios *attr) {
  struct termios raw = *attr;
  errno = 0;
  if (tcgetattr(fd, attr) != 0)
    return;
  cfmakeraw(&raw);
  switch (fd) {
  case STDIN_FILENO:
    raw.c_oflag = attr->c_oflag;
    break;
  case STDOUT_FILENO:
    raw.c_iflag = attr->c_iflag;
    raw.c_lflag = attr->c_lflag;
    break;
  }
  tcsetattr(fd, TCSANOW, &raw);
}


x86 assembly (clang, -O0):
<console_make_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,-0x20(%rbp)
mov    0x8(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e81(%rip),%rax
movq   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
je     1179 <console_make_raw+0x49>
jmp    11e2 <console_make_raw+0xb2>
lea    -0x20(%rbp),%rdi
call   1030 <cfmakeraw@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x80,%eax
je     11ba <console_make_raw+0x8a>
jmp    1198 <console_make_raw+0x68>
mov    -0x24(%rbp),%eax
sub    $0x81,%eax
jne    11cd <console_make_raw+0x9d>
jmp    11ab <console_make_raw+0x7b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x18(%rbp)
jmp    11cd <console_make_raw+0x9d>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <tcsetattr@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<console_make_raw>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%eax
mov    %eax,0x10(%rsp)
mov    (%rsi),%rax
mov    %rax,0x8(%rsp)
mov    0x2e87(%rip),%rax
movq   $0x0,(%rax)
call   1040 <tcgetattr@plt>
test   %rax,%rax
jne    11a7 <console_make_raw+0x77>
lea    0x8(%rsp),%rdi
call   1030 <cfmakeraw@plt>
cmp    $0x80,%ebp
je     1185 <console_make_raw+0x55>
cmp    $0x81,%ebp
jne    1192 <console_make_raw+0x62>
mov    0x8(%rbx),%eax
mov    %eax,0x10(%rsp)
jmp    1192 <console_make_raw+0x62>
mov    0x4(%rbx),%eax
mov    %eax,0xc(%rsp)
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1050 <tcsetattr@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32 }
@errno = global i64 0
@TCSANOW = global i32 0
define void @console_make_raw(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 %struct.termios*, %struct.termios** %4
%7 = bitcast %struct.termios* %5 to i8*
%8 = bitcast %struct.termios* %6 to i8*
store i64 0, i64* @errno
%9 = load i32, i32* %3
%10 = load %struct.termios*, %struct.termios** %4
%11 = call i64 @tcgetattr(i32 %9, %struct.termios* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
br label %35
14: ; preds = %2
%15 = call i32 @cfmakeraw(%struct.termios* %5)
%16 = load i32, i32* %3
switch i32 %16, label %31 [
i32 129, label %17
i32 128, label %22
]
17: ; preds = %14
%18 = load %struct.termios*, %struct.termios** %4
%19 = getelementptr inbounds %struct.termios, %struct.termios* %18, i32 0, i32 2
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 2
store i32 %20, i32* %21
br label %31
22: ; preds = %14
%23 = load %struct.termios*, %struct.termios** %4
%24 = getelementptr inbounds %struct.termios, %struct.termios* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 1
store i32 %25, i32* %26
%27 = load %struct.termios*, %struct.termios** %4
%28 = getelementptr inbounds %struct.termios, %struct.termios* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
store i32 %29, i32* %30
br label %31
31: ; preds = %14, %22, %17
%32 = load i32, i32* %3
%33 = load i32, i32* @TCSANOW
%34 = call i32 @tcsetattr(i32 %32, i32 %33, %struct.termios* %5)
br label %35
35: ; preds = %31, %13
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32 }
@errno = global i64 0
@TCSANOW = global i32 0
define void @console_make_raw(i32 %0, %struct.termios* %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = bitcast %struct.termios* %1 to i8*
store i64 0, i64* @errno
%6 = tail call i64 @tcgetattr(i32 %0, %struct.termios* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %2
%9 = call i32 @cfmakeraw(%struct.termios* %3)
switch i32 %0, label %21 [
i32 129, label %10
i32 128, label %14
]
10: ; preds = %8
%11 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
store i32 %12, i32* %13
br label %21
14: ; preds = %8
%15 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
store i32 %19, i32* %20
br label %21
21: ; preds = %8, %14, %10
%22 = load i32, i32* @TCSANOW
%23 = call i32 @tcsetattr(i32 %0, i32 %22, %struct.termios* %3)
br label %24
24: ; preds = %2, %21
ret void
}