#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;
int access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ dbg_fprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ free(char *);
char *set_db_path(char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *check_restore_path(const char *fn) {
  char *path = set_db_path(fn);
  if (access(path, F_OK) != -1)
    return path;
  do {
    dbg_fprintf("DB file %s doesn't exist. %s\n", path, strerror(errno));
  } while (0);
  free(path);
  return NULL;
}


x86 assembly (clang, -O0):
<check_restore_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <set_db_path@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
je     1191 <check_restore_path+0x41>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <check_restore_path+0x7f>
jmp    1196 <check_restore_path+0x46>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    0xe47(%rip),%rdi
call   1050 <dbg_fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_restore_path>:
push   %rbx
call   1040 <set_db_path@plt>
mov    %rax,%rbx
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <access@plt>
cmp    $0xffffffff,%eax
jne    1198 <check_restore_path+0x48>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe7c(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <dbg_fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [30 x i8] c"DB file %s doesn't exist. %s\0A\00"
@errno = global i32 0
define i8* @check_restore_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @set_db_path(i8* %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = load i32, i32* @F_OK
%9 = call i32 @access(i8* %7, i32 %8)
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i8*, i8** %4
store i8* %12, i8** %2
br label %22
13: ; preds = %1
br label %14
14: ; preds = %13
%15 = load i8*, i8** %4
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @dbg_fprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %17)
br label %19
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
store i8* null, i8** %2
br label %22
22: ; preds = %19, %11
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [30 x i8] c"DB file %s doesn't exist. %s\0A\00"
@errno = global i32 0
define i8* @check_restore_path(i8* %0) {
%2 = tail call i8* @set_db_path(i8* %0)
%3 = load i32, i32* @F_OK
%4 = tail call i32 @access(i8* %2, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @dbg_fprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %8)
%10 = tail call i32 @free(i8* %2)
br label %11
11: ; preds = %1, %6
%12 = phi i8* [ null, %6 ], [ %2, %1 ]
ret i8* %12
}