#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 /*<<< orphan*/ errno;
int /*<<< orphan*/ error_message(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
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;
  memset(&tty, 0, sizeof tty);
  if (tcgetattr(fd, &tty) != 0) {
    error_message("error %d from tcgetattr", errno);
    return -1;
  }
  cfsetospeed(&tty, speed);
  cfsetispeed(&tty, speed);
  tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
  tty.c_iflag &= ~IGNBRK;
  tty.c_lflag = 0;
  tty.c_oflag = 0;
  tty.c_cc[VMIN] = 1;
  tty.c_cc[VTIME] = 0;
  tty.c_iflag &= ~(IXON | IXOFF | IXANY);
  tty.c_cflag |= (CLOCAL | CREAD);
  tty.c_cflag &= ~(PARENB | PARODD);
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~CRTSCTS;
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    error_message("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)
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     11b5 <set_interface_attribs+0x55>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
lea    0xe5c(%rip),%rdi
call   1050 <error_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f8 <set_interface_attribs+0x198>
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    0x2dd1(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2dd3(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d97(%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    0x2d99(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2d54(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    0x2da2(%rip),%rcx
or     (%rcx),%eax
mov    0x2d49(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    0x2d56(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    0x2d46(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cd4(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2cca(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d15(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
je     12f1 <set_interface_attribs+0x191>
mov    0x2cb9(%rip),%rax
mov    (%rax),%esi
lea    0xd38(%rip),%rdi
call   1050 <error_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f8 <set_interface_attribs+0x198>
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   %r12
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %edi,%r15d
mov    %rsp,%rbx
xor    %r12d,%r12d
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),%rdi
jmp    1292 <set_interface_attribs+0x132>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1080 <cfsetispeed@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    0x2dea(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x4(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2dba(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d79(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2dc8(%rip),%rax
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d6e(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d27(%rip),%rax
mov    0x2d80(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2d8a(%rip),%rax
mov    0x2d73(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    0x2d08(%rip),%rax
or     (%rax),%edx
mov    0x2d07(%rip),%rax
or     (%rax),%edx
not    %edx
and    %ecx,%edx
mov    %edx,(%rsp)
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
test   %rax,%rax
je     12a6 <set_interface_attribs+0x146>
lea    0xd86(%rip),%rdi
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
call   1050 <error_message@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
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
@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.1 = [24 x i8] c"error %d from tcsetattr\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 = call i32 @memset(%struct.termios* %6, i32 0, i32 32)
%8 = load i32, i32* %4
%9 = call i64 @tcgetattr(i32 %8, %struct.termios* %6)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @errno
%13 = call i32 @error_message(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 -1, i32* %3
br label %82
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 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%20 = load i32, i32* %19
%21 = load i32, i32* @CSIZE
%22 = xor i32 %21, -1
%23 = and i32 %20, %22
%24 = load i32, i32* @CS8
%25 = or i32 %23, %24
%26 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @IGNBRK
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
store i64 0, i64* %32
%33 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
store i64 0, i64* %33
%34 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%35 = load i32*, i32** %34
%36 = load i64, i64* @VMIN
%37 = getelementptr inbounds i32, i32* %35, i64 %36
store i32 1, i32* %37
%38 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
%39 = load i32*, i32** %38
%40 = load i64, i64* @VTIME
%41 = getelementptr inbounds i32, i32* %39, i64 %40
store i32 0, i32* %41
%42 = load i32, i32* @IXON
%43 = load i32, i32* @IXOFF
%44 = or i32 %42, %43
%45 = load i32, i32* @IXANY
%46 = or i32 %44, %45
%47 = xor i32 %46, -1
%48 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%49 = load i32, i32* %48
%50 = and i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @CLOCAL
%52 = load i32, i32* @CREAD
%53 = or i32 %51, %52
%54 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%55 = load i32, i32* %54
%56 = or i32 %55, %53
store i32 %56, i32* %54
%57 = load i32, i32* @PARENB
%58 = load i32, i32* @PARODD
%59 = or i32 %57, %58
%60 = xor i32 %59, -1
%61 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%62 = load i32, i32* %61
%63 = and i32 %62, %60
store i32 %63, i32* %61
%64 = load i32, i32* @CSTOPB
%65 = xor i32 %64, -1
%66 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%67 = load i32, i32* %66
%68 = and i32 %67, %65
store i32 %68, i32* %66
%69 = load i32, i32* @CRTSCTS
%70 = xor i32 %69, -1
%71 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%72 = load i32, i32* %71
%73 = and i32 %72, %70
store i32 %73, i32* %71
%74 = load i32, i32* %4
%75 = load i32, i32* @TCSANOW
%76 = call i64 @tcsetattr(i32 %74, i32 %75, %struct.termios* %6)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %14
%79 = load i32, i32* @errno
%80 = call i32 @error_message(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %79)
store i32 -1, i32* %3
br label %82
81: ; preds = %14
store i32 0, i32* %3
br label %82
82: ; preds = %81, %78, %11
%83 = load i32, i32* %3
ret i32 %83
}

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