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

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ISIG;
int IXANY;
int IXOFF;
int IXON;
int PARENB;
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*/ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int initSerialPort(int fd) {
  struct termios options;
  tcgetattr(fd, &options);
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_iflag &= ~(IXON | IXOFF | IXANY);
  options.c_cflag |= CRTSCTS;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_cc[VMIN] = 1;
  options.c_cc[VTIME] = 0;
  if (tcsetattr(fd, TCSANOW, &options) < 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<initSerialPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    0x2e1d(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    0x2e00(%rip),%rcx
or     (%rcx),%eax
mov    0x2d8f(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    0x2dad(%rip),%rcx
or     (%rcx),%eax
mov    0x2d9c(%rip),%rcx
or     (%rcx),%eax
mov    0x2d8b(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d55(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x2d20(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
jge    128d <initSerialPort+0x14d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1294 <initSerialPort+0x154>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initSerialPort>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e52(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1060 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2dd7(%rip),%rax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    0x2dc0(%rip),%rdx
or     (%rdx),%eax
mov    0x2def(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2df2(%rip),%rcx
or     (%rcx),%eax
mov    0x2e29(%rip),%rcx
mov    0x2e2a(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2db7(%rip),%rcx
or     (%rcx),%edx
not    %edx
and    %edx,0xc(%rsp)
mov    0x2d88(%rip),%rcx
or     (%rcx),%eax
mov    0x2d8f(%rip),%rcx
mov    0x2de0(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    %eax,0x8(%rsp)
mov    0x2dc9(%rip),%rax
or     (%rax),%edx
mov    0x2db8(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x10(%rsp)
mov    0x18(%rsp),%rax
mov    0x2d84(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d53(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
sar    $0x3f,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32* }
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@CRTSCTS = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define i32 @initSerialPort(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %4)
%7 = load i32, i32* @B9600
%8 = call i32 @cfsetispeed(%struct.termios* %4, i32 %7)
%9 = load i32, i32* @B9600
%10 = call i32 @cfsetospeed(%struct.termios* %4, i32 %9)
%11 = load i32, i32* @CLOCAL
%12 = load i32, i32* @CREAD
%13 = or i32 %11, %12
%14 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%15 = load i32, i32* %14
%16 = or i32 %15, %13
store i32 %16, i32* %14
%17 = load i32, i32* @PARENB
%18 = xor i32 %17, -1
%19 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%20 = load i32, i32* %19
%21 = and i32 %20, %18
store i32 %21, i32* %19
%22 = load i32, i32* @CSTOPB
%23 = xor i32 %22, -1
%24 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%25 = load i32, i32* %24
%26 = and i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* @CSIZE
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @CS8
%33 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%34 = load i32, i32* %33
%35 = or i32 %34, %32
store i32 %35, i32* %33
%36 = load i32, i32* @IXON
%37 = load i32, i32* @IXOFF
%38 = or i32 %36, %37
%39 = load i32, i32* @IXANY
%40 = or i32 %38, %39
%41 = xor i32 %40, -1
%42 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%43 = load i32, i32* %42
%44 = and i32 %43, %41
store i32 %44, i32* %42
%45 = load i32, i32* @CRTSCTS
%46 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%47 = load i32, i32* %46
%48 = or i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @ICANON
%50 = load i32, i32* @ECHO
%51 = or i32 %49, %50
%52 = load i32, i32* @ECHOE
%53 = or i32 %51, %52
%54 = load i32, i32* @ISIG
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
%61 = load i32*, i32** %60
%62 = load i64, i64* @VMIN
%63 = getelementptr inbounds i32, i32* %61, i64 %62
store i32 1, i32* %63
%64 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
%65 = load i32*, i32** %64
%66 = load i64, i64* @VTIME
%67 = getelementptr inbounds i32, i32* %65, i64 %66
store i32 0, i32* %67
%68 = load i32, i32* %3
%69 = load i32, i32* @TCSANOW
%70 = call i64 @tcsetattr(i32 %68, i32 %69, %struct.termios* %4)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %1
store i32 -1, i32* %2
br label %74
73: ; preds = %1
store i32 0, i32* %2
br label %74
74: ; preds = %73, %72
%75 = load i32, i32* %2
ret i32 %75
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32* }
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@IXANY = global i32 0
@CRTSCTS = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
define i32 @initSerialPort(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = load i32, i32* @B9600
%6 = call i32 @cfsetispeed(%struct.termios* %2, i32 %5)
%7 = load i32, i32* @B9600
%8 = call i32 @cfsetospeed(%struct.termios* %2, i32 %7)
%9 = load i32, i32* @CLOCAL
%10 = load i32, i32* @CREAD
%11 = or i32 %10, %9
%12 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = or i32 %11, %13
%15 = load i32, i32* @PARENB
%16 = load i32, i32* @CSTOPB
%17 = or i32 %15, %16
%18 = load i32, i32* @CSIZE
%19 = or i32 %17, %18
%20 = xor i32 %19, -1
%21 = and i32 %14, %20
%22 = load i32, i32* @CS8
%23 = or i32 %22, %21
%24 = load i32, i32* @IXON
%25 = load i32, i32* @IXOFF
%26 = or i32 %25, %24
%27 = load i32, i32* @IXANY
%28 = or i32 %26, %27
%29 = xor i32 %28, -1
%30 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%31 = load i32, i32* %30
%32 = and i32 %31, %29
store i32 %32, i32* %30
%33 = load i32, i32* @CRTSCTS
%34 = or i32 %33, %23
store i32 %34, i32* %12
%35 = load i32, i32* @ICANON
%36 = load i32, i32* @ECHO
%37 = or i32 %36, %35
%38 = load i32, i32* @ECHOE
%39 = or i32 %37, %38
%40 = load i32, i32* @ISIG
%41 = or i32 %39, %40
%42 = xor i32 %41, -1
%43 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%44 = load i32, i32* %43
%45 = and i32 %44, %42
store i32 %45, i32* %43
%46 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%47 = load i32*, i32** %46
%48 = load i64, i64* @VMIN
%49 = getelementptr inbounds i32, i32* %47, i64 %48
store i32 1, i32* %49
%50 = load i64, i64* @VTIME
%51 = getelementptr inbounds i32, i32* %47, i64 %50
store i32 0, i32* %51
%52 = load i32, i32* @TCSANOW
%53 = call i64 @tcsetattr(i32 %0, i32 %52, %struct.termios* %2)
%54 = ashr i64 %53, 63
%55 = trunc i64 %54 to i32
ret i32 %55
}