#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 *);
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)
    die("Unable to read terminal attributes: %m");
  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   1040 <tcgetattr@plt>
cmp    $0x0,%rax
jge    116d <setup_raw+0x2d>
lea    0xe98(%rip),%rdi
call   1060 <die@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <cfmakeraw@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
jge    11a9 <setup_raw+0x69>
lea    0xe83(%rip),%rdi
call   1060 <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   1040 <tcgetattr@plt>
test   %rax,%rax
jns    1163 <setup_raw+0x23>
lea    0xea2(%rip),%rdi
call   1060 <die@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <cfmakeraw@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
test   %rax,%rax
jns    119a <setup_raw+0x5a>
lea    0xe92(%rip),%rdi
call   1060 <die@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@.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 %9
7: ; preds = %1
%8 = call i32 @die(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = load %struct.termios*, %struct.termios** %2
%11 = bitcast %struct.termios* %3 to i8*
%12 = bitcast %struct.termios* %10 to i8*
%13 = call i32 @cfmakeraw(%struct.termios* %3)
%14 = load i32, i32* @TCSANOW
%15 = call i64 @tcsetattr(i32 0, i32 %14, %struct.termios* %3)
%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 = %17, %9
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.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 %8
6: ; preds = %1
%7 = tail call i32 @die(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = getelementptr %struct.termios, %struct.termios* %0, i64 0, i32 0
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = load i32, i32* %9
store i32 %11, i32* %10
%12 = call i32 @cfmakeraw(%struct.termios* %2)
%13 = load i32, i32* @TCSANOW
%14 = call i64 @tcsetattr(i32 0, i32 %13, %struct.termios* %2)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @die(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %8
ret void
}