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

/* Variables and functions */
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int INPCK;
int ISTRIP;
int IXANY;
int IXOFF;
int IXON;
int PARENB;
int PARODD;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int);
int /*<<< orphan*/ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serial_set_attribs(int fd) {
  struct termios tty;
  memset(&tty, 0, sizeof tty);
  tcgetattr(fd, &tty);
  cfsetispeed(&tty, 0010015);
  cfsetospeed(&tty, 0010015);
  tty.c_cflag &= ~CSIZE;
  tty.c_cflag |= CS8;
  tty.c_cflag |= (CLOCAL | CREAD);
  tty.c_cflag &= ~CSTOPB;
  tty.c_cflag &= ~(PARENB | PARODD);
  tty.c_iflag &= ~(INPCK | ISTRIP);
  tty.c_iflag &= ~(IXON | IXOFF);
  tty.c_iflag |= IXANY;
  if (tcsetattr(fd, TCSANOW, &tty) != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<serial_set_attribs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1050 <tcgetattr@plt>
lea    -0x10(%rbp),%rdi
mov    $0x100d,%esi
call   1070 <cfsetispeed@plt>
lea    -0x10(%rbp),%rdi
mov    $0x100d,%esi
call   1030 <cfsetospeed@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    0x2dfc(%rip),%rcx
or     (%rcx),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    0x2dda(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    0x2d87(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
mov    0x2dc4(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     1269 <serial_set_attribs+0x119>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <serial_set_attribs+0x120>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_set_attribs>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    %r14,%rdi
mov    $0x100d,%esi
call   1070 <cfsetispeed@plt>
mov    %r14,%rdi
mov    $0x100d,%esi
call   1030 <cfsetospeed@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
not    %eax
and    (%rsp),%eax
mov    0x2e17(%rip),%rcx
or     (%rcx),%eax
mov    0x2dce(%rip),%rcx
or     (%rcx),%eax
mov    0x2e0d(%rip),%rcx
or     (%rcx),%eax
mov    0x2e1c(%rip),%rcx
mov    0x2e05(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2db2(%rip),%rcx
or     (%rcx),%edx
not    %edx
and    %eax,%edx
mov    %edx,(%rsp)
mov    0x2dba(%rip),%rax
mov    0x2dab(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2df0(%rip),%rax
mov    0x2df1(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
or     %ecx,%edx
not    %edx
and    0x4(%rsp),%edx
mov    0x2d96(%rip),%rax
or     (%rax),%edx
mov    %edx,0x4(%rsp)
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
neg    %rax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32 }
@CSIZE = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSTOPB = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@TCSANOW = global i32 0
define i32 @serial_set_attribs(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %3
%5 = call i32 @memset(%struct.termios* %4, i32 0, i32 8)
%6 = load i32, i32* %3
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %4)
%8 = call i32 @cfsetispeed(%struct.termios* %4, i32 4109)
%9 = call i32 @cfsetospeed(%struct.termios* %4, i32 4109)
%10 = load i32, i32* @CSIZE
%11 = xor i32 %10, -1
%12 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = and i32 %13, %11
store i32 %14, i32* %12
%15 = load i32, i32* @CS8
%16 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%17 = load i32, i32* %16
%18 = or i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* @CLOCAL
%20 = load i32, i32* @CREAD
%21 = or i32 %19, %20
%22 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%23 = load i32, i32* %22
%24 = or i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* @CSTOPB
%26 = xor i32 %25, -1
%27 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%28 = load i32, i32* %27
%29 = and i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* @PARENB
%31 = load i32, i32* @PARODD
%32 = or i32 %30, %31
%33 = xor i32 %32, -1
%34 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%35 = load i32, i32* %34
%36 = and i32 %35, %33
store i32 %36, i32* %34
%37 = load i32, i32* @INPCK
%38 = load i32, i32* @ISTRIP
%39 = or i32 %37, %38
%40 = xor i32 %39, -1
%41 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%42 = load i32, i32* %41
%43 = and i32 %42, %40
store i32 %43, i32* %41
%44 = load i32, i32* @IXON
%45 = load i32, i32* @IXOFF
%46 = or i32 %44, %45
%47 = xor i32 %46, -1
%48 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%49 = load i32, i32* %48
%50 = and i32 %49, %47
store i32 %50, i32* %48
%51 = load i32, i32* @IXANY
%52 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%53 = load i32, i32* %52
%54 = or i32 %53, %51
store i32 %54, i32* %52
%55 = load i32, i32* %3
%56 = load i32, i32* @TCSANOW
%57 = call i64 @tcsetattr(i32 %55, i32 %56, %struct.termios* %4)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %1
store i32 -1, i32* %2
br label %61
60: ; preds = %1
store i32 0, i32* %2
br label %61
61: ; preds = %60, %59
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
%struct.termios = type { i32, i32 }
@CSIZE = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@CSTOPB = global i32 0
@PARENB = global i32 0
@PARODD = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@TCSANOW = global i32 0
define i32 @serial_set_attribs(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @memset(%struct.termios* %2, i32 0, i32 8)
%5 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%6 = call i32 @cfsetispeed(%struct.termios* %2, i32 4109)
%7 = call i32 @cfsetospeed(%struct.termios* %2, i32 4109)
%8 = load i32, i32* @CSIZE
%9 = xor i32 %8, -1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = and i32 %11, %9
%13 = load i32, i32* @CS8
%14 = or i32 %13, %12
%15 = load i32, i32* @CLOCAL
%16 = load i32, i32* @CREAD
%17 = or i32 %15, %14
%18 = or i32 %17, %16
%19 = load i32, i32* @CSTOPB
%20 = load i32, i32* @PARENB
%21 = load i32, i32* @PARODD
%22 = or i32 %21, %20
%23 = or i32 %19, %22
%24 = xor i32 %23, -1
%25 = and i32 %18, %24
store i32 %25, i32* %10
%26 = load i32, i32* @INPCK
%27 = load i32, i32* @ISTRIP
%28 = or i32 %27, %26
%29 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%30 = load i32, i32* %29
%31 = load i32, i32* @IXON
%32 = load i32, i32* @IXOFF
%33 = or i32 %32, %31
%34 = or i32 %28, %33
%35 = xor i32 %34, -1
%36 = and i32 %30, %35
%37 = load i32, i32* @IXANY
%38 = or i32 %36, %37
store i32 %38, i32* %29
%39 = load i32, i32* @TCSANOW
%40 = call i64 @tcsetattr(i32 %0, i32 %39, %struct.termios* %2)
%41 = icmp ne i64 %40, 0
%42 = sext i1 %41 to i32
ret i32 %42
}