#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 {
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
  scalar_t__ c_iflag;
};

/* Variables and functions */
int /*<<< orphan*/ TCSANOW;
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;
  set.c_iflag = 0;
  set.c_oflag = 0;
  set.c_lflag = 0;
  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    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1030 <tcgetattr@plt>
cmp    $0x0,%rax
jge    115d <setup_raw+0x2d>
lea    0xea8(%rip),%rdi
call   1050 <die@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,-0x20(%rbp)
mov    0x8(%rax),%rcx
mov    %rcx,-0x18(%rbp)
mov    0x10(%rax),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x20(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
jge    11ba <setup_raw+0x8a>
lea    0xe72(%rip),%rdi
call   1050 <die@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_raw>:
sub    $0x18,%rsp
mov    %rdi,%rsi
xor    %edi,%edi
call   1030 <tcgetattr@plt>
test   %rax,%rax
jns    114f <setup_raw+0x1f>
lea    0xeb6(%rip),%rdi
call   1050 <die@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
xor    %edi,%edi
call   1040 <tcsetattr@plt>
test   %rax,%rax
js     117c <setup_raw+0x4c>
add    $0x18,%rsp
ret
lea    0xea4(%rip),%rdi
call   1050 <die@plt>
add    $0x18,%rsp
ret

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

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