#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*/ access(char *, int);
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *strdup(char *);
char *get_book_file(char *bookdir, char *env_variable, char *path, char *name,
                    int mode) {
  char file[256];
  char *aux;
  if (bookdir)
    path = bookdir;
  else if ((aux = getenv(env_variable)))
    path = aux;
  else if (!access(name, mode))
    path = ".";
  else
    ;
  sprintf(file, "%s/%s", path, name);
  return strdup(file);
}


x86 assembly (clang, -O0):
<get_book_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1177 <get_book_file+0x37>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11d5 <get_book_file+0x95>
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x138(%rbp)
cmp    $0x0,%rax
je     11a1 <get_book_file+0x61>
mov    -0x138(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11d0 <get_book_file+0x90>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <access@plt>
cmp    $0x0,%eax
jne    11c6 <get_book_file+0x86>
lea    0xe43(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11cb <get_book_file+0x8b>
jmp    11cb <get_book_file+0x8b>
jmp    11d0 <get_book_file+0x90>
jmp    11d5 <get_book_file+0x95>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe17(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x130(%rbp),%rdi
call   1060 <strdup@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_book_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rdi,%rdx
test   %rdi,%rdi
jne    1186 <get_book_file+0x46>
mov    %r8d,%ebp
mov    %rsi,%rdi
call   1030 <getenv@plt>
mov    %rax,%rdx
test   %rax,%rax
jne    1186 <get_book_file+0x46>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <access@plt>
test   %eax,%eax
lea    0xe81(%rip),%rax
cmove  %rax,%r14
mov    %r14,%rdx
lea    0xe75(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rcx
call   1050 <sprintf@plt>
mov    %rbp,%rdi
call   1060 <strdup@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define noalias i8* @get_book_file(i8* %0, i8* nocapture %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = icmp eq i8* %0, null
br i1 %8, label %9, label %16
9: ; preds = %5
%10 = tail call i8* @getenv(i8* %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = tail call i32 @access(i8* %3, i32 %4)
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %2
br label %16
16: ; preds = %12, %9, %5
%17 = phi i8* [ %0, %5 ], [ %10, %9 ], [ %15, %12 ]
%18 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %3)
%19 = call i8* @strdup(i8* %7)
ret i8* %19
}