#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int ffindex_insert_filestream(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              size_t *, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *fopen(char const *, char *);
int ffindex_insert_file(FILE *data_file, FILE *index_file, size_t *offset,
                        const char *path, char *name) {
  FILE *file = fopen(path, "r");
  if (file == NULL)
    return errno;
  int ret =
      ffindex_insert_filestream(data_file, index_file, offset, file, name);
  fclose(file);
  return ret;
}


x86 assembly (clang, -O0):
<ffindex_insert_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    117c <ffindex_insert_file+0x4c>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11a7 <ffindex_insert_file+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1030 <ffindex_insert_filestream@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffindex_insert_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
lea    0xeb2(%rip),%rsi
mov    %rcx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1180 <ffindex_insert_file+0x50>
mov    %rax,%rbx
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
mov    %r14,%r8
call   1030 <ffindex_insert_filestream@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
jmp    1189 <ffindex_insert_file+0x59>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@errno = global i32 0
define i32 @ffindex_insert_file(i32* %0, i32* %1, i64* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i64*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32
store i32* %0, i32** %7
store i32* %1, i32** %8
store i64* %2, i64** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%14 = load i8*, i8** %10
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %12
%16 = load i32*, i32** %12
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %5
%19 = load i32, i32* @errno
store i32 %19, i32* %6
br label %30
20: ; preds = %5
%21 = load i32*, i32** %7
%22 = load i32*, i32** %8
%23 = load i64*, i64** %9
%24 = load i32*, i32** %12
%25 = load i8*, i8** %11
%26 = call i32 @ffindex_insert_filestream(i32* %21, i32* %22, i64* %23, i32* %24, i8* %25)
store i32 %26, i32* %13
%27 = load i32*, i32** %12
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %13
store i32 %29, i32* %6
br label %30
30: ; preds = %20, %18
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@errno = global i32 0
define i32 @ffindex_insert_file(i32* %0, i32* %1, i64* %2, i8* nocapture %3, i8* %4) {
%6 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = load i32, i32* @errno
br label %13
10: ; preds = %5
%11 = tail call i32 @ffindex_insert_filestream(i32* %0, i32* %1, i64* %2, i32* %6, i8* %4)
%12 = tail call i32 @fclose(i32* %6)
br label %13
13: ; preds = %10, %8
%14 = phi i32 [ %9, %8 ], [ %11, %10 ]
ret i32 %14
}