#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*/ abort();
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ perror(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) {
    perror(("Unable to read terminal attributes: %m"));
    abort();
  };
  set = *save;
  cfmakeraw(&set);
  if ((tcsetattr(0, TCSANOW, &set)) < 0) {
    perror(("Unable to set terminal attributes: %m"));
    abort();
  };
}


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    1184 <setup_raw+0x34>
lea    0xe88(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <cfmakeraw@plt>
mov    0x2e4b(%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    0xe6c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x0,%al
call   1030 <abort@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     1198 <setup_raw+0x48>
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
js     11a1 <setup_raw+0x51>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe61(%rip),%rdi
jmp    11a8 <setup_raw+0x58>
lea    0xe7f(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

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 %10
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @abort()
unreachable
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 %21
18: ; preds = %10
%19 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %10
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 %9
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 (...) @abort()
unreachable
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 %20
17: ; preds = %9
%18 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %9
ret void
}