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

/* Variables and functions */
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
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 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", errno);
    return -1;
  }
  cfsetospeed(&tty, speed);
  cfsetispeed(&tty, speed);
  tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
  tty.c_lflag = 0;
  tty.c_oflag = 0;
  tty.c_cc[VMIN] = 0;
  tty.c_cc[VTIME] = 5;
  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", 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    0x2e0a(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%edx
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <set_interface_attribs+0x180>
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    0x2dd5(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2dd7(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2daf(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2d72(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    0x2d90(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    0x2d80(%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    0x2d0d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     12d9 <set_interface_attribs+0x179>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
mov    0x2ce1(%rip),%rax
mov    (%rax),%edx
lea    0xd50(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <set_interface_attribs+0x180>
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     11a9 <set_interface_attribs+0x49>
lea    0xe5c(%rip),%rsi
jmp    1276 <set_interface_attribs+0x116>
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    0x2def(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x8(%rsp),%eax
mov    0x2df0(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2dce(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d95(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d64(%rip),%rax
mov    0x2db5(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2dbe(%rip),%rax
mov    0x2da7(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
not    %edx
and    %ecx,%edx
or     %r14d,%edx
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
mov    0x2d3c(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %edx,%eax
mov    %eax,0x8(%rsp)
mov    0x2d83(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    %r15,%rdx
call   1070 <tcsetattr@plt>
test   %rax,%rax
je     1293 <set_interface_attribs+0x133>
lea    0xda2(%rip),%rsi
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
mov    0x2d1a(%rip),%rax
mov    (%rax),%edx
call   1050 <fprintf@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*, i64, i64 }
@stderr = global i32 0
@.str = [24 x i8] c"error %d from tcgetattr\00"
@errno = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@VMIN = global i64 0
@VTIME = global i64 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 %17
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 -1, i32* %4
br label %76
17: ; preds = %3
%18 = load i32, i32* %6
%19 = call i32 @cfsetospeed(%struct.termios* %8, i32 %18)
%20 = load i32, i32* %6
%21 = call i32 @cfsetispeed(%struct.termios* %8, i32 %20)
%22 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i32, i32* @CSIZE
%25 = xor i32 %24, -1
%26 = and i32 %23, %25
%27 = load i32, i32* @CS8
%28 = or i32 %26, %27
%29 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
store i64 0, i64* %30
%31 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
store i64 0, i64* %31
%32 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%33 = load i32*, i32** %32
%34 = load i64, i64* @VMIN
%35 = getelementptr inbounds i32, i32* %33, i64 %34
store i32 0, i32* %35
%36 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%37 = load i32*, i32** %36
%38 = load i64, i64* @VTIME
%39 = getelementptr inbounds i32, i32* %37, i64 %38
store i32 5, i32* %39
%40 = load i32, i32* @CLOCAL
%41 = load i32, i32* @CREAD
%42 = or i32 %40, %41
%43 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%44 = load i32, i32* %43
%45 = or i32 %44, %42
store i32 %45, i32* %43
%46 = load i32, i32* @PARENB
%47 = load i32, i32* @PARODD
%48 = or i32 %46, %47
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%51 = load i32, i32* %50
%52 = and i32 %51, %49
store i32 %52, i32* %50
%53 = load i32, i32* %7
%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* @CSTOPB
%58 = xor i32 %57, -1
%59 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%60 = load i32, i32* %59
%61 = and i32 %60, %58
store i32 %61, i32* %59
%62 = load i32, i32* @CRTSCTS
%63 = xor i32 %62, -1
%64 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%65 = load i32, i32* %64
%66 = and i32 %65, %63
store i32 %66, i32* %64
%67 = load i32, i32* %5
%68 = load i32, i32* @TCSANOW
%69 = call i64 @tcsetattr(i32 %67, i32 %68, %struct.termios* %8)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %17
%72 = load i32, i32* @stderr
%73 = load i32, i32* @errno
%74 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %73)
store i32 -1, i32* %4
br label %76
75: ; preds = %17
store i32 0, i32* %4
br label %76
76: ; preds = %75, %71, %13
%77 = load i32, i32* %4
ret i32 %77
}

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