#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int O_CREAT;
int O_EXCL;
int O_WRONLY;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int open(char const *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
FILE *open_file(const char *path) {
  int fd;
  FILE *f;
  fd = open(path, O_WRONLY | 0 | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | 0 | 0);
  if (fd < 0) {
    fprintf(stderr, "Error creating '%s': %s\n", path, strerror(errno));
    exit(EXIT_FAILURE);
  }
  f = fdopen(fd, "wb");
  if (f == NULL) {
    fprintf(stderr, "Error creating stream for '%s': %s\n", path,
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  return f;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
mov    0x2e85(%rip),%rax
or     (%rax),%esi
mov    0x2e4c(%rip),%rax
or     (%rax),%esi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
mov    0x2e52(%rip),%rax
or     (%rax),%edx
or     $0x0,%edx
or     $0x0,%edx
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ee <open_file+0x9e>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe25(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
lea    0xe21(%rip),%rsi
call   1040 <fdopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1252 <open_file+0x102>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xddd(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e43(%rip),%rax
mov    0x2e94(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e59(%rip),%rax
or     (%rax),%esi
mov    0x2e38(%rip),%rax
mov    0x2e61(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1050 <open@plt>
test   %eax,%eax
js     11a6 <open_file+0x56>
lea    0xe86(%rip),%rsi
mov    %eax,%edi
call   1040 <fdopen@plt>
test   %rax,%rax
je     11c6 <open_file+0x76>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e23(%rip),%rax
mov    (%rax),%ebp
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe3c(%rip),%rsi
jmp    11e4 <open_file+0x94>
mov    0x2e03(%rip),%rax
mov    (%rax),%ebp
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe38(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Error creating '%s': %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [36 x i8] c"Error creating stream for '%s': %s\0A\00"
define i32* @open_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_WRONLY
%7 = or i32 %6, 0
%8 = load i32, i32* @O_CREAT
%9 = or i32 %7, %8
%10 = load i32, i32* @O_EXCL
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IRUSR
%13 = load i32, i32* @S_IWUSR
%14 = or i32 %12, %13
%15 = or i32 %14, 0
%16 = or i32 %15, 0
%17 = call i32 @open(i8* %5, i32 %11, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %1
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %2
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %1
%29 = load i32, i32* %3
%30 = call i32* @fdopen(i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %4
%31 = load i32*, i32** %4
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %41
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %2
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %28
%42 = load i32*, i32** %4
ret i32* %42
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"Error creating '%s': %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [36 x i8] c"Error creating stream for '%s': %s\0A\00"
define noalias i32* @open_file(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_EXCL
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* %0, i32 %6, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %1
%20 = tail call i32* @fdopen(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = tail call i8* @strerror(i32 %24)
%26 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %19
ret i32* %20
}