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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ die(int /*<<< orphan*/, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ isatty(int /*<<< orphan*/);
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
void rawmode(void) {
  struct termios termios;
  if (!isatty(STDIN_FILENO))
    return;
  if (tcgetattr(STDIN_FILENO, &termios) < 0)
    die(errno, "tcgetattr");
  cfmakeraw(&termios);
  tcsetattr(STDIN_FILENO, TCSANOW, &termios);
}


x86 assembly (clang, -O0):
<rawmode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
jne    1174 <rawmode+0x24>
jmp    11c9 <rawmode+0x79>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
jge    11a5 <rawmode+0x55>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1070 <die@plt>
lea    -0x8(%rbp),%rdi
call   1040 <cfmakeraw@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1060 <tcsetattr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rawmode>:
push   %r14
push   %rbx
push   %rax
mov    0x2e75(%rip),%r14
mov    (%r14),%edi
call   1030 <isatty@plt>
test   %eax,%eax
je     11ab <rawmode+0x5b>
mov    (%r14),%edi
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
jns    118c <rawmode+0x3c>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1070 <die@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <cfmakeraw@plt>
mov    (%r14),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdx
call   1060 <tcsetattr@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@errno = global i32 0
@.str = [10 x i8] c"tcgetattr\00"
@TCSANOW = global i32 0
define void @rawmode() {
%1 = alloca %struct.termios
%2 = load i32, i32* @STDIN_FILENO
%3 = call i32 @isatty(i32 %2)
%4 = icmp ne i32 %3, 0
br i1 %4, label %6, label %5
5: ; preds = %0
br label %18
6: ; preds = %0
%7 = load i32, i32* @STDIN_FILENO
%8 = call i64 @tcgetattr(i32 %7, %struct.termios* %1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* @errno
%12 = call i32 @die(i32 %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %6
%14 = call i32 @cfmakeraw(%struct.termios* %1)
%15 = load i32, i32* @STDIN_FILENO
%16 = load i32, i32* @TCSANOW
%17 = call i32 @tcsetattr(i32 %15, i32 %16, %struct.termios* %1)
br label %18
18: ; preds = %13, %5
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@errno = global i32 0
@.str = [10 x i8] c"tcgetattr\00"
@TCSANOW = global i32 0
define void @rawmode() {
%1 = alloca %struct.termios
%2 = bitcast %struct.termios* %1 to i8*
%3 = load i32, i32* @STDIN_FILENO
%4 = tail call i32 @isatty(i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %0
%7 = load i32, i32* @STDIN_FILENO
%8 = call i64 @tcgetattr(i32 %7, %struct.termios* %1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* @errno
%12 = call i32 @die(i32 %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %10, %6
%14 = call i32 @cfmakeraw(%struct.termios* %1)
%15 = load i32, i32* @STDIN_FILENO
%16 = load i32, i32* @TCSANOW
%17 = call i32 @tcsetattr(i32 %15, i32 %16, %struct.termios* %1)
br label %18
18: ; preds = %0, %13
ret void
}