#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 O_CREAT;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
int open_output_file(char *path) {
  int fd;
  fd = open(path, O_WRONLY | O_CREAT, (S_IRUSR | S_IWUSR));
  if (fd < 0) {
    fprintf(stderr, "oepn : %s failed \n", path);
    exit(1);
  }
  return fd;
}


x86 assembly (clang, -O0):
<open_output_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    0x2ea8(%rip),%rax
or     (%rax),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
mov    0x2e7e(%rip),%rax
or     (%rax),%edx
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1199 <open_output_file+0x69>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_output_file>:
push   %rbx
mov    %rdi,%rbx
mov    0x2e7d(%rip),%rax
mov    0x2eb6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e7b(%rip),%rax
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1040 <open@plt>
test   %eax,%eax
js     1163 <open_output_file+0x33>
pop    %rbx
ret
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"oepn : %s failed \0A\00"
define i32 @open_output_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %8, %9
%11 = call i32 @open(i8* %4, i32 %7, i32 %10)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %2
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %1
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"oepn : %s failed \0A\00"
define i32 @open_output_file(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @S_IRUSR
%6 = load i32, i32* @S_IWUSR
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %0, i32 %4, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %1
ret i32 %8
}