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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ init_file(struct file_data *, char const *, size_t);
int open(char const *, int, int);
int /*<<< orphan*/ stderr;
int create_file(struct file_data *data, const char *name, int flags,
                size_t filesize) {
  int fd;
  if ((fd = open(name, flags, 0644)) < 0) {
    fprintf(stderr, "unable to open file %s: %m\n", name);
    return -1;
  }
  init_file(data, name, filesize);
  return fd;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1189 <create_file+0x59>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe88(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a0 <create_file+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <init_file@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
mov    %edx,%esi
mov    $0x1a4,%edx
call   1050 <open@plt>
test   %eax,%eax
js     1165 <create_file+0x35>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <init_file@plt>
jmp    1182 <create_file+0x52>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.file_data = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"unable to open file %s: %m\0A\00"
define i32 @create_file(%struct.file_data* %0, i8* %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca %struct.file_data*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
store %struct.file_data* %0, %struct.file_data** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64 %3, i64* %9
%11 = load i8*, i8** %7
%12 = load i32, i32* %8
%13 = call i32 @open(i8* %11, i32 %12, i32 420)
store i32 %13, i32* %10
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %7
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %5
br label %25
19: ; preds = %4
%20 = load %struct.file_data*, %struct.file_data** %6
%21 = load i8*, i8** %7
%22 = load i64, i64* %9
%23 = call i32 @init_file(%struct.file_data* %20, i8* %21, i64 %22)
%24 = load i32, i32* %10
store i32 %24, i32* %5
br label %25
25: ; preds = %19, %15
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
%struct.file_data = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"unable to open file %s: %m\0A\00"
define i32 @create_file(%struct.file_data* %0, i8* %1, i32 %2, i64 %3) {
%5 = tail call i32 @open(i8* %1, i32 %2, i32 420)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %12
10: ; preds = %4
%11 = tail call i32 @init_file(%struct.file_data* %0, i8* %1, i64 %3)
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ -1, %7 ], [ %5, %10 ]
ret i32 %13
}