#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;
};
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*/ printf(char *, char *);
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) {
  struct termios tty;
  if (tcgetattr(fd, &tty) < 0) {
    printf("Error from tcgetattr: %s\n", strerror(errno));
    return -1;
  }
  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) {
    printf("Error from tcsetattr: %s\n", strerror(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    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
jge    11ad <set_interface_attribs+0x4d>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1346 <set_interface_attribs+0x1e6>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0xc(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    0x2dbb(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d0d(%rip),%rax
mov    (%rax),%eax
mov    0x2d54(%rip),%rcx
or     (%rcx),%eax
mov    0x2da3(%rip),%rcx
or     (%rcx),%eax
mov    0x2d02(%rip),%rcx
or     (%rcx),%eax
mov    0x2d79(%rip),%rcx
or     (%rcx),%eax
mov    0x2d68(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6f(%rip),%rcx
or     (%rcx),%eax
mov    0x2d46(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    0x2cbb(%rip),%rcx
or     (%rcx),%eax
mov    0x2c9a(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf9(%rip),%rcx
or     (%rcx),%eax
mov    0x2cc0(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2ca8(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2c53(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2caf(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     133f <set_interface_attribs+0x1df>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xcec(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1346 <set_interface_attribs+0x1e6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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
mov    %rsp,%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
js     12b9 <set_interface_attribs+0x159>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    0x2d7d(%rip),%rax
mov    0x2dee(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2dc8(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    0x2dcb(%rip),%rcx
or     (%rcx),%eax
mov    0x2df2(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d51(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d50(%rip),%rdx
or     (%rdx),%ecx
mov    0x2d67(%rip),%rdx
mov    0x2db0(%rip),%rsi
mov    (%rsi),%esi
or     (%rdx),%esi
mov    0x2dfd(%rip),%rdx
or     (%rdx),%esi
mov    0x2d5c(%rip),%rdx
or     (%rdx),%esi
mov    0x2dd3(%rip),%rdx
or     (%rdx),%esi
not    %ecx
and    %eax,%ecx
mov    0x2dbe(%rip),%rax
or     (%rax),%esi
mov    %ecx,(%rsp)
mov    0x2dc2(%rip),%rax
or     (%rax),%esi
mov    0x2d99(%rip),%rax
or     (%rax),%esi
not    %esi
and    %esi,0x4(%rsp)
mov    0x2d72(%rip),%rax
mov    0x2d13(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2cf0(%rip),%rax
or     (%rax),%ecx
mov    0x2d4f(%rip),%rax
or     (%rax),%ecx
mov    0x2d16(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2d03(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2cb2(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
je     12e0 <set_interface_attribs+0x180>
lea    0xd63(%rip),%rbx
jmp    12c0 <set_interface_attribs+0x160>
lea    0xd40(%rip),%rbx
mov    0x2c99(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    12e2 <set_interface_attribs+0x182>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@.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 %79, 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 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = call i32 @printf(i8* %75, i8* %77)
br label %79
79: ; preds = %74, %7
%80 = phi i32 [ 0, %7 ], [ -1, %74 ]
ret i32 %80
}