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

/* Variables and functions */
int /*<<< orphan*/ B4800;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ GetGpsInfoFromSerial(int);
int O_NDELAY;
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*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main() {
  int fd;
  struct termios options;
  fd = open("/dev/tty.usbserial-A602HTRY", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    perror("open_port: Unable to open:");
  } else {
    fcntl(fd, F_SETFL, 0);
    printf("Connected...\n");
  }
  tcgetattr(fd, &options);
  cfsetispeed(&options, B4800);
  cfsetospeed(&options, B4800);
  tcsetattr(fd, TCSANOW, &options);
  for (;;) {
    GetGpsInfoFromSerial(fd);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e19(%rip),%rax
or     (%rax),%esi
mov    0x2e00(%rip),%rax
or     (%rax),%esi
lea    0xe3f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e4 <main+0x54>
lea    0xe42(%rip),%rdi
call   10a0 <perror@plt>
jmp    1203 <main+0x73>
mov    -0x8(%rbp),%edi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
lea    0xe39(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    -0x8(%rbp),%edi
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x8(%rbp),%edi
call   10b0 <GetGpsInfoFromSerial@plt>
jmp    1248 <main+0xb8>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e48(%rip),%rax
mov    0x2e21(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e06(%rip),%rax
or     (%rax),%esi
lea    0xe45(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1239 <main+0xa9>
mov    0x2df2(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <tcgetattr@plt>
mov    0x2ddd(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1090 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1050 <cfsetospeed@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1070 <tcsetattr@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
call   10b0 <GetGpsInfoFromSerial@plt>
jmp    1230 <main+0xa0>
lea    0xddc(%rip),%rdi
call   10a0 <perror@plt>
jmp    11e5 <main+0x55>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [28 x i8] c"/dev/tty.usbserial-A602HTRY\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [27 x i8] c"open_port: Unable to open:\00"
@F_SETFL = global i32 0
@.str.2 = [14 x i8] c"Connected...\0A\00"
@B4800 = global i32 0
@TCSANOW = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.termios
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_NOCTTY
%6 = or i32 %4, %5
%7 = load i32, i32* @O_NDELAY
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %19
14: ; preds = %0
%15 = load i32, i32* %2
%16 = load i32, i32* @F_SETFL
%17 = call i32 @fcntl(i32 %15, i32 %16, i32 0)
%18 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %14, %12
%20 = load i32, i32* %2
%21 = call i32 @tcgetattr(i32 %20, %struct.termios* %3)
%22 = load i32, i32* @B4800
%23 = call i32 @cfsetispeed(%struct.termios* %3, i32 %22)
%24 = load i32, i32* @B4800
%25 = call i32 @cfsetospeed(%struct.termios* %3, i32 %24)
%26 = load i32, i32* %2
%27 = load i32, i32* @TCSANOW
%28 = call i32 @tcsetattr(i32 %26, i32 %27, %struct.termios* %3)
br label %29
29: ; preds = %29, %19
%30 = load i32, i32* %2
%31 = call i32 @GetGpsInfoFromSerial(i32 %30)
br label %29
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [28 x i8] c"/dev/tty.usbserial-A602HTRY\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [27 x i8] c"open_port: Unable to open:\00"
@F_SETFL = global i32 0
@B4800 = global i32 0
@TCSANOW = global i32 0
@str = [13 x i8] c"Connected...\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = bitcast %struct.termios* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %4, %3
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %5, %6
%8 = tail call i32 @open(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %16
12: ; preds = %0
%13 = load i32, i32* @F_SETFL
%14 = tail call i32 @fcntl(i32 %8, i32 %13, i32 0)
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %12, %10
%17 = call i32 @tcgetattr(i32 %8, %struct.termios* %1)
%18 = load i32, i32* @B4800
%19 = call i32 @cfsetispeed(%struct.termios* %1, i32 %18)
%20 = load i32, i32* @B4800
%21 = call i32 @cfsetospeed(%struct.termios* %1, i32 %20)
%22 = load i32, i32* @TCSANOW
%23 = call i32 @tcsetattr(i32 %8, i32 %22, %struct.termios* %1)
br label %24
24: ; preds = %24, %16
%25 = call i32 @GetGpsInfoFromSerial(i32 %8)
br label %24
}