#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 */

/* Variables and functions */
int /*<<< orphan*/ F_SETFL;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int open_port(void) {
  int fd;
  fd = open("/dev/ttyO2", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    printf("open_port: Unable to open /dev/ttyO2. \n");
  } else {
    fcntl(fd, F_SETFL, 0);
    printf("port is open.\n");
  }
  return (fd);
}


x86 assembly (clang, -O0):
<open_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
mov    0x2e77(%rip),%rax
or     (%rax),%esi
lea    0xea6(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    117d <open_port+0x4d>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
jmp    119c <open_port+0x6c>
mov    -0x4(%rbp),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_port>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e7e(%rip),%rax
or     (%rax),%esi
lea    0xead(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     117a <open_port+0x4a>
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
lea    0xe93(%rip),%rdi
jmp    1181 <open_port+0x51>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/ttyO2\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [40 x i8] c"open_port: Unable to open /dev/ttyO2. \0A\00"
@F_SETFL = global i32 0
@.str.2 = [15 x i8] c"port is open.\0A\00"
define i32 @open_port() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %2, %3
%5 = load i32, i32* @O_NDELAY
%6 = or i32 %4, %5
%7 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %17
12: ; preds = %0
%13 = load i32, i32* %1
%14 = load i32, i32* @F_SETFL
%15 = call i32 @fcntl(i32 %13, i32 %14, i32 0)
%16 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %12, %10
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/ttyO2\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
@str = [14 x i8] c"port is open.\00"
@str.3 = [39 x i8] c"open_port: Unable to open /dev/ttyO2. \00"
define i32 @open_port() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_NOCTTY
%3 = or i32 %2, %1
%4 = load i32, i32* @O_NDELAY
%5 = or i32 %3, %4
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = load i32, i32* @F_SETFL
%10 = tail call i32 @fcntl(i32 %6, i32 %9, i32 0)
br label %11
11: ; preds = %0, %8
%12 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0), %8 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @str.3, i64 0, i64 0), %0 ]
%13 = tail call i32 @puts(i8* dereferenceable(1) %12)
ret i32 %6
}