#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_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ close(int);
scalar_t__ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int open_serial_port(char *port) {
  int fd;
  ;
  ;
  fd = open(port, O_RDWR | O_NONBLOCK);
  if (fd < 0) {
    ;
    ;
    return -1;
  } else {
    ;
    ;
  }
  if (fcntl(fd, F_SETFL, 0) < 0) {
    close(fd);
    ;
    ;
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<open_serial_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1170 <open_serial_port+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <open_serial_port+0x7c>
jmp    1175 <open_serial_port+0x45>
mov    -0x14(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    11a6 <open_serial_port+0x76>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <open_serial_port+0x7c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_serial_port>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <open@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1177 <open_serial_port+0x47>
mov    %eax,%ebp
mov    0x2e74(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %rax,%rax
js     1170 <open_serial_port+0x40>
mov    %ebp,%ebx
jmp    1177 <open_serial_port+0x47>
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @open_serial_port(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %6, %7
%9 = call i32 @open(i8* %5, i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %24
13: ; preds = %1
br label %14
14: ; preds = %13
%15 = load i32, i32* %4
%16 = load i32, i32* @F_SETFL
%17 = call i64 @fcntl(i32 %15, i32 %16, i32 0)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
store i32 -1, i32* %2
br label %24
22: ; preds = %14
%23 = load i32, i32* %4
store i32 %23, i32* %2
br label %24
24: ; preds = %22, %19, %12
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @open_serial_port(i8* nocapture %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NONBLOCK
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %1
%8 = load i32, i32* @F_SETFL
%9 = tail call i64 @fcntl(i32 %5, i32 %8, i32 0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @close(i32 %5)
br label %13
13: ; preds = %7, %1, %11
%14 = phi i32 [ -1, %11 ], [ -1, %1 ], [ %5, %7 ]
ret i32 %14
}