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

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
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, int hwflowctrl) {
  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);
  if (hwflowctrl)
    options.c_cflag |= CRTSCTS;
  else
    options.c_cflag &= ~CRTSCTS;
  options.c_cc[VMIN] = 1;
  options.c_cc[VTIME] = 1;
  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    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    0x2e32(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    0x2dfd(%rip),%rcx
or     (%rcx),%eax
mov    0x2da4(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     121d <initSerialPort+0xdd>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    122f <initSerialPort+0xef>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2d76(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2d41(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
jge    1284 <initSerialPort+0x144>
movl   $0xffffffff,-0x4(%rbp)
jmp    128b <initSerialPort+0x14b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initSerialPort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r15d
mov    %edi,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
mov    0x2e65(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   1060 <cfsetispeed@plt>
mov    0x0(%rbp),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2df0(%rip),%rax
mov    0x2e39(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    0x2dd9(%rip),%rdx
or     (%rdx),%eax
mov    0x2e00(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2e2b(%rip),%rcx
mov    0x2e2c(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2dd1(%rip),%rcx
or     (%rcx),%edx
mov    0x2de8(%rip),%rcx
not    %edx
and    %edx,0xc(%rsp)
or     (%rcx),%eax
mov    0x2da1(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%edx
not    %edx
and    %eax,%edx
or     %ecx,%eax
test   %r15d,%r15d
cmove  %edx,%eax
mov    %eax,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0x2db1(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2d80(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
sar    $0x3f,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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