#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 const *, int);
scalar_t__ setup_uart(int, int);
int init_uart(const char *port, int baud) {
  int fd = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    return -1;
  } else {
    fcntl(fd, F_SETFL, 0);
  }
  if (setup_uart(fd, baud) < 0) {
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<init_uart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
mov    0x2e85(%rip),%rax
or     (%rax),%esi
mov    0x2e6c(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    117c <init_uart+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <init_uart+0x86>
mov    -0x18(%rbp),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <setup_uart@plt>
cmp    $0x0,%rax
jge    11b0 <init_uart+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <init_uart+0x86>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_uart>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rcx
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %esi,%ebx
mov    0x2e7a(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1186 <init_uart+0x56>
mov    %eax,%ebp
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %ebp,%edi
mov    %ebx,%esi
call   1040 <setup_uart@plt>
test   %rax,%rax
mov    $0xffffffff,%eax
cmovns %ebp,%eax
jmp    118b <init_uart+0x5b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
define i32 @init_uart(i8* nocapture %0, i32 %1) {
%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* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* @F_SETFL
%12 = tail call i32 @fcntl(i32 %8, i32 %11, i32 0)
%13 = tail call i64 @setup_uart(i32 %8, i32 %1)
%14 = icmp slt i64 %13, 0
%15 = select i1 %14, i32 -1, i32 %8
br label %16
16: ; preds = %10, %2
%17 = phi i32 [ -1, %2 ], [ %15, %10 ]
ret i32 %17
}