#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*/ perror(char *);
int open_port(char *port) {
  int fd;
  fd = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    perror("open_port: Unable to open /dev/ttyd0 - ");
  } else
    fcntl(fd, F_SETFL, 0);
  return (fd);
}


x86 assembly (clang, -O0):
<open_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
or     (%rax),%esi
mov    0x2e6f(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    117e <open_port+0x4e>
lea    0xe8c(%rip),%rdi
call   1050 <perror@plt>
jmp    1191 <open_port+0x61>
mov    -0xc(%rbp),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0xc(%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
call   1040 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     116e <open_port+0x3e>
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
jmp    116a <open_port+0x3a>

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

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