#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*/ TCSANOW;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ die(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
void setup_raw(struct termios *save) {
  struct termios set;
  if (tcgetattr(0, save) < 0) {
    fprintf(stderr, "Unable to read terminal attributes: %m");
    return;
  }
  set = *save;
  cfmakeraw(&set);
  if (tcsetattr(0, TCSANOW, &set) < 0)
    die("Unable to set terminal attributes: %m");
}


x86 assembly (clang, -O0):
<setup_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
jge    118b <setup_raw+0x3b>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11c7 <setup_raw+0x77>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <cfmakeraw@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
jge    11c7 <setup_raw+0x77>
lea    0xe65(%rip),%rdi
call   1070 <die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_raw>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
js     11a4 <setup_raw+0x54>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <cfmakeraw@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %rbx,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
jns    119e <setup_raw+0x4e>
lea    0xe8e(%rip),%rdi
call   1070 <die@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Unable to read terminal attributes: %m\00"
@TCSANOW = global i32 0
@.str.1 = [38 x i8] c"Unable to set terminal attributes: %m\00"
define void @setup_raw(%struct.termios* %0) {
%2 = alloca %struct.termios*
%3 = alloca %struct.termios
store %struct.termios* %0, %struct.termios** %2
%4 = load %struct.termios*, %struct.termios** %2
%5 = call i64 @tcgetattr(i32 0, %struct.termios* %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %20
10: ; preds = %1
%11 = load %struct.termios*, %struct.termios** %2
%12 = bitcast %struct.termios* %3 to i8*
%13 = bitcast %struct.termios* %11 to i8*
%14 = call i32 @cfmakeraw(%struct.termios* %3)
%15 = load i32, i32* @TCSANOW
%16 = call i64 @tcsetattr(i32 0, i32 %15, %struct.termios* %3)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %7, %18, %10
ret void
}

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