#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 *c_cc;
  int /*<<< orphan*/ c_oflag;
  int /*<<< orphan*/ c_iflag;
  int /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ B19200;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
scalar_t__ cfsetispeed(struct termios *, int /*<<< orphan*/);
scalar_t__ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void raw(int fd) {
  struct termios it;
  if (tcgetattr(fd, &it) < 0) {
    perror("tcgetattr failed");
    err("get attr");
  }
  it.c_lflag &= 0;
  it.c_iflag &= 0;
  it.c_oflag &= 0;
  it.c_cc[VMIN] = 1;
  it.c_cc[VTIME] = 0;
  if (cfsetospeed(&it, B19200) < 0)
    err("set o speed");
  if (cfsetispeed(&it, B19200) < 0)
    err("set i speed");
  if (tcsetattr(fd, TCSANOW, &it) < 0)
    err("set attr");
}


x86 assembly (clang, -O0):
<raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1199 <raw+0x39>
lea    0xe78(%rip),%rdi
call   1080 <perror@plt>
lea    0xe7d(%rip),%rdi
call   1040 <err@plt>
mov    -0x10(%rbp),%eax
and    $0x0,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
and    $0x0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
and    $0x0,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e19(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2df4(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
cmp    $0x0,%rax
jge    1206 <raw+0xa6>
lea    0xe19(%rip),%rdi
call   1040 <err@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1070 <cfsetispeed@plt>
cmp    $0x0,%rax
jge    122e <raw+0xce>
lea    0xdfd(%rip),%rdi
call   1040 <err@plt>
mov    -0x4(%rbp),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
jge    1259 <raw+0xf9>
lea    0xdde(%rip),%rdi
call   1040 <err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raw>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
js     1218 <raw+0xb8>
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    (%rsp),%rax
mov    0x2e43(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e22(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e39(%rip),%rbx
mov    (%rbx),%esi
mov    %rsp,%rdi
call   1030 <cfsetospeed@plt>
test   %rax,%rax
jns    11d2 <raw+0x72>
lea    0xe4d(%rip),%rdi
call   1040 <err@plt>
mov    (%rbx),%esi
mov    %rsp,%rdi
call   1070 <cfsetispeed@plt>
test   %rax,%rax
jns    11ed <raw+0x8d>
lea    0xe3e(%rip),%rdi
call   1040 <err@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1060 <tcsetattr@plt>
test   %rax,%rax
jns    1211 <raw+0xb1>
lea    0xe26(%rip),%rdi
call   1040 <err@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xde1(%rip),%rdi
call   1080 <perror@plt>
lea    0xde6(%rip),%rdi
call   1040 <err@plt>
jmp    1179 <raw+0x19>

LLVM IR (-O0):
%struct.termios = type { i32*, i32, i32, i32 }
@.str = [17 x i8] c"tcgetattr failed\00"
@.str.1 = [9 x i8] c"get attr\00"
@VMIN = global i64 0
@VTIME = global i64 0
@B19200 = global i32 0
@.str.2 = [12 x i8] c"set o speed\00"
@.str.3 = [12 x i8] c"set i speed\00"
@TCSANOW = global i32 0
@.str.4 = [9 x i8] c"set attr\00"
define void @raw(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i64 @tcgetattr(i32 %4, %struct.termios* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @err(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
%11 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%12 = load i32, i32* %11
%13 = and i32 %12, 0
store i32 %13, i32* %11
%14 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%15 = load i32, i32* %14
%16 = and i32 %15, 0
store i32 %16, i32* %14
%17 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%18 = load i32, i32* %17
%19 = and i32 %18, 0
store i32 %19, i32* %17
%20 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%21 = load i32*, i32** %20
%22 = load i64, i64* @VMIN
%23 = getelementptr inbounds i32, i32* %21, i64 %22
store i32 1, i32* %23
%24 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%25 = load i32*, i32** %24
%26 = load i64, i64* @VTIME
%27 = getelementptr inbounds i32, i32* %25, i64 %26
store i32 0, i32* %27
%28 = load i32, i32* @B19200
%29 = call i64 @cfsetospeed(%struct.termios* %3, i32 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %10
%32 = call i32 @err(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %10
%34 = load i32, i32* @B19200
%35 = call i64 @cfsetispeed(%struct.termios* %3, i32 %34)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @err(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
%40 = load i32, i32* %2
%41 = load i32, i32* @TCSANOW
%42 = call i64 @tcsetattr(i32 %40, i32 %41, %struct.termios* %3)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = call i32 @err(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %39
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32, i32, i32 }
@.str = [17 x i8] c"tcgetattr failed\00"
@.str.1 = [9 x i8] c"get attr\00"
@VMIN = global i64 0
@VTIME = global i64 0
@B19200 = global i32 0
@.str.2 = [12 x i8] c"set o speed\00"
@.str.3 = [12 x i8] c"set i speed\00"
@TCSANOW = global i32 0
@.str.4 = [9 x i8] c"set attr\00"
define void @raw(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i64 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @err(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %6, %1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
store i32 0, i32* %10
%11 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
store i32 0, i32* %11
%12 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
store i32 0, i32* %12
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%14 = load i32*, i32** %13
%15 = load i64, i64* @VMIN
%16 = getelementptr inbounds i32, i32* %14, i64 %15
store i32 1, i32* %16
%17 = load i64, i64* @VTIME
%18 = getelementptr inbounds i32, i32* %14, i64 %17
store i32 0, i32* %18
%19 = load i32, i32* @B19200
%20 = call i64 @cfsetospeed(%struct.termios* %2, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %9
%23 = call i32 @err(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %9
%25 = load i32, i32* @B19200
%26 = call i64 @cfsetispeed(%struct.termios* %2, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 @err(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = load i32, i32* @TCSANOW
%32 = call i64 @tcsetattr(i32 %0, i32 %31, %struct.termios* %2)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @err(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
ret void
}