#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*/ memcpy(struct termios *, struct termios *, int);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set_tty_raw(int fd, struct termios *origin_attr) {
  struct termios attr[1];
  if (tcgetattr(fd, attr) == -1)
    return -1;
  memcpy(origin_attr, attr, sizeof(struct termios));
  cfmakeraw(attr);
  return tcsetattr(fd, TCSANOW, attr);
}


x86 assembly (clang, -O0):
<set_tty_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1170 <set_tty_raw+0x30>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <set_tty_raw+0x63>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
lea    -0x18(%rbp),%rdi
call   1040 <cfmakeraw@plt>
mov    -0x8(%rbp),%edi
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_tty_raw>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     118f <set_tty_raw+0x4f>
lea    0x8(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    %r15,%rdi
call   1040 <cfmakeraw@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r15,%rdx
call   1060 <tcsetattr@plt>
jmp    1194 <set_tty_raw+0x54>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@TCSANOW = global i32 0
define i32 @set_tty_raw(i32 %0, %struct.termios* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios*
%6 = alloca [1 x %struct.termios]
store i32 %0, i32* %4
store %struct.termios* %1, %struct.termios** %5
%7 = load i32, i32* %4
%8 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %6, i64 0, i64 0
%9 = call i32 @tcgetattr(i32 %7, %struct.termios* %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %22
12: ; preds = %2
%13 = load %struct.termios*, %struct.termios** %5
%14 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %6, i64 0, i64 0
%15 = call i32 @memcpy(%struct.termios* %13, %struct.termios* %14, i32 4)
%16 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %6, i64 0, i64 0
%17 = call i32 @cfmakeraw(%struct.termios* %16)
%18 = load i32, i32* %4
%19 = load i32, i32* @TCSANOW
%20 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %6, i64 0, i64 0
%21 = call i32 @tcsetattr(i32 %18, i32 %19, %struct.termios* %20)
store i32 %21, i32* %3
br label %22
22: ; preds = %12, %11
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TCSANOW = global i32 0
define i32 @set_tty_raw(i32 %0, %struct.termios* %1) {
%3 = alloca [1 x %struct.termios]
%4 = bitcast [1 x %struct.termios]* %3 to i8*
%5 = getelementptr inbounds [1 x %struct.termios], [1 x %struct.termios]* %3, i64 0, i64 0
%6 = call i32 @tcgetattr(i32 %0, %struct.termios* %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = call i32 @memcpy(%struct.termios* %1, %struct.termios* %5, i32 4)
%10 = call i32 @cfmakeraw(%struct.termios* %5)
%11 = load i32, i32* @TCSANOW
%12 = call i32 @tcsetattr(i32 %0, i32 %11, %struct.termios* %5)
br label %13
13: ; preds = %2, %8
%14 = phi i32 [ %12, %8 ], [ -1, %2 ]
ret i32 %14
}