#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_RDONLY;
int S_IRUSR;
int S_IWUSR;
int close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void failExclFileCreation() {
  int fd;
  if ((fd = open("./newfile", O_RDONLY | O_CREAT | O_EXCL,
                 S_IRUSR | S_IWUSR)) == -1) {
    fprintf(stderr, "Unable to create './newfile': %s\n", strerror(errno));
  }
  if (close(fd) == -1) {
    fprintf(stderr, "Closing failed: %s\n", strerror(errno));
  }
}


x86 assembly (clang, -O0):
<failExclFileCreation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    0x2ea0(%rip),%rax
or     (%rax),%esi
mov    0x2e5f(%rip),%rax
or     (%rax),%esi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
mov    0x2e65(%rip),%rax
or     (%rax),%edx
lea    0xe84(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
jne    11b9 <failExclFileCreation+0x79>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x8(%rbp),%edi
mov    %rax,%rdx
lea    0xe56(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
jne    11f6 <failExclFileCreation+0xb6>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rdx
lea    0xe3b(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<failExclFileCreation>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e96(%rip),%rax
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e64(%rip),%rax
or     (%rax),%esi
mov    0x2e4b(%rip),%rax
mov    0x2e6c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe89(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11ab <failExclFileCreation+0x6b>
mov    0x2e3e(%rip),%rax
mov    (%rax),%ebp
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe69(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    %ebx,%edi
call   1030 <close@plt>
cmp    $0xffffffff,%eax
je     11be <failExclFileCreation+0x7e>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e03(%rip),%rax
mov    (%rax),%ebx
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe50(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"./newfile\00"
@O_RDONLY = 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.1 = [34 x i8] c"Unable to create './newfile': %s\0A\00"
@errno = global i32 0
@.str.2 = [20 x i8] c"Closing failed: %s\0A\00"
define void @failExclFileCreation() {
%1 = alloca i32
%2 = load i32, i32* @O_RDONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %2, %3
%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 %7, %8
%10 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %9)
store i32 %10, i32* %1
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %17
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %12, %0
%18 = load i32, i32* %1
%19 = call i32 @close(i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = call i8* @strerror(i32 %23)
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %21, %17
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"./newfile\00"
@O_RDONLY = 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.1 = [34 x i8] c"Unable to create './newfile': %s\0A\00"
@errno = global i32 0
@.str.2 = [20 x i8] c"Closing failed: %s\0A\00"
define void @failExclFileCreation() {
%1 = load i32, i32* @O_RDONLY
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = load i32, i32* @O_EXCL
%5 = or i32 %3, %4
%6 = load i32, i32* @S_IRUSR
%7 = load i32, i32* @S_IWUSR
%8 = or i32 %7, %6
%9 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %0
%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 ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %11, %0
%17 = tail call i32 @close(i32 %9)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %19, %16
ret void
}