#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*/ F_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ asprintf(char **, char *, char const *, char const *);
int /*<<< orphan*/ free(char *);
bool fsll_file_exists(const char *base, const char *file) {
  const char *target = base;
  char *path = NULL;
  if (file != NULL) {
    asprintf(&path, "%s/%s", base, file);
    target = path;
  }
  bool result = (access(target, F_OK) == 0);
  free(path);
  return result;
}


x86 assembly (clang, -O0):
<fsll_file_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117b <fsll_file_exists+0x4b>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1040 <asprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsll_file_exists>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rdx
movq   $0x0,0x8(%rsp)
test   %rsi,%rsi
je     115f <fsll_file_exists+0x2f>
mov    %rsi,%rcx
lea    0xeb0(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1040 <asprintf@plt>
mov    0x8(%rsp),%rdx
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    %rdx,%rdi
call   1050 <access@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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