#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int ret = -1;
  int fd = -1;
  fd = open(argv[1], O_CREAT | O_EXCL, 0644);
  if (fd == -1) {
    fprintf(stderr, "creation of the file %s failed (%s)\n", argv[1],
            strerror(errno));
    goto out;
  }
  ret = 0;
out:
  if (fd > 0)
    close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    0x2e54(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11d6 <main+0x96>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe34(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11dd <main+0x9d>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    11ef <main+0xaf>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2ea7(%rip),%rax
mov    0x2e78(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     117a <main+0x3a>
xor    %ebx,%ebx
test   %eax,%eax
jle    11ae <main+0x6e>
mov    %eax,%edi
call   1030 <close@plt>
jmp    11ae <main+0x6e>
mov    0x2e57(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe64(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"creation of the file %s failed (%s)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_EXCL
%13 = or i32 %11, %12
%14 = call i32 @open(i8* %10, i32 %13, i32 420)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %25
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %23)
br label %26
25: ; preds = %2
store i32 0, i32* %6
br label %26
26: ; preds = %25, %17
%27 = load i32, i32* %7
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %7
%31 = call i32 @close(i32 %30)
br label %32
32: ; preds = %29, %26
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"creation of the file %s failed (%s)\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_EXCL
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %4, i32 %7, i32 420)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = load i32, i32* @errno
%14 = tail call i8* @strerror(i32 %13)
%15 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %14)
br label %20
16: ; preds = %2
%17 = icmp sgt i32 %8, 0
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 @close(i32 %8)
br label %20
20: ; preds = %10, %18, %16
%21 = phi i32 [ -1, %10 ], [ 0, %18 ], [ 0, %16 ]
ret i32 %21
}