#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_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int,
                           char *);
int open64(char const *, int, int);
int /*<<< orphan*/ stderr;
char *strerror(int);
int open_file(const char *filename) {
  int fd = -1, ret = 0;
  int open_rw_flags = O_RDWR;
  fd = open64(filename, open_rw_flags,
              (S_IRUSR | S_IWUSR | S_IXUSR | S_IROTH | S_IWOTH | S_IXOTH |
               S_IRGRP | S_IWGRP | S_IXGRP));
  if (fd < 0) {
    ret = errno;
    fprintf(stderr, "create file %s failed:%d:%s\n", filename, ret,
            strerror(ret));
  }
  ret = fd;
  return ret;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
mov    0x2e5b(%rip),%rax
or     (%rax),%edx
mov    0x2e62(%rip),%rax
or     (%rax),%edx
mov    0x2e19(%rip),%rax
or     (%rax),%edx
mov    0x2df8(%rip),%rax
or     (%rax),%edx
mov    0x2e4f(%rip),%rax
or     (%rax),%edx
mov    0x2e06(%rip),%rax
or     (%rax),%edx
mov    0x2e2d(%rip),%rax
or     (%rax),%edx
mov    0x2e14(%rip),%rax
or     (%rax),%edx
call   1040 <open64@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1207 <open_file+0xd7>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%ecx
mov    %rax,%r8
lea    0xdfe(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e52(%rip),%rax
mov    0x2e83(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e88(%rip),%rax
or     (%rax),%edx
mov    0x2e3f(%rip),%rax
or     (%rax),%edx
mov    0x2e1e(%rip),%rax
or     (%rax),%edx
mov    0x2e75(%rip),%rax
or     (%rax),%edx
mov    %rdi,%rbx
mov    0x2e29(%rip),%rax
or     (%rax),%edx
mov    0x2e68(%rip),%rax
mov    0x2e49(%rip),%rcx
or     (%rcx),%edx
mov    (%rax),%esi
mov    0x2e2e(%rip),%rax
or     (%rax),%edx
call   1040 <open64@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11d3 <open_file+0xa3>
mov    0x2e02(%rip),%rax
mov    (%rax),%r14d
mov    0x2e00(%rip),%rax
mov    (%rax),%r15d
mov    %r14d,%edi
call   1050 <strerror@plt>
lea    0xe3e(%rip),%rsi
mov    %r15d,%edi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    %rax,%r8
call   1030 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"create file %s failed:%d:%s\0A\00"
define i32 @open_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
store i32 0, i32* %4
%6 = load i32, i32* @O_RDWR
store i32 %6, i32* %5
%7 = load i8*, i8** %2
%8 = load i32, i32* %5
%9 = load i32, i32* @S_IRUSR
%10 = load i32, i32* @S_IWUSR
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IXUSR
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IROTH
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IWOTH
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IXOTH
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IRGRP
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IWGRP
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IXGRP
%25 = or i32 %23, %24
%26 = call i32 @open64(i8* %7, i32 %8, i32 %25)
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %1
%30 = load i32, i32* @errno
store i32 %30, i32* %4
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %2
%33 = load i32, i32* %4
%34 = load i32, i32* %4
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %32, i32 %33, i8* %35)
br label %37
37: ; preds = %29, %1
%38 = load i32, i32* %3
store i32 %38, i32* %4
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"create file %s failed:%d:%s\0A\00"
define i32 @open_file(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @S_IRUSR
%4 = load i32, i32* @S_IWUSR
%5 = or i32 %4, %3
%6 = load i32, i32* @S_IXUSR
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IROTH
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IWOTH
%11 = or i32 %9, %10
%12 = load i32, i32* @S_IXOTH
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IRGRP
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IWGRP
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IXGRP
%19 = or i32 %17, %18
%20 = tail call i32 @open64(i8* %0, i32 %2, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %1
%23 = load i32, i32* @errno
%24 = load i32, i32* @stderr
%25 = tail call i8* @strerror(i32 %23)
%26 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %23, i8* %25)
br label %27
27: ; preds = %22, %1
ret i32 %20
}