#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 errno;
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, 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) {
    printf("error %d from tcgetattr", errno);
    return -1;
  }
  cfsetospeed(&tty, speed);
  cfsetispeed(&tty, speed);
  tty.c_cflag &= ~(PARENB | PARODD);
  tty.c_cflag |= parity;
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
  tty.c_cflag &= ~CRTSCTS;
  tty.c_cflag |= (CLOCAL | CREAD);
  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);
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    printf("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   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0x0,%rax
je     11b8 <set_interface_attribs+0x58>
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <set_interface_attribs+0x1a4>
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    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    0x2de8(%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    0x2d6d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    0x2d98(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2d9a(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d24(%rip),%rax
mov    (%rax),%eax
mov    0x2d7b(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d34(%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    0x2d36(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2cf1(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
mov    0x2d3f(%rip),%rcx
or     (%rcx),%eax
mov    0x2ce6(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     12fd <set_interface_attribs+0x19d>
mov    0x2cad(%rip),%rax
mov    (%rax),%esi
lea    0xd2c(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1304 <set_interface_attribs+0x1a4>
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,%r15d
mov    %esi,%ebp
mov    %edi,%r12d
lea    0x8(%rsp),%rbx
xor    %r13d,%r13d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1060 <tcgetattr@plt>
test   %rax,%rax
je     11a9 <set_interface_attribs+0x49>
lea    0xe5c(%rip),%rdi
jmp    129e <set_interface_attribs+0x13e>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1080 <cfsetispeed@plt>
mov    0x2e0f(%rip),%rax
mov    0x2df8(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    0x2dc4(%rip),%rdx
or     (%rdx),%eax
not    %ecx
and    0x8(%rsp),%ecx
or     %r15d,%ecx
not    %eax
and    %ecx,%eax
mov    0x2dbe(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6d(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    0x2d50(%rip),%rax
mov    0x2da9(%rip),%rdx
or     (%rax),%ecx
or     (%rdx),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2d6e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d2d(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d7c(%rip),%rax
mov    0x2d7d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d22(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0xc(%rsp)
mov    0x2d4b(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
test   %rax,%rax
je     12b2 <set_interface_attribs+0x152>
lea    0xd7a(%rip),%rdi
mov    0x2ceb(%rip),%rax
mov    (%rax),%esi
call   1040 <printf@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"
@errno = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@CLOCAL = global i32 0
@CREAD = 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
@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 %16
13: ; preds = %3
%14 = load i32, i32* @errno
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 -1, i32* %4
br label %88
16: ; preds = %3
%17 = load i32, i32* %6
%18 = call i32 @cfsetospeed(%struct.termios* %8, i32 %17)
%19 = load i32, i32* %6
%20 = call i32 @cfsetispeed(%struct.termios* %8, i32 %19)
%21 = load i32, i32* @PARENB
%22 = load i32, i32* @PARODD
%23 = or i32 %21, %22
%24 = xor i32 %23, -1
%25 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%26 = load i32, i32* %25
%27 = and i32 %26, %24
store i32 %27, i32* %25
%28 = load i32, i32* %7
%29 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%30 = load i32, i32* %29
%31 = or i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @CSTOPB
%33 = xor i32 %32, -1
%34 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%35 = load i32, i32* %34
%36 = and i32 %35, %33
store i32 %36, i32* %34
%37 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%38 = load i32, i32* %37
%39 = load i32, i32* @CSIZE
%40 = xor i32 %39, -1
%41 = and i32 %38, %40
%42 = load i32, i32* @CS8
%43 = or i32 %41, %42
%44 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
store i32 %43, i32* %44
%45 = load i32, i32* @CRTSCTS
%46 = xor i32 %45, -1
%47 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%48 = load i32, i32* %47
%49 = and i32 %48, %46
store i32 %49, i32* %47
%50 = load i32, i32* @CLOCAL
%51 = load i32, i32* @CREAD
%52 = or i32 %50, %51
%53 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%54 = load i32, i32* %53
%55 = or i32 %54, %52
store i32 %55, i32* %53
%56 = load i32, i32* @IGNBRK
%57 = xor i32 %56, -1
%58 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%59 = load i32, i32* %58
%60 = and i32 %59, %57
store i32 %60, i32* %58
%61 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 4
store i64 0, i64* %61
%62 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
store i64 0, i64* %62
%63 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%64 = load i32*, i32** %63
%65 = load i64, i64* @VMIN
%66 = getelementptr inbounds i32, i32* %64, i64 %65
store i32 0, i32* %66
%67 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%68 = load i32*, i32** %67
%69 = load i64, i64* @VTIME
%70 = getelementptr inbounds i32, i32* %68, i64 %69
store i32 5, i32* %70
%71 = load i32, i32* @IXON
%72 = load i32, i32* @IXOFF
%73 = or i32 %71, %72
%74 = load i32, i32* @IXANY
%75 = or i32 %73, %74
%76 = xor i32 %75, -1
%77 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%78 = load i32, i32* %77
%79 = and i32 %78, %76
store i32 %79, i32* %77
%80 = load i32, i32* %5
%81 = load i32, i32* @TCSANOW
%82 = call i64 @tcsetattr(i32 %80, i32 %81, %struct.termios* %8)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %16
%85 = load i32, i32* @errno
%86 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %85)
store i32 -1, i32* %4
br label %88
87: ; preds = %16
store i32 0, i32* %4
br label %88
88: ; preds = %87, %84, %13
%89 = load i32, i32* %4
ret i32 %89
}

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