#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_lflag;
  scalar_t__ c_oflag;
};

/* Variables and functions */
int BRKINT;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ICRNL;
int IGNBRK;
int INLCR;
int INPCK;
int ISTRIP;
int IXANY;
int IXOFF;
int IXON;
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*/ memset(struct termios *, int /*<<< orphan*/, int);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int uart_set_interface_attribs(int fd, int speed, int parity) {
  struct termios tty;
  memset(&tty, 0, sizeof tty);
  if (tcgetattr(fd, &tty) != 0) {
    return -1;
  }
  cfsetospeed(&tty, speed);
  cfsetispeed(&tty, speed);
  tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
  tty.c_iflag &=
      ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON);
  tty.c_oflag = 0;
  tty.c_lflag = 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;
  if (tcsetattr(fd, TCSANOW, &tty) != 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<uart_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   1040 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0x0,%rax
je     1193 <uart_set_interface_attribs+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <uart_set_interface_attribs+0x1b9>
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    -0x30(%rbp),%eax
mov    0x2dd3(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2dd5(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    0x2dd0(%rip),%rcx
or     (%rcx),%eax
mov    0x2dff(%rip),%rcx
or     (%rcx),%eax
mov    0x2dee(%rip),%rcx
or     (%rcx),%eax
mov    0x2dfd(%rip),%rcx
or     (%rcx),%eax
mov    0x2d74(%rip),%rcx
or     (%rcx),%eax
mov    0x2d63(%rip),%rcx
or     (%rcx),%eax
mov    0x2dba(%rip),%rcx
or     (%rcx),%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    0x2d5c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2d0f(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    0x2d6d(%rip),%rcx
or     (%rcx),%eax
mov    0x2d0c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2cba(%rip),%rax
mov    (%rax),%eax
mov    0x2d19(%rip),%rcx
or     (%rcx),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    0x2d11(%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    0x2c86(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2c7c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2cd7(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     1302 <uart_set_interface_attribs+0x1b2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <uart_set_interface_attribs+0x1b9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_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>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    12ba <uart_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    0x2dd8(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    0x2dda(%rip),%rcx
or     (%rcx),%eax
mov    0x2d99(%rip),%rcx
mov    0x2dda(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e07(%rip),%rcx
or     (%rcx),%edx
mov    0x2df6(%rip),%rcx
or     (%rcx),%edx
mov    0x2e05(%rip),%rcx
or     (%rcx),%edx
mov    0x2d7c(%rip),%rcx
or     (%rcx),%edx
mov    %eax,(%rsp)
mov    0x2d68(%rip),%rax
or     (%rax),%edx
mov    0x2dbf(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x4(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x8(%rsp),%rcx
mov    0x2d6b(%rip),%rdx
mov    (%rdx),%rdx
movl   $0x0,(%rcx,%rdx,4)
mov    0x2d22(%rip),%rdx
mov    (%rdx),%rdx
movl   $0x5,(%rcx,%rdx,4)
mov    0x2d89(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d26(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2cd7(%rip),%rax
mov    0x2d38(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2d4a(%rip),%rax
mov    0x2d33(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
not    %edx
and    %ecx,%edx
or     %r15d,%edx
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
mov    0x2cb0(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %edx,%eax
mov    %eax,(%rsp)
mov    0x2d10(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
neg    %rax
sbb    %eax,%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 }
@CSIZE = global i32 0
@CS8 = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@ICRNL = global i32 0
@INLCR = global i32 0
@PARMRK = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@VMIN = global i64 0
@VTIME = global i64 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
define i32 @uart_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 %14
13: ; preds = %3
store i32 -1, i32* %4
br label %98
14: ; preds = %3
%15 = load i32, i32* %6
%16 = call i32 @cfsetospeed(%struct.termios* %8, i32 %15)
%17 = load i32, i32* %6
%18 = call i32 @cfsetispeed(%struct.termios* %8, i32 %17)
%19 = getelementptr inbounds %struct.termios, %struct.termios* %8, 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* %8, i32 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @IGNBRK
%28 = load i32, i32* @BRKINT
%29 = or i32 %27, %28
%30 = load i32, i32* @ICRNL
%31 = or i32 %29, %30
%32 = load i32, i32* @INLCR
%33 = or i32 %31, %32
%34 = load i32, i32* @PARMRK
%35 = or i32 %33, %34
%36 = load i32, i32* @INPCK
%37 = or i32 %35, %36
%38 = load i32, i32* @ISTRIP
%39 = or i32 %37, %38
%40 = load i32, i32* @IXON
%41 = or i32 %39, %40
%42 = xor i32 %41, -1
%43 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%44 = load i32, i32* %43
%45 = and i32 %44, %42
store i32 %45, i32* %43
%46 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 4
store i64 0, i64* %46
%47 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
store i64 0, i64* %47
%48 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%49 = load i32*, i32** %48
%50 = load i64, i64* @VMIN
%51 = getelementptr inbounds i32, i32* %49, i64 %50
store i32 0, i32* %51
%52 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%53 = load i32*, i32** %52
%54 = load i64, i64* @VTIME
%55 = getelementptr inbounds i32, i32* %53, i64 %54
store i32 5, i32* %55
%56 = load i32, i32* @IXON
%57 = load i32, i32* @IXOFF
%58 = or i32 %56, %57
%59 = load i32, i32* @IXANY
%60 = or i32 %58, %59
%61 = xor i32 %60, -1
%62 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = load i32, i32* @CLOCAL
%66 = load i32, i32* @CREAD
%67 = or i32 %65, %66
%68 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%69 = load i32, i32* %68
%70 = or i32 %69, %67
store i32 %70, i32* %68
%71 = load i32, i32* @PARENB
%72 = load i32, i32* @PARODD
%73 = or i32 %71, %72
%74 = xor i32 %73, -1
%75 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%76 = load i32, i32* %75
%77 = and i32 %76, %74
store i32 %77, i32* %75
%78 = load i32, i32* %7
%79 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%80 = load i32, i32* %79
%81 = or i32 %80, %78
store i32 %81, i32* %79
%82 = load i32, i32* @CSTOPB
%83 = xor i32 %82, -1
%84 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%85 = load i32, i32* %84
%86 = and i32 %85, %83
store i32 %86, i32* %84
%87 = load i32, i32* @CRTSCTS
%88 = xor i32 %87, -1
%89 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%90 = load i32, i32* %89
%91 = and i32 %90, %88
store i32 %91, i32* %89
%92 = load i32, i32* %5
%93 = load i32, i32* @TCSANOW
%94 = call i64 @tcsetattr(i32 %92, i32 %93, %struct.termios* %8)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %14
store i32 -1, i32* %4
br label %98
97: ; preds = %14
store i32 0, i32* %4
br label %98
98: ; preds = %97, %96, %13
%99 = load i32, i32* %4
ret i32 %99
}

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