#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_EXCL;
int O_WRONLY;
int /*<<< orphan*/ S_IRUSR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int open(char const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int create_file(const char *path) {
  int fd = open(path, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR);
  if (fd == -1)
    fprintf(stderr, "open: %s: %s\n", path, strerror(errno));
  return fd;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    0x2e80(%rip),%rax
or     (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
mov    0x2e5e(%rip),%rax
mov    (%rax),%edx
call   1040 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11ae <create_file+0x7e>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe57(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2eba(%rip),%rax
mov    0x2e8b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e60(%rip),%rax
or     (%rax),%esi
mov    0x2e67(%rip),%rax
mov    (%rax),%edx
call   1040 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1194 <create_file+0x64>
mov    0x2e6a(%rip),%rax
mov    (%rax),%r14d
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe7a(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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