#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
char *find_file_path(char *);
int /*<<< orphan*/ free(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int read_file(int, char **, size_t *);
int find_load_file(char *path, char **file_content) {
  int fd, res;
  size_t len = 0;
  char *file_name = path;
  char *tmp;
  tmp = find_file_path(file_name);
  fd = open(tmp, O_RDONLY);
  if (fd == -1) {
    printf("cannot open XML file: Path = %s.\n", tmp);
    return -1;
  }
  res = read_file(fd, file_content, &len);
  free(tmp);
  close(fd);
  return res;
}


x86 assembly (clang, -O0):
<find_load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <find_file_path@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11c8 <find_load_file+0x68>
mov    -0x38(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <find_load_file+0x92>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <read_file@plt>
mov    %eax,-0x20(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_load_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
movq   $0x0,0x8(%rsp)
call   1060 <find_file_path@plt>
mov    %rax,%rbx
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     11b7 <find_load_file+0x57>
mov    %eax,%ebp
lea    0x8(%rsp),%rdx
mov    %eax,%edi
mov    %r14,%rsi
call   1070 <read_file@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1050 <close@plt>
jmp    11cc <find_load_file+0x6c>
lea    0xe42(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [34 x i8] c"cannot open XML file: Path = %s.\0A\00"
define i32 @find_load_file(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i64 0, i64* %8
%11 = load i8*, i8** %4
store i8* %11, i8** %9
%12 = load i8*, i8** %9
%13 = call i8* @find_file_path(i8* %12)
store i8* %13, i8** %10
%14 = load i8*, i8** %10
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i8*, i8** %10
%21 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %3
br label %31
22: ; preds = %2
%23 = load i32, i32* %6
%24 = load i8**, i8*** %5
%25 = call i32 @read_file(i32 %23, i8** %24, i64* %8)
store i32 %25, i32* %7
%26 = load i8*, i8** %10
%27 = call i32 @free(i8* %26)
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %7
store i32 %30, i32* %3
br label %31
31: ; preds = %22, %19
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [34 x i8] c"cannot open XML file: Path = %s.\0A\00"
define i32 @find_load_file(i8* %0, i8** %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%5 = tail call i8* @find_file_path(i8* %0)
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %5, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %15
11: ; preds = %2
%12 = call i32 @read_file(i32 %7, i8** %1, i64* %3)
%13 = call i32 @free(i8* %5)
%14 = call i32 @close(i32 %7)
br label %15
15: ; preds = %11, %9
%16 = phi i32 [ -1, %9 ], [ %12, %11 ]
ret i32 %16
}