#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;
};

/* Variables and functions */
int BRKINT;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ICANON;
int ICRNL;
int IGNBRK;
int IGNCR;
int INLCR;
int ISIG;
int ISTRIP;
int IXANY;
int IXOFF;
int IXON;
int /*<<< orphan*/ OPOST;
int PARENB;
int PARMRK;
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*/ exit(int);
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, int parity) {
  struct termios tty;
  memset(&tty, 0, sizeof tty);
  if (tcgetattr(fd, &tty) != 0) {
    exit(-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] = 0;
  tty.c_cc[VTIME] = 5;
  tty.c_iflag &= ~(IXON | IXOFF | IXANY);
  tty.c_cflag |= (CLOCAL | CREAD);
  tty.c_cflag &= ~(PARENB | PARODD);
  tty.c_cflag |= parity;
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~CRTSCTS;
  tty.c_lflag &= ~(ICANON | ECHO | ISIG);
  tty.c_iflag &=
      ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
  tty.c_oflag &= ~OPOST;
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    exit(-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_interface_attribs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-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   1050 <tcgetattr@plt>
cmp    $0x0,%rax
je     11a1 <set_interface_attribs+0x41>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0x8(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1070 <cfsetispeed@plt>
mov    -0x30(%rbp),%eax
mov    0x2da5(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2da7(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2d6f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2d2a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    0x2da0(%rip),%rcx
or     (%rcx),%eax
mov    0x2d1f(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2ccd(%rip),%rax
mov    (%rax),%eax
mov    0x2d2c(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
mov    0x2d2c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c99(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c8f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c8d(%rip),%rax
mov    (%rax),%eax
mov    0x2cec(%rip),%rcx
or     (%rcx),%eax
mov    0x2cd3(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c79(%rip),%rax
mov    (%rax),%eax
mov    0x2cb0(%rip),%rcx
or     (%rcx),%eax
mov    0x2d0f(%rip),%rcx
or     (%rcx),%eax
mov    0x2c66(%rip),%rcx
or     (%rcx),%eax
mov    0x2ce5(%rip),%rcx
or     (%rcx),%eax
mov    0x2ccc(%rip),%rcx
or     (%rcx),%eax
mov    0x2cdb(%rip),%rcx
or     (%rcx),%eax
mov    0x2caa(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2ca0(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2c73(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     1354 <set_interface_attribs+0x1f4>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
xor    %eax,%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    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r12d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
call   1050 <tcgetattr@plt>
test   %rax,%rax
jne    1311 <set_interface_attribs+0x1b1>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <cfsetispeed@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    0x2db2(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2d76(%rip),%r8
mov    (%r8),%eax
not    %eax
and    %eax,0x4(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2d79(%rip),%rdx
mov    (%rdx),%rdx
movl   $0x0,(%rax,%rdx,4)
mov    0x2d38(%rip),%rdx
mov    (%rdx),%rdx
movl   $0x5,(%rax,%rdx,4)
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    0x2dae(%rip),%rdx
mov    (%rdx),%edx
or     %eax,%edx
mov    0x2d2b(%rip),%rsi
or     (%rsi),%edx
mov    0x2ce2(%rip),%rsi
mov    0x2d43(%rip),%rdi
mov    (%rdi),%edi
or     (%rsi),%edi
or     (%rsp),%edi
mov    0x2d65(%rip),%rsi
mov    0x2d46(%rip),%rbp
mov    0x0(%rbp),%ebp
or     (%rsi),%ebp
not    %ebp
and    %edi,%ebp
or     %r15d,%ebp
mov    0x2cbb(%rip),%rsi
mov    (%rsi),%esi
mov    0x2cba(%rip),%rdi
or     (%rdi),%esi
not    %esi
and    %ebp,%esi
mov    %esi,(%rsp)
mov    0x2cba(%rip),%rsi
mov    0x2d1b(%rip),%rdi
mov    (%rdi),%edi
or     (%rsi),%edi
mov    0x2d00(%rip),%rsi
or     (%rsi),%edi
not    %edi
and    %edi,0x8(%rsp)
mov    0x2ce9(%rip),%rsi
mov    0x2d4a(%rip),%rdi
mov    0x2ca3(%rip),%rbp
mov    0x2d24(%rip),%rbx
mov    0x2d0d(%rip),%rcx
or     (%r8),%eax
or     (%rsi),%eax
or     (%rdi),%eax
or     0x0(%rbp),%eax
or     (%rbx),%eax
or     (%rcx),%eax
mov    0x2d10(%rip),%rcx
or     (%rcx),%eax
or     %edx,%eax
not    %eax
and    %eax,0x4(%rsp)
mov    0x2cdf(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
jne    1311 <set_interface_attribs+0x1b1>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@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
@ICANON = global i32 0
@ECHO = global i32 0
@ISIG = 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
@OPOST = global i32 0
@TCSANOW = global i32 0
define i32 @set_interface_attribs(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = call i32 @memset(%struct.termios* %7, i32 0, i32 32)
%9 = load i32, i32* %4
%10 = call i64 @tcgetattr(i32 %9, %struct.termios* %7)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %3
%15 = load i32, i32* %5
%16 = call i32 @cfsetospeed(%struct.termios* %7, i32 %15)
%17 = load i32, i32* %5
%18 = call i32 @cfsetispeed(%struct.termios* %7, i32 %17)
%19 = getelementptr inbounds %struct.termios, %struct.termios* %7, 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* %7, 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* %7, 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* %7, i32 0, i32 2
store i32 0, i32* %32
%33 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 4
store i32 0, i32* %33
%34 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%35 = load i32*, i32** %34
%36 = load i64, i64* @VMIN
%37 = getelementptr inbounds i32, i32* %35, i64 %36
store i32 0, i32* %37
%38 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 3
%39 = load i32*, i32** %38
%40 = load i64, i64* @VTIME
%41 = getelementptr inbounds i32, i32* %39, i64 %40
store i32 5, 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* %7, 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* %7, 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* %7, i32 0, i32 0
%62 = load i32, i32* %61
%63 = and i32 %62, %60
store i32 %63, i32* %61
%64 = load i32, i32* %6
%65 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%66 = load i32, i32* %65
%67 = or i32 %66, %64
store i32 %67, i32* %65
%68 = load i32, i32* @CSTOPB
%69 = xor i32 %68, -1
%70 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%71 = load i32, i32* %70
%72 = and i32 %71, %69
store i32 %72, i32* %70
%73 = load i32, i32* @CRTSCTS
%74 = xor i32 %73, -1
%75 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%76 = load i32, i32* %75
%77 = and i32 %76, %74
store i32 %77, i32* %75
%78 = load i32, i32* @ICANON
%79 = load i32, i32* @ECHO
%80 = or i32 %78, %79
%81 = load i32, i32* @ISIG
%82 = or i32 %80, %81
%83 = xor i32 %82, -1
%84 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 2
%85 = load i32, i32* %84
%86 = and i32 %85, %83
store i32 %86, i32* %84
%87 = load i32, i32* @IGNBRK
%88 = load i32, i32* @BRKINT
%89 = or i32 %87, %88
%90 = load i32, i32* @PARMRK
%91 = or i32 %89, %90
%92 = load i32, i32* @ISTRIP
%93 = or i32 %91, %92
%94 = load i32, i32* @INLCR
%95 = or i32 %93, %94
%96 = load i32, i32* @IGNCR
%97 = or i32 %95, %96
%98 = load i32, i32* @ICRNL
%99 = or i32 %97, %98
%100 = load i32, i32* @IXON
%101 = or i32 %99, %100
%102 = xor i32 %101, -1
%103 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%104 = load i32, i32* %103
%105 = and i32 %104, %102
store i32 %105, i32* %103
%106 = load i32, i32* @OPOST
%107 = xor i32 %106, -1
%108 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 4
%109 = load i32, i32* %108
%110 = and i32 %109, %107
store i32 %110, i32* %108
%111 = load i32, i32* %4
%112 = load i32, i32* @TCSANOW
%113 = call i64 @tcsetattr(i32 %111, i32 %112, %struct.termios* %7)
%114 = icmp ne i64 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %14
%116 = call i32 @exit(i32 -1)
unreachable
117: ; preds = %14
ret i32 0
}

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