#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 */
typedef int /*<<< orphan*/ mode_t;

/* Variables and functions */
int /*<<< orphan*/ POSIX_FADV_SEQUENTIAL;
int /*<<< orphan*/ access_flags_string(int);
int /*<<< orphan*/ fatal_error_with_errno(char *, char const *,
                                          int /*<<< orphan*/);
int open(char const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ posix_fadvise(int, int /*<<< orphan*/, int /*<<< orphan*/,
                                 int /*<<< orphan*/);
int standard_fd_from_flags(int);
scalar_t__ string_is_hyphen(char const *);
void *xopen(const char *path, int flags, mode_t mode) {
  int fd;
  if (string_is_hyphen(path)) {
    fd = standard_fd_from_flags(flags);
  } else {
    fd = open(path, flags | 0, mode);
  }
  if (fd < 0)
    fatal_error_with_errno("Failed to open \"%s\" for %s", path,
                           access_flags_string(flags));
  posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
  return (void *)(intptr_t)fd;
}


x86 assembly (clang, -O0):
<xopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <string_is_hyphen@plt>
cmp    $0x0,%rax
je     1195 <xopen+0x35>
mov    -0xc(%rbp),%edi
call   1060 <standard_fd_from_flags@plt>
mov    %eax,-0x14(%rbp)
jmp    11aa <xopen+0x4a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
or     $0x0,%esi
mov    -0x10(%rbp),%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d6 <xopen+0x76>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <access_flags_string@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe2f(%rip),%rdi
call   1040 <fatal_error_with_errno@plt>
mov    -0x14(%rbp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%ecx
xor    %edx,%edx
mov    %edx,%esi
call   1050 <posix_fadvise@plt>
movslq -0x14(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xopen>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <string_is_hyphen@plt>
test   %rax,%rax
je     1180 <xopen+0x20>
mov    %r14d,%edi
call   1060 <standard_fd_from_flags@plt>
jmp    118d <xopen+0x2d>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %ebp,%edx
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11ac <xopen+0x4c>
mov    %r14d,%edi
call   1080 <access_flags_string@plt>
lea    0xe5e(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <fatal_error_with_errno@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%ecx
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <posix_fadvise@plt>
movslq %ebp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Failed to open \22%s\22 for %s\00"
@POSIX_FADV_SEQUENTIAL = global i32 0
define i8* @xopen(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i64 @string_is_hyphen(i8* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* %5
%13 = call i32 @standard_fd_from_flags(i32 %12)
store i32 %13, i32* %7
br label %20
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = or i32 %16, 0
%18 = load i32, i32* %6
%19 = call i32 @open(i8* %15, i32 %17, i32 %18)
store i32 %19, i32* %7
br label %20
20: ; preds = %14, %11
%21 = load i32, i32* %7
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = call i32 @access_flags_string(i32 %25)
%27 = call i32 @fatal_error_with_errno(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %24, i32 %26)
br label %28
28: ; preds = %23, %20
%29 = load i32, i32* %7
%30 = load i32, i32* @POSIX_FADV_SEQUENTIAL
%31 = call i32 @posix_fadvise(i32 %29, i32 0, i32 0, i32 %30)
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = inttoptr i64 %33 to i8*
ret i8* %34
}

LLVM IR (-O2):
@.str = [27 x i8] c"Failed to open \22%s\22 for %s\00"
@POSIX_FADV_SEQUENTIAL = global i32 0
define i8* @xopen(i8* %0, i32 %1, i32 %2) {
%4 = tail call i64 @string_is_hyphen(i8* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @standard_fd_from_flags(i32 %1)
br label %10
8: ; preds = %3
%9 = tail call i32 @open(i8* %0, i32 %1, i32 %2)
br label %10
10: ; preds = %8, %6
%11 = phi i32 [ %7, %6 ], [ %9, %8 ]
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @access_flags_string(i32 %1)
%15 = tail call i32 @fatal_error_with_errno(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %14)
br label %16
16: ; preds = %13, %10
%17 = load i32, i32* @POSIX_FADV_SEQUENTIAL
%18 = tail call i32 @posix_fadvise(i32 %11, i32 0, i32 0, i32 %17)
%19 = sext i32 %11 to i64
%20 = inttoptr i64 %19 to i8*
ret i8* %20
}