#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 vmfile {
  int dummy;
};

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int open(char const *, int, int);
int perror(char *);
int /*<<< orphan*/ unlink(char const *);
int vmfile_attachfd(struct vmfile *, int, size_t);
int vmfile_init(struct vmfile *vmb, const char *filename, size_t initial_size) {
  unlink(filename);
  int fd = open(filename, O_CREAT | O_RDWR, 0644);
  if (fd < 0)
    return perror("open, "
                  "vmfile"
                  "_init"),
           -1;
  return vmfile_attachfd(vmb, fd, initial_size);
}


x86 assembly (clang, -O0):
<vmfile_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
mov    0x2e6f(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a2 <vmfile_init+0x62>
lea    0xe6f(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <vmfile_init+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <vmfile_attachfd@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vmfile_init>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <unlink@plt>
mov    0x2e9b(%rip),%rax
mov    0x2e7c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1a4,%edx
call   1050 <open@plt>
test   %eax,%eax
js     118b <vmfile_init+0x4b>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <vmfile_attachfd@plt>
lea    0xe6e(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.vmfile = type { i32 }
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str = [18 x i8] c"open, vmfile_init\00"
define i32 @vmfile_init(%struct.vmfile* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.vmfile*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store %struct.vmfile* %0, %struct.vmfile** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%9 = load i8*, i8** %6
%10 = call i32 @unlink(i8* %9)
%11 = load i8*, i8** %6
%12 = load i32, i32* @O_CREAT
%13 = load i32, i32* @O_RDWR
%14 = or i32 %12, %13
%15 = call i32 @open(i8* %11, i32 %14, i32 420)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %25
20: ; preds = %3
%21 = load %struct.vmfile*, %struct.vmfile** %5
%22 = load i32, i32* %8
%23 = load i64, i64* %7
%24 = call i32 @vmfile_attachfd(%struct.vmfile* %21, i32 %22, i64 %23)
store i32 %24, i32* %4
br label %25
25: ; preds = %20, %18
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
%struct.vmfile = type { i32 }
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str = [18 x i8] c"open, vmfile_init\00"
define i32 @vmfile_init(%struct.vmfile* %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32 @unlink(i8* %1)
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_RDWR
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %1, i32 %7, i32 420)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %14
12: ; preds = %3
%13 = tail call i32 @vmfile_attachfd(%struct.vmfile* %0, i32 %8, i64 %2)
br label %14
14: ; preds = %12, %10
%15 = phi i32 [ -1, %10 ], [ %13, %12 ]
ret i32 %15
}