#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_lflag;
  int *c_cc;
  int /*<<< orphan*/ c_oflag;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ speed_t;

/* Variables and functions */
int BRKINT;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHONL;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNBRK;
int IGNCR;
int INLCR;
int ISIG;
int ISTRIP;
int IXON;
int /*<<< orphan*/ OPOST;
int PARENB;
int PARMRK;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int set_interface_attribs(int fd, int speed) {
  int retCode = 0;
  struct termios tty = {0};
  if (tcgetattr(fd, &tty) < 0) {
    fprintf(stderr, "Error from tcgetattr: %s\n", strerror(errno));
    retCode = -1;
  } else {
    cfsetospeed(&tty, (speed_t)speed);
    cfsetispeed(&tty, (speed_t)speed);
    tty.c_cflag |= (CLOCAL | CREAD);
    tty.c_cflag &= ~CSIZE;
    tty.c_cflag |= CS8;
    tty.c_cflag &= ~PARENB;
    tty.c_cflag &= ~CSTOPB;
    tty.c_cflag &= ~CRTSCTS;
    tty.c_iflag &=
        ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
    tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
    tty.c_oflag &= ~OPOST;
    tty.c_cc[VMIN] = 1;
    tty.c_cc[VTIME] = 1;
    if (tcsetattr(fd, TCSANOW, &tty) != 0) {
      fprintf(stderr, "Error from tcsetattr: %s\n", strerror(errno));
      retCode = -2;
    }
  }
  return retCode;
}


x86 assembly (clang, -O0):
<set_interface_attribs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0x0,%rax
jge    11e3 <set_interface_attribs+0x73>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe2e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    1384 <set_interface_attribs+0x214>
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%eax
mov    0x2d85(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ccb(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cc1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%eax
mov    0x2d1e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6d(%rip),%rcx
or     (%rcx),%eax
mov    0x2cc4(%rip),%rcx
or     (%rcx),%eax
mov    0x2d43(%rip),%rcx
or     (%rcx),%eax
mov    0x2d32(%rip),%rcx
or     (%rcx),%eax
mov    0x2d39(%rip),%rcx
or     (%rcx),%eax
mov    0x2d10(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
mov    0x2c7d(%rip),%rcx
or     (%rcx),%eax
mov    0x2c5c(%rip),%rcx
or     (%rcx),%eax
mov    0x2cc3(%rip),%rcx
or     (%rcx),%eax
mov    0x2c8a(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2cd0(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2c72(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2c15(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2c79(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     137f <set_interface_attribs+0x20f>
mov    0x2c0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2bf9(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xca7(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xfffffffe,-0xc(%rbp)
jmp    1384 <set_interface_attribs+0x214>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_interface_attribs>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
js     12ca <set_interface_attribs+0x16a>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    0x2d69(%rip),%rax
mov    0x2de2(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    0x2dbf(%rip),%rcx
or     (%rcx),%eax
mov    0x2de6(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d3d(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d3c(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d53(%rip),%rdx
mov    0x2da4(%rip),%rsi
mov    (%rsi),%esi
or     (%rdx),%esi
mov    0x2df1(%rip),%rdx
or     (%rdx),%esi
mov    0x2d48(%rip),%rdx
or     (%rdx),%esi
mov    0x2dc7(%rip),%rdx
or     (%rdx),%esi
not    %ecx
and    %eax,%ecx
mov    0x2db2(%rip),%rax
or     (%rax),%esi
mov    %ecx,(%rsp)
mov    0x2db6(%rip),%rax
or     (%rax),%esi
mov    0x2d8d(%rip),%rax
or     (%rax),%esi
not    %esi
and    %esi,0x4(%rsp)
mov    0x2d66(%rip),%rax
mov    0x2cff(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2cdc(%rip),%rax
or     (%rax),%ecx
mov    0x2d43(%rip),%rax
or     (%rax),%ecx
mov    0x2d0a(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2cf7(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2c9e(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
je     12fc <set_interface_attribs+0x19c>
mov    $0xfffffffe,%ebx
lea    0xd52(%rip),%r14
jmp    12d6 <set_interface_attribs+0x176>
mov    $0xffffffff,%ebx
lea    0xd2a(%rip),%r14
mov    0x2c83(%rip),%rax
mov    (%rax),%ebp
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <fprintf@plt>
jmp    12fe <set_interface_attribs+0x19e>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32, i32 }
@stderr = global i32 0
@.str = [26 x i8] c"Error from tcgetattr: %s\0A\00"
@errno = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [26 x i8] c"Error from tcsetattr: %s\0A\00"
define i32 @set_interface_attribs(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = bitcast %struct.termios* %6 to i8*
%8 = load i32, i32* %3
%9 = call i64 @tcgetattr(i32 %8, %struct.termios* %6)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %5
br label %106
16: ; preds = %2
%17 = load i32, i32* %4
%18 = call i32 @cfsetospeed(%struct.termios* %6, i32 %17)
%19 = load i32, i32* %4
%20 = call i32 @cfsetispeed(%struct.termios* %6, i32 %19)
%21 = load i32, i32* @CLOCAL
%22 = load i32, i32* @CREAD
%23 = or i32 %21, %22
%24 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* @CSIZE
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @CS8
%33 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%34 = load i32, i32* %33
%35 = or i32 %34, %32
store i32 %35, i32* %33
%36 = load i32, i32* @PARENB
%37 = xor i32 %36, -1
%38 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%39 = load i32, i32* %38
%40 = and i32 %39, %37
store i32 %40, i32* %38
%41 = load i32, i32* @CSTOPB
%42 = xor i32 %41, -1
%43 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%44 = load i32, i32* %43
%45 = and i32 %44, %42
store i32 %45, i32* %43
%46 = load i32, i32* @CRTSCTS
%47 = xor i32 %46, -1
%48 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%49 = load i32, i32* %48
%50 = and i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @IGNBRK
%52 = load i32, i32* @BRKINT
%53 = or i32 %51, %52
%54 = load i32, i32* @PARMRK
%55 = or i32 %53, %54
%56 = load i32, i32* @ISTRIP
%57 = or i32 %55, %56
%58 = load i32, i32* @INLCR
%59 = or i32 %57, %58
%60 = load i32, i32* @IGNCR
%61 = or i32 %59, %60
%62 = load i32, i32* @ICRNL
%63 = or i32 %61, %62
%64 = load i32, i32* @IXON
%65 = or i32 %63, %64
%66 = xor i32 %65, -1
%67 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%68 = load i32, i32* %67
%69 = and i32 %68, %66
store i32 %69, i32* %67
%70 = load i32, i32* @ECHO
%71 = load i32, i32* @ECHONL
%72 = or i32 %70, %71
%73 = load i32, i32* @ICANON
%74 = or i32 %72, %73
%75 = load i32, i32* @ISIG
%76 = or i32 %74, %75
%77 = load i32, i32* @IEXTEN
%78 = or i32 %76, %77
%79 = xor i32 %78, -1
%80 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%81 = load i32, i32* %80
%82 = and i32 %81, %79
store i32 %82, i32* %80
%83 = load i32, i32* @OPOST
%84 = xor i32 %83, -1
%85 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
%86 = load i32, i32* %85
%87 = and i32 %86, %84
store i32 %87, i32* %85
%88 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%89 = load i32*, i32** %88
%90 = load i64, i64* @VMIN
%91 = getelementptr inbounds i32, i32* %89, i64 %90
store i32 1, i32* %91
%92 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
%93 = load i32*, i32** %92
%94 = load i64, i64* @VTIME
%95 = getelementptr inbounds i32, i32* %93, i64 %94
store i32 1, i32* %95
%96 = load i32, i32* %3
%97 = load i32, i32* @TCSANOW
%98 = call i64 @tcsetattr(i32 %96, i32 %97, %struct.termios* %6)
%99 = icmp ne i64 %98, 0
br i1 %99, label %100, label %105
100: ; preds = %16
%101 = load i32, i32* @stderr
%102 = load i32, i32* @errno
%103 = call i8* @strerror(i32 %102)
%104 = call i32 @fprintf(i32 %101, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %103)
store i32 -2, i32* %5
br label %105
105: ; preds = %100, %16
br label %106
106: ; preds = %105, %11
%107 = load i32, i32* %5
ret i32 %107
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32, i32 }
@stderr = global i32 0
@.str = [26 x i8] c"Error from tcgetattr: %s\0A\00"
@errno = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CRTSCTS = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@ECHO = global i32 0
@ECHONL = global i32 0
@ICANON = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [26 x i8] c"Error from tcsetattr: %s\0A\00"
define i32 @set_interface_attribs(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i64 @tcgetattr(i32 %0, %struct.termios* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %74, label %7
7: ; preds = %2
%8 = call i32 @cfsetospeed(%struct.termios* %3, i32 %1)
%9 = call i32 @cfsetispeed(%struct.termios* %3, i32 %1)
%10 = load i32, i32* @CLOCAL
%11 = load i32, i32* @CREAD
%12 = or i32 %11, %10
%13 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = or i32 %12, %14
%16 = load i32, i32* @CSIZE
%17 = xor i32 %16, -1
%18 = and i32 %15, %17
%19 = load i32, i32* @CS8
%20 = or i32 %19, %18
%21 = load i32, i32* @PARENB
%22 = load i32, i32* @CSTOPB
%23 = or i32 %21, %22
%24 = load i32, i32* @CRTSCTS
%25 = or i32 %23, %24
%26 = xor i32 %25, -1
%27 = and i32 %20, %26
store i32 %27, i32* %13
%28 = load i32, i32* @IGNBRK
%29 = load i32, i32* @BRKINT
%30 = or i32 %29, %28
%31 = load i32, i32* @PARMRK
%32 = or i32 %30, %31
%33 = load i32, i32* @ISTRIP
%34 = or i32 %32, %33
%35 = load i32, i32* @INLCR
%36 = or i32 %34, %35
%37 = load i32, i32* @IGNCR
%38 = or i32 %36, %37
%39 = load i32, i32* @ICRNL
%40 = or i32 %38, %39
%41 = load i32, i32* @IXON
%42 = or i32 %40, %41
%43 = xor i32 %42, -1
%44 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%45 = load i32, i32* %44
%46 = and i32 %45, %43
store i32 %46, i32* %44
%47 = load i32, i32* @ECHO
%48 = load i32, i32* @ECHONL
%49 = or i32 %48, %47
%50 = load i32, i32* @ICANON
%51 = or i32 %49, %50
%52 = load i32, i32* @ISIG
%53 = or i32 %51, %52
%54 = load i32, i32* @IEXTEN
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @OPOST
%61 = xor i32 %60, -1
%62 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 4
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%66 = load i32*, i32** %65
%67 = load i64, i64* @VMIN
%68 = getelementptr inbounds i32, i32* %66, i64 %67
store i32 1, i32* %68
%69 = load i64, i64* @VTIME
%70 = getelementptr inbounds i32, i32* %66, i64 %69
store i32 1, i32* %70
%71 = load i32, i32* @TCSANOW
%72 = call i64 @tcsetattr(i32 %0, i32 %71, %struct.termios* %3)
%73 = icmp eq i64 %72, 0
br i1 %73, label %81, label %74
74: ; preds = %7, %2
%75 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), %7 ]
%76 = phi i32 [ -1, %2 ], [ -2, %7 ]
%77 = load i32, i32* @stderr
%78 = load i32, i32* @errno
%79 = call i8* @strerror(i32 %78)
%80 = call i32 @fprintf(i32 %77, i8* %75, i8* %79)
br label %81
81: ; preds = %74, %7
%82 = phi i32 [ 0, %7 ], [ %76, %74 ]
ret i32 %82
}