#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_cflag;
  int *c_cc;
};

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CREAD;
int CS8;
int CSTOPB;
int PARENB;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ errExit(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
void set_attr(int fd) {
  struct termios tp;
  if (tcgetattr(fd, &tp) == -1)
    errExit("tcgetattr");
  if (cfsetispeed(&tp, B9600) == -1)
    errExit("cfsetispeed");
  tp.c_cflag = CS8 | CREAD;
  tp.c_cflag &= ~PARENB;
  tp.c_cflag &= ~CSTOPB;
  tp.c_cc[VMIN] = 1;
  tp.c_cc[VTIME] = 0;
  tcflush(fd, TCIOFLUSH);
  if (tcsetattr(fd, TCSANOW, &tp) == -1)
    errExit("tcsetattr");
}


x86 assembly (clang, -O0):
<set_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    117c <set_attr+0x2c>
lea    0xe89(%rip),%rdi
call   1030 <errExit@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1070 <cfsetispeed@plt>
cmp    $0xffffffff,%eax
jne    11a3 <set_attr+0x53>
lea    0xe6c(%rip),%rdi
call   1030 <errExit@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    0x2e1d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2dd9(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x2dac(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x4(%rbp),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1241 <set_attr+0xf1>
lea    0xdda(%rip),%rdi
call   1030 <errExit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_attr>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1170 <set_attr+0x20>
lea    0xe95(%rip),%rdi
call   1030 <errExit@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1070 <cfsetispeed@plt>
cmp    $0xffffffff,%eax
jne    1192 <set_attr+0x42>
lea    0xe7d(%rip),%rdi
call   1030 <errExit@plt>
mov    0x2e2f(%rip),%rax
mov    0x2e30(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    0x2de4(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    %eax,(%rsp)
mov    0x8(%rsp),%rax
mov    0x2df7(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2dce(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1060 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1218 <set_attr+0xc8>
lea    0xe03(%rip),%rdi
call   1030 <errExit@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32* }
@.str = [10 x i8] c"tcgetattr\00"
@B9600 = global i32 0
@.str.1 = [12 x i8] c"cfsetispeed\00"
@CS8 = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.2 = [10 x i8] c"tcsetattr\00"
define void @set_attr(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @tcgetattr(i32 %4, %struct.termios* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @errExit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = load i32, i32* @B9600
%11 = call i32 @cfsetispeed(%struct.termios* %3, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @errExit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = load i32, i32* @CS8
%17 = load i32, i32* @CREAD
%18 = or i32 %16, %17
%19 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @PARENB
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* @CSTOPB
%26 = xor i32 %25, -1
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%28 = load i32, i32* %27
%29 = and i32 %28, %26
store i32 %29, i32* %27
%30 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%31 = load i32*, i32** %30
%32 = load i64, i64* @VMIN
%33 = getelementptr inbounds i32, i32* %31, i64 %32
store i32 1, i32* %33
%34 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%35 = load i32*, i32** %34
%36 = load i64, i64* @VTIME
%37 = getelementptr inbounds i32, i32* %35, i64 %36
store i32 0, i32* %37
%38 = load i32, i32* %2
%39 = load i32, i32* @TCIOFLUSH
%40 = call i32 @tcflush(i32 %38, i32 %39)
%41 = load i32, i32* %2
%42 = load i32, i32* @TCSANOW
%43 = call i32 @tcsetattr(i32 %41, i32 %42, %struct.termios* %3)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %15
%46 = call i32 @errExit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %15
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32* }
@.str = [10 x i8] c"tcgetattr\00"
@B9600 = global i32 0
@.str.1 = [12 x i8] c"cfsetispeed\00"
@CS8 = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
@.str.2 = [10 x i8] c"tcsetattr\00"
define void @set_attr(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @errExit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* @B9600
%10 = call i32 @cfsetispeed(%struct.termios* %2, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @errExit(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32, i32* @CS8
%16 = load i32, i32* @CREAD
%17 = or i32 %16, %15
%18 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%19 = load i32, i32* @PARENB
%20 = load i32, i32* @CSTOPB
%21 = or i32 %19, %20
%22 = xor i32 %21, -1
%23 = and i32 %17, %22
store i32 %23, i32* %18
%24 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%25 = load i32*, i32** %24
%26 = load i64, i64* @VMIN
%27 = getelementptr inbounds i32, i32* %25, i64 %26
store i32 1, i32* %27
%28 = load i64, i64* @VTIME
%29 = getelementptr inbounds i32, i32* %25, i64 %28
store i32 0, i32* %29
%30 = load i32, i32* @TCIOFLUSH
%31 = call i32 @tcflush(i32 %0, i32 %30)
%32 = load i32, i32* @TCSANOW
%33 = call i32 @tcsetattr(i32 %0, i32 %32, %struct.termios* %2)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %14
%36 = call i32 @errExit(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %14
ret void
}