#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 */
scalar_t__ asprintf(char **, char *, char const *, char const *);
int /*<<< orphan*/ file_is_openable_for_read(char *);
int /*<<< orphan*/ free(char *);
char *check_path(const char *path, const char *filename) {
  char *cur;
  if (asprintf(&cur, "%s/%s", path, filename) < 0) {
    return 0;
  } else if (!file_is_openable_for_read(cur)) {
    free(cur);
    return 0;
  }
  return cur;
}


x86 assembly (clang, -O0):
<check_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0x0,%rax
jge    116f <check_path+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <check_path+0x74>
mov    -0x20(%rbp),%rdi
call   1050 <file_is_openable_for_read@plt>
cmp    $0x0,%eax
jne    1197 <check_path+0x67>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a4 <check_path+0x74>
jmp    119c <check_path+0x6c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_path>:
push   %rax
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xec2(%rip),%rsi
mov    %rsp,%rdi
call   1040 <asprintf@plt>
test   %rax,%rax
js     1168 <check_path+0x38>
mov    (%rsp),%rdi
call   1050 <file_is_openable_for_read@plt>
mov    %eax,%ecx
mov    (%rsp),%rax
test   %ecx,%ecx
je     1160 <check_path+0x30>
pop    %rcx
ret
mov    %rax,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
define i8* @check_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = call i32 @file_is_openable_for_read(i8* %8)
%10 = icmp eq i32 %9, 0
%11 = load i8*, i8** %3
br i1 %10, label %12, label %14
12: ; preds = %7
%13 = call i32 @free(i8* %11)
br label %14
14: ; preds = %7, %2, %12
%15 = phi i8* [ null, %12 ], [ null, %2 ], [ %11, %7 ]
ret i8* %15
}