#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*/ EXIT_FAILURE;
int O_APPEND;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int open_or_die(char *path) {
  int file, flags = O_CREAT | O_WRONLY | O_APPEND;
  if ((NULL == path) || (-1 == (file = open(path, flags, 0666)))) {
    (void)fprintf(stderr, "Failed to open file \"%s\": %s\n", path,
                  strerror(errno));
    exit(EXIT_FAILURE);
  }
  return file;
}


x86 assembly (clang, -O0):
<open_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    0x2e5c(%rip),%rcx
or     (%rcx),%eax
mov    0x2e4b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
je     1199 <open_or_die+0x59>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    $0x1b6,%edx
call   1040 <open@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11df <open_or_die+0x9f>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe34(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_or_die>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %rdi,%rdi
je     117f <open_or_die+0x3f>
mov    0x2ea6(%rip),%rax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e4c(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1040 <open@plt>
cmp    $0xffffffff,%eax
je     117f <open_or_die+0x3f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e52(%rip),%rax
mov    (%rax),%ebp
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe63(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"Failed to open file \22%s\22: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @open_or_die(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_WRONLY
%7 = or i32 %5, %6
%8 = load i32, i32* @O_APPEND
%9 = or i32 %7, %8
store i32 %9, i32* %4
%10 = load i8*, i8** %2
%11 = icmp eq i8* null, %10
br i1 %11, label %17, label %12
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = call i32 @open(i8* %13, i32 %14, i32 438)
store i32 %15, i32* %3
%16 = icmp eq i32 -1, %15
br i1 %16, label %17, label %25
17: ; preds = %12, %1
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %2
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %12
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"Failed to open file \22%s\22: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @open_or_die(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = load i32, i32* @O_CREAT
%5 = load i32, i32* @O_WRONLY
%6 = or i32 %5, %4
%7 = load i32, i32* @O_APPEND
%8 = or i32 %6, %7
%9 = tail call i32 @open(i8* %0, i32 %8, i32 438)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %18
11: ; preds = %3, %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %3
ret i32 %9
}