#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_RDWR;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, char *);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int main() {
  int fd1 = open("/asdf/gakk", O_RDWR | O_CREAT | O_EXCL, S_IRWXU);
  fprintf(stderr, "fd1: %d, errno: %d, strerror: %s\n", fd1, errno,
          strerror(errno));
  close(fd1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
mov    0x2e58(%rip),%rax
or     (%rax),%esi
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
lea    0xe86(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    %rax,%r8
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e8d(%rip),%rax
mov    0x2ea6(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e63(%rip),%rax
or     (%rax),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
lea    0xe91(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
mov    0x2e4b(%rip),%rax
mov    (%rax),%r14d
mov    0x2e31(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xe74(%rip),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %rax,%r8
call   1040 <fprintf@plt>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/asdf/gakk\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRWXU = global i32 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"fd1: %d, errno: %d, strerror: %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_CREAT
%5 = or i32 %3, %4
%6 = load i32, i32* @O_EXCL
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRWXU
%9 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* @stderr
%11 = load i32, i32* %2
%12 = load i32, i32* @errno
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12, i8* %14)
%16 = load i32, i32* %2
%17 = call i32 @close(i32 %16)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/asdf/gakk\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRWXU = global i32 0
@stderr = global i32 0
@.str.1 = [34 x i8] c"fd1: %d, errno: %d, strerror: %s\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%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_IRWXU
%7 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %9, i8* %10)
%12 = tail call i32 @close(i32 %7)
ret i32 0
}