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


x86 assembly (clang, -O0):
<find_load_photo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%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    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11c4 <find_load_photo+0x64>
mov    -0x38(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ee <find_load_photo+0x8e>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1070 <read_file@plt>
mov    %eax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_load_photo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
call   1060 <find_file_path@plt>
mov    %rax,%rbx
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     11b1 <find_load_photo+0x51>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <read_file@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %r14d,%eax
jmp    11c5 <find_load_photo+0x65>
lea    0xe48(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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