#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;
  int *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*/ error_message(char *, int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
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;
  memset(&tty, 0, sizeof tty);
  if (tcgetattr(fd, &tty) != 0) {
    error_message("error %d from tcgetattr", -1);
    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] = 5;
  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) {
    error_message("error %d from tcsetattr", -2);
    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)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0x0,%rax
je     11b4 <set_interface_attribs+0x54>
lea    0xe62(%rip),%rdi
mov    $0xffffffff,%esi
call   1050 <error_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fc <set_interface_attribs+0x19c>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    -0x30(%rbp),%eax
mov    0x2dd2(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2dd4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2da0(%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    0x2d9a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2d5d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    0x2da3(%rip),%rcx
or     (%rcx),%eax
mov    0x2d4a(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    0x2d57(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    0x2d47(%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    0x2cd4(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cca(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     12f5 <set_interface_attribs+0x195>
lea    0xd39(%rip),%rdi
mov    $0xfffffffe,%esi
call   1050 <error_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12fc <set_interface_attribs+0x19c>
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   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r12d
lea    0x8(%rsp),%rbx
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1060 <tcgetattr@plt>
test   %rax,%rax
je     11b9 <set_interface_attribs+0x59>
lea    0xe5c(%rip),%rdi
mov    $0xffffffff,%r13d
mov    $0xffffffff,%esi
call   1050 <error_message@plt>
jmp    12c6 <set_interface_attribs+0x166>
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1080 <cfsetispeed@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2dd0(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2d9f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d66(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2dad(%rip),%rax
mov    0x2dae(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d53(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0xc(%rsp)
mov    0x2d14(%rip),%rax
mov    0x2d65(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2d6e(%rip),%rax
mov    0x2d57(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
not    %edx
and    %ecx,%edx
or     %r14d,%edx
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
mov    0x2cec(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %edx,%eax
mov    %eax,0x8(%rsp)
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    %r15,%rdx
call   1070 <tcsetattr@plt>
test   %rax,%rax
je     12c6 <set_interface_attribs+0x166>
lea    0xd62(%rip),%rdi
mov    $0xfffffffe,%esi
call   1050 <error_message@plt>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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