#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;
scalar_t__ cfsetispeed(struct termios *, int);
scalar_t__ cfsetospeed(struct termios *, int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
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) {
    fprintf(stderr, "error %d from tcgetattr.\n", errno);
    return -1;
  }
  if (cfsetospeed(&tty, speed)) {
    fprintf(stderr, "error %d from cfsetospeed.\n", errno);
    return -1;
  }
  if (cfsetispeed(&tty, speed)) {
    fprintf(stderr, "error %d from cfsetispeed.\n", errno);
    return -1;
  }
  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) {
    fprintf(stderr, "error %d from tcsetattr.\n", errno);
    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     11c1 <set_interface_attribs+0x61>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1380 <set_interface_attribs+0x220>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
cmp    $0x0,%rax
je     1201 <set_interface_attribs+0xa1>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
mov    0x2da1(%rip),%rax
mov    (%rax),%edx
lea    0xe2a(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1380 <set_interface_attribs+0x220>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
cmp    $0x0,%rax
je     1241 <set_interface_attribs+0xe1>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%edx
lea    0xe06(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1380 <set_interface_attribs+0x220>
mov    -0x30(%rbp),%eax
mov    0x2d5d(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2d5f(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d1b(%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    0x2d25(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    0x2cd7(%rip),%rcx
mov    (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    0x2d2c(%rip),%rcx
or     (%rcx),%eax
mov    0x2cd3(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2c81(%rip),%rax
mov    (%rax),%eax
mov    0x2ce0(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ce9(%rip),%rax
mov    (%rax),%eax
mov    0x2cd0(%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    0x2c4d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c43(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2c96(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     1379 <set_interface_attribs+0x219>
mov    0x2c3a(%rip),%rax
mov    (%rax),%edi
mov    0x2c29(%rip),%rax
mov    (%rax),%edx
lea    0xcea(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1380 <set_interface_attribs+0x220>
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,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1060 <tcgetattr@plt>
test   %rax,%rax
je     11a2 <set_interface_attribs+0x42>
lea    0xe63(%rip),%rsi
jmp    12be <set_interface_attribs+0x15e>
lea    0x8(%rsp),%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
test   %rax,%rax
je     11bf <set_interface_attribs+0x5f>
lea    0xe60(%rip),%rsi
jmp    12be <set_interface_attribs+0x15e>
lea    0x8(%rsp),%rdi
mov    %ebp,%esi
call   1080 <cfsetispeed@plt>
test   %rax,%rax
je     11dc <set_interface_attribs+0x7c>
lea    0xe5f(%rip),%rsi
jmp    12be <set_interface_attribs+0x15e>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2dc6(%rip),%rcx
or     (%rcx),%eax
mov    0x2d85(%rip),%rcx
mov    (%rcx),%ecx
mov    0xc(%rsp),%edx
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rsp),%rsi
mov    0x2d9b(%rip),%rdi
mov    (%rdi),%rdi
movq   $0x0,(%rsi,%rdi,8)
mov    0x2d51(%rip),%rdi
mov    (%rdi),%rdi
movq   $0x0,(%rsi,%rdi,8)
mov    0x2da7(%rip),%rsi
mov    0x2da8(%rip),%rdi
mov    (%rdi),%edi
or     (%rsi),%edi
mov    0x2d4d(%rip),%rsi
or     (%rsi),%edi
or     %ecx,%edi
not    %edi
and    %edx,%edi
mov    %edi,0xc(%rsp)
mov    0x2cfa(%rip),%rcx
mov    0x2d5b(%rip),%rdx
or     (%rcx),%eax
or     (%rdx),%eax
mov    0x2d68(%rip),%rcx
mov    0x2d51(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
not    %edx
and    %eax,%edx
or     %r14d,%edx
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
mov    0x2cd6(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %edx,%eax
mov    %eax,0x8(%rsp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r15d,%edi
call   1070 <tcsetattr@plt>
test   %rax,%rax
je     12e5 <set_interface_attribs+0x185>
lea    0xd94(%rip),%rsi
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
mov    0x2cba(%rip),%rax
mov    (%rax),%edx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    12da <set_interface_attribs+0x17a>

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

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