#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRGRP;
int S_IRUSR;
int S_IWGRP;
int S_IWUSR;
int open(char *, int, int);
int stat(char *, struct stat *);
int xattrkv_new(char *dbname) {
  struct stat dbs;
  int ok = stat(dbname, &dbs);
  if (ok != 0) {
    int db =
        open(dbname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
    return db;
  }
  return -1;
}


x86 assembly (clang, -O0):
<xattrkv_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1193 <xattrkv_new+0x73>
mov    -0x10(%rbp),%rdi
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
mov    0x2e86(%rip),%rax
or     (%rax),%esi
mov    0x2e55(%rip),%rax
mov    (%rax),%edx
mov    0x2e64(%rip),%rax
or     (%rax),%edx
mov    0x2e4b(%rip),%rax
or     (%rax),%edx
mov    0x2e5a(%rip),%rax
or     (%rax),%edx
call   1040 <open@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119a <xattrkv_new+0x7a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xattrkv_new>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <stat@plt>
test   %eax,%eax
je     1179 <xattrkv_new+0x59>
mov    0x2ebb(%rip),%rax
mov    0x2e9c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e69(%rip),%rax
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e5f(%rip),%rax
or     (%rax),%edx
mov    0x2e6e(%rip),%rax
or     (%rax),%edx
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1040 <open@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
define i32 @xattrkv_new(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @stat(i8* %7, %struct.stat* %4)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_RDWR
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IRGRP
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IWGRP
%22 = or i32 %20, %21
%23 = call i32 @open(i8* %12, i32 %15, i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
store i32 %24, i32* %2
br label %26
25: ; preds = %1
store i32 -1, i32* %2
br label %26
26: ; preds = %25, %11
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
define i32 @xattrkv_new(i8* nocapture %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i32 @stat(i8* %0, %struct.stat* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = load i32, i32* @O_CREAT
%8 = load i32, i32* @O_RDWR
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %11, %10
%13 = load i32, i32* @S_IRGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IWGRP
%16 = or i32 %14, %15
%17 = tail call i32 @open(i8* %0, i32 %9, i32 %16)
br label %18
18: ; preds = %1, %6
%19 = phi i32 [ %17, %6 ], [ -1, %1 ]
ret i32 %19
}