#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 /*<<< orphan*/ c_oflag;
  scalar_t__ c_lflag;
  scalar_t__ c_iflag;
};

/* Variables and functions */
int /*<<< orphan*/ B460800;
int CLOCAL;
int CREAD;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ OPOST;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int init() {
  int navdata_fd = 0;
  if (navdata_fd <= 0) {
    navdata_fd = open("/dev/ttyO1", O_RDWR | O_NOCTTY);
    if (navdata_fd < 0) {
      printf("[navdata] Unable to open navdata board connection(/dev/ttyO1)\n");
    }
    fcntl(navdata_fd, F_SETFL, 0);
    struct termios options;
    tcgetattr(navdata_fd, &options);
    cfsetispeed(&options, B460800);
    cfsetospeed(&options, B460800);
    options.c_cflag |= (CLOCAL | CREAD);
    options.c_iflag = 0;
    options.c_lflag = 0;
    options.c_oflag &= ~OPOST;
    tcsetattr(navdata_fd, TCSANOW, &options);
  }
  return navdata_fd;
}


x86 assembly (clang, -O0):
<init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1252 <init+0xe2>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    0x2e27(%rip),%rax
or     (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11c0 <init+0x50>
lea    0xe50(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    0x2dbd(%rip),%rcx
or     (%rcx),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d91(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e68(%rip),%rax
mov    0x2e39(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe6e(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11a9 <init+0x39>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    0x2ddf(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1090 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1050 <cfsetospeed@plt>
mov    0x2db2(%rip),%rax
mov    0x2ddb(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     %ecx,0x8(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i64, i64 }
@.str = [11 x i8] c"/dev/ttyO1\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [63 x i8] c"[navdata] Unable to open navdata board connection(/dev/ttyO1)\0A\00"
@F_SETFL = global i32 0
@B460800 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@OPOST = global i32 0
@TCSANOW = global i32 0
define i32 @init() {
%1 = alloca i32
%2 = alloca %struct.termios
store i32 0, i32* %1
%3 = load i32, i32* %1
%4 = icmp sle i32 %3, 0
br i1 %4, label %5, label %40
5: ; preds = %0
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NOCTTY
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %5
%15 = load i32, i32* %1
%16 = load i32, i32* @F_SETFL
%17 = call i32 @fcntl(i32 %15, i32 %16, i32 0)
%18 = load i32, i32* %1
%19 = call i32 @tcgetattr(i32 %18, %struct.termios* %2)
%20 = load i32, i32* @B460800
%21 = call i32 @cfsetispeed(%struct.termios* %2, i32 %20)
%22 = load i32, i32* @B460800
%23 = call i32 @cfsetospeed(%struct.termios* %2, i32 %22)
%24 = load i32, i32* @CLOCAL
%25 = load i32, i32* @CREAD
%26 = or i32 %24, %25
%27 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%28 = load i32, i32* %27
%29 = or i32 %28, %26
store i32 %29, i32* %27
%30 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 3
store i64 0, i64* %30
%31 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 2
store i64 0, i64* %31
%32 = load i32, i32* @OPOST
%33 = xor i32 %32, -1
%34 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 1
%35 = load i32, i32* %34
%36 = and i32 %35, %33
store i32 %36, i32* %34
%37 = load i32, i32* %1
%38 = load i32, i32* @TCSANOW
%39 = call i32 @tcsetattr(i32 %37, i32 %38, %struct.termios* %2)
br label %40
40: ; preds = %14, %0
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i64, i64 }
@.str = [11 x i8] c"/dev/ttyO1\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@F_SETFL = global i32 0
@B460800 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@OPOST = global i32 0
@TCSANOW = global i32 0
@str = [62 x i8] c"[navdata] Unable to open navdata board connection(/dev/ttyO1)\00"
define i32 @init() {
%1 = alloca %struct.termios
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = load i32, i32* @F_SETFL
%11 = tail call i32 @fcntl(i32 %5, i32 %10, i32 0)
%12 = bitcast %struct.termios* %1 to i8*
%13 = call i32 @tcgetattr(i32 %5, %struct.termios* %1)
%14 = load i32, i32* @B460800
%15 = call i32 @cfsetispeed(%struct.termios* %1, i32 %14)
%16 = load i32, i32* @B460800
%17 = call i32 @cfsetospeed(%struct.termios* %1, i32 %16)
%18 = load i32, i32* @CLOCAL
%19 = load i32, i32* @CREAD
%20 = or i32 %19, %18
%21 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%22 = load i32, i32* %21
%23 = or i32 %20, %22
store i32 %23, i32* %21
%24 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 2
%25 = bitcast i64* %24 to i8*
%26 = load i32, i32* @OPOST
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @TCSANOW
%32 = call i32 @tcsetattr(i32 %5, i32 %31, %struct.termios* %1)
ret i32 %5
}