#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_iflag;
  scalar_t__ *c_cc;
  scalar_t__ c_oflag;
  scalar_t__ c_lflag;
};

/* Variables and functions */
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int IGNBRK;
int IXANY;
int IXOFF;
int IXON;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set_interface_attribs(int fd, int speed, int parity) {
  struct termios tty;
  if (tcgetattr(fd, &tty) != 0) {
    printf("Error getting attributes\n");
    return -1;
  }
  cfsetospeed(&tty, speed);
  cfsetispeed(&tty, speed);
  tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
  tty.c_iflag &= ~IGNBRK;
  tty.c_lflag = 0;
  tty.c_oflag = 0;
  tty.c_cc[VMIN] = 0;
  tty.c_cc[VTIME] = 0;
  tty.c_iflag &= ~(IXON | IXOFF | IXANY);
  tty.c_cflag |= (CLOCAL | CREAD);
  tty.c_cflag &= ~(PARENB | PARODD);
  tty.c_cflag |= parity;
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~CRTSCTS;
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    printf("Error Setting Attributes\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_interface_attribs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
je     118f <set_interface_attribs+0x3f>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d4 <set_interface_attribs+0x184>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x30(%rbp),%eax
mov    0x2df7(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2df9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2dbf(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    0x2d81(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    0x2dc6(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6d(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d2b(%rip),%rax
mov    (%rax),%eax
mov    0x2d7a(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    0x2d6a(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     12cd <set_interface_attribs+0x17d>
lea    0xd5e(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d4 <set_interface_attribs+0x184>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_interface_attribs>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
je     117c <set_interface_attribs+0x2c>
lea    0xea2(%rip),%rdi
jmp    1274 <set_interface_attribs+0x124>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <cfsetospeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2e0d(%rip),%rcx
or     (%rcx),%eax
mov    0x2ddc(%rip),%rcx
mov    (%rcx),%ecx
mov    0xc(%rsp),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rsp),%rsi
mov    0x2de2(%rip),%rdi
mov    (%rdi),%rdi
movq   $0x0,(%rsi,%rdi,8)
mov    0x2da8(%rip),%rdi
mov    (%rdi),%rdi
movq   $0x0,(%rsi,%rdi,8)
mov    0x2dee(%rip),%rsi
mov    0x2def(%rip),%rdi
mov    (%rdi),%edi
or     (%rsi),%edi
mov    0x2d94(%rip),%rsi
or     (%rsi),%edi
or     %ecx,%edi
not    %edi
and    %edx,%edi
mov    %edi,0xc(%rsp)
mov    0x2d51(%rip),%rcx
mov    0x2da2(%rip),%rdx
or     (%rcx),%eax
or     (%rdx),%eax
mov    0x2daf(%rip),%rcx
mov    0x2d98(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
not    %edx
and    %eax,%edx
or     %r15d,%edx
mov    0x2d2e(%rip),%rax
mov    (%rax),%eax
mov    0x2d2d(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %edx,%eax
mov    %eax,0x8(%rsp)
mov    0x2d74(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
je     1289 <set_interface_attribs+0x139>
lea    0xd8c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    127e <set_interface_attribs+0x12e>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i64*, i64, i64 }
@.str = [26 x i8] c"Error getting attributes\0A\00"
@CSIZE = global i32 0
@CS8 = global i32 0
@IGNBRK = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@.str.1 = [26 x i8] c"Error Setting Attributes\0A\00"
define i32 @set_interface_attribs(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.termios
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %5
%10 = call i64 @tcgetattr(i32 %9, %struct.termios* %8)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %85
14: ; preds = %3
%15 = load i32, i32* %6
%16 = call i32 @cfsetospeed(%struct.termios* %8, i32 %15)
%17 = load i32, i32* %6
%18 = call i32 @cfsetispeed(%struct.termios* %8, i32 %17)
%19 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load i32, i32* @CSIZE
%22 = xor i32 %21, -1
%23 = and i32 %20, %22
%24 = load i32, i32* @CS8
%25 = or i32 %23, %24
%26 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @IGNBRK
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 4
store i64 0, i64* %32
%33 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
store i64 0, i64* %33
%34 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%35 = load i64*, i64** %34
%36 = load i64, i64* @VMIN
%37 = getelementptr inbounds i64, i64* %35, i64 %36
store i64 0, i64* %37
%38 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%39 = load i64*, i64** %38
%40 = load i64, i64* @VTIME
%41 = getelementptr inbounds i64, i64* %39, i64 %40
store i64 0, i64* %41
%42 = load i32, i32* @IXON
%43 = load i32, i32* @IXOFF
%44 = or i32 %42, %43
%45 = load i32, i32* @IXANY
%46 = or i32 %44, %45
%47 = xor i32 %46, -1
%48 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%49 = load i32, i32* %48
%50 = and i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @CLOCAL
%52 = load i32, i32* @CREAD
%53 = or i32 %51, %52
%54 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%55 = load i32, i32* %54
%56 = or i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @PARENB
%58 = load i32, i32* @PARODD
%59 = or i32 %57, %58
%60 = xor i32 %59, -1
%61 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%62 = load i32, i32* %61
%63 = and i32 %62, %60
store i32 %63, i32* %61
%64 = load i32, i32* %7
%65 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%66 = load i32, i32* %65
%67 = or i32 %66, %64
store i32 %67, i32* %65
%68 = load i32, i32* @CSTOPB
%69 = xor i32 %68, -1
%70 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%71 = load i32, i32* %70
%72 = and i32 %71, %69
store i32 %72, i32* %70
%73 = load i32, i32* @CRTSCTS
%74 = xor i32 %73, -1
%75 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%76 = load i32, i32* %75
%77 = and i32 %76, %74
store i32 %77, i32* %75
%78 = load i32, i32* %5
%79 = load i32, i32* @TCSANOW
%80 = call i64 @tcsetattr(i32 %78, i32 %79, %struct.termios* %8)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %14
%83 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %85
84: ; preds = %14
store i32 0, i32* %4
br label %85
85: ; preds = %84, %82, %12
%86 = load i32, i32* %4
ret i32 %86
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i64*, i64, i64 }
@CSIZE = global i32 0
@CS8 = global i32 0
@IGNBRK = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@str = [25 x i8] c"Error Setting Attributes\00"
@str.2 = [25 x i8] c"Error getting attributes\00"
define i32 @set_interface_attribs(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.termios
%5 = bitcast %struct.termios* %4 to i8*
%6 = call i64 @tcgetattr(i32 %0, %struct.termios* %4)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %55
8: ; preds = %3
%9 = call i32 @cfsetospeed(%struct.termios* %4, i32 %1)
%10 = call i32 @cfsetispeed(%struct.termios* %4, i32 %1)
%11 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%12 = load i32, i32* %11
%13 = load i32, i32* @CSIZE
%14 = xor i32 %13, -1
%15 = and i32 %12, %14
%16 = load i32, i32* @CS8
%17 = or i32 %15, %16
%18 = load i32, i32* @IGNBRK
%19 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 3
%22 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%23 = bitcast i64* %21 to i8*
%24 = load i64*, i64** %22
%25 = load i64, i64* @VMIN
%26 = getelementptr inbounds i64, i64* %24, i64 %25
store i64 0, i64* %26
%27 = load i64, i64* @VTIME
%28 = getelementptr inbounds i64, i64* %24, i64 %27
store i64 0, i64* %28
%29 = load i32, i32* @IXON
%30 = load i32, i32* @IXOFF
%31 = or i32 %30, %29
%32 = load i32, i32* @IXANY
%33 = or i32 %31, %32
%34 = or i32 %18, %33
%35 = xor i32 %34, -1
%36 = and i32 %20, %35
store i32 %36, i32* %19
%37 = load i32, i32* @CLOCAL
%38 = load i32, i32* @CREAD
%39 = or i32 %37, %17
%40 = or i32 %39, %38
%41 = load i32, i32* @PARENB
%42 = load i32, i32* @PARODD
%43 = or i32 %42, %41
%44 = xor i32 %43, -1
%45 = and i32 %40, %44
%46 = or i32 %45, %2
%47 = load i32, i32* @CSTOPB
%48 = load i32, i32* @CRTSCTS
%49 = or i32 %47, %48
%50 = xor i32 %49, -1
%51 = and i32 %46, %50
store i32 %51, i32* %11
%52 = load i32, i32* @TCSANOW
%53 = call i64 @tcsetattr(i32 %0, i32 %52, %struct.termios* %4)
%54 = icmp eq i64 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %8, %3
%56 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0), %8 ]
%57 = call i32 @puts(i8* dereferenceable(1) %56)
br label %58
58: ; preds = %55, %8
%59 = phi i32 [ 0, %8 ], [ -1, %55 ]
ret i32 %59
}