#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 ANT_SetSerialAttrs(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ B115200;
int O_EXCL;
int O_NOCTTY;
int O_RDWR;
int O_SYNC;
int open(char const *, int);
int ANT_OpenSerial(const char *path) {
  int fd;
  fd = open(path, O_RDWR | O_NOCTTY | O_SYNC | O_EXCL);
  if (-1 == fd)
    return -1;
  if (-1 == ANT_SetSerialAttrs(fd, B115200, 0)) {
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<ANT_OpenSerial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
mov    0x2e97(%rip),%rax
or     (%rax),%esi
mov    0x2e76(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1176 <ANT_OpenSerial+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <ANT_OpenSerial+0x8a>
mov    -0x14(%rbp),%edi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ANT_SetSerialAttrs@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11a4 <ANT_OpenSerial+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <ANT_OpenSerial+0x8a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ANT_OpenSerial>:
push   %rbx
mov    0x2ec0(%rip),%rax
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2ea6(%rip),%rax
or     (%rax),%esi
mov    0x2e85(%rip),%rax
or     (%rax),%esi
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     116b <ANT_OpenSerial+0x4b>
mov    %eax,%ebx
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <ANT_SetSerialAttrs@plt>
cmp    $0xffffffff,%eax
cmove  %eax,%ebx
jmp    1170 <ANT_OpenSerial+0x50>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@O_EXCL = global i32 0
@B115200 = global i32 0
define i32 @ANT_OpenSerial(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_NOCTTY
%8 = or i32 %6, %7
%9 = load i32, i32* @O_SYNC
%10 = or i32 %8, %9
%11 = load i32, i32* @O_EXCL
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %5, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = icmp eq i32 -1, %14
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 -1, i32* %2
br label %25
17: ; preds = %1
%18 = load i32, i32* %4
%19 = load i32, i32* @B115200
%20 = call i32 @ANT_SetSerialAttrs(i32 %18, i32 %19, i32 0)
%21 = icmp eq i32 -1, %20
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 -1, i32* %2
br label %25
23: ; preds = %17
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %25
25: ; preds = %23, %22, %16
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@O_EXCL = global i32 0
@B115200 = global i32 0
define i32 @ANT_OpenSerial(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_SYNC
%6 = or i32 %4, %5
%7 = load i32, i32* @O_EXCL
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* %0, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %16, label %11
11: ; preds = %1
%12 = load i32, i32* @B115200
%13 = tail call i32 @ANT_SetSerialAttrs(i32 %9, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
%15 = select i1 %14, i32 -1, i32 %9
br label %16
16: ; preds = %11, %1
%17 = phi i32 [ -1, %1 ], [ %15, %11 ]
ret i32 %17
}