#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 asprintf(char **, char *, char const *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *ltr_int_get_data_path(char const *);
char *ltr_int_get_default_file_name(char *);
char *ltr_int_get_resource_path(const char *section, const char *rsrc) {
  char *rsrc_path = NULL;
  if (asprintf(&rsrc_path, "/%s/%s", section, rsrc) == -1) {
    return NULL;
  }
  char *path = ltr_int_get_default_file_name(rsrc_path);
  FILE *f = fopen(path, "rb");
  if (f != NULL) {
    fclose(f);
    free(rsrc_path);
    return path;
  }
  path = ltr_int_get_data_path(rsrc);
  f = fopen(path, "rb");
  if (f != NULL) {
    fclose(f);
    return path;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<ltr_int_get_resource_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1070 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    11a6 <ltr_int_get_resource_path+0x46>
movq   $0x0,-0x8(%rbp)
jmp    123b <ltr_int_get_resource_path+0xdb>
mov    -0x20(%rbp),%rdi
call   1040 <ltr_int_get_default_file_name@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11f1 <ltr_int_get_resource_path+0x91>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123b <ltr_int_get_resource_path+0xdb>
mov    -0x18(%rbp),%rdi
call   1060 <ltr_int_get_data_path@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1233 <ltr_int_get_resource_path+0xd3>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    123b <ltr_int_get_resource_path+0xdb>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltr_int_get_resource_path>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rdx
movq   $0x0,(%rsp)
lea    0xe87(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rcx
call   1070 <asprintf@plt>
cmp    $0xffffffff,%eax
je     11e5 <ltr_int_get_resource_path+0x85>
mov    (%rsp),%rdi
call   1040 <ltr_int_get_default_file_name@plt>
mov    %rax,%rbx
lea    0xe6b(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11bc <ltr_int_get_resource_path+0x5c>
mov    %rax,%rdi
call   1050 <fclose@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    11e7 <ltr_int_get_resource_path+0x87>
mov    %r14,%rdi
call   1060 <ltr_int_get_data_path@plt>
mov    %rax,%rbx
lea    0xe39(%rip),%rsi
mov    %rax,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e5 <ltr_int_get_resource_path+0x85>
mov    %rax,%rdi
call   1050 <fclose@plt>
jmp    11e7 <ltr_int_get_resource_path+0x87>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"/%s/%s\00"
@.str.1 = [3 x i8] c"rb\00"
define i8* @ltr_int_get_resource_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %2
store i8* null, i8** %3
br label %39
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = call i8* @ltr_int_get_default_file_name(i8* %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %8
%19 = load i32*, i32** %8
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %14
%22 = load i32*, i32** %8
%23 = call i32 @fclose(i32* %22)
%24 = load i8*, i8** %6
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %7
store i8* %26, i8** %3
br label %39
27: ; preds = %14
%28 = load i8*, i8** %5
%29 = call i8* @ltr_int_get_data_path(i8* %28)
store i8* %29, i8** %7
%30 = load i8*, i8** %7
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %31, i32** %8
%32 = load i32*, i32** %8
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i32*, i32** %8
%36 = call i32 @fclose(i32* %35)
%37 = load i8*, i8** %7
store i8* %37, i8** %3
br label %39
38: ; preds = %27
store i8* null, i8** %3
br label %39
39: ; preds = %38, %34, %21, %13
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
@.str = [7 x i8] c"/%s/%s\00"
@.str.1 = [3 x i8] c"rb\00"
define i8* @ltr_int_get_resource_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = call i32 @asprintf(i8** %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%6 = icmp eq i32 %5, -1
br i1 %6, label %22, label %7
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = call i8* @ltr_int_get_default_file_name(i8* %8)
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = call i32 @fclose(i32* %10)
%14 = load i8*, i8** %3
%15 = call i32 @free(i8* %14)
br label %22
16: ; preds = %7
%17 = call i8* @ltr_int_get_data_path(i8* %1)
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 @fclose(i32* %18)
br label %22
22: ; preds = %12, %20, %16, %2
%23 = phi i8* [ null, %2 ], [ %9, %12 ], [ %17, %20 ], [ null, %16 ]
ret i8* %23
}