#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*/ FILENAME_MAX;
char *getenv(char *);
char *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int /*<<< orphan*/, char *, char *, char *);
char *get_cache_path(void) {
  char *ref_cache = getenv("REF_CACHE");
  if (!ref_cache || *ref_cache == 0) {
    char *ext = NULL;
    char *base = getenv("XDG_CACHE_HOME");
    if (!(base && *base)) {
      base = getenv("HOME");
      if (base && *base)
        ext = "/.cache";
    }
    if (!(base && *base))
      base = getenv("TMPDIR");
    if (!(base && *base))
      base = getenv("TEMP");
    if (!(base && *base))
      base = "/tmp";
    if (!ext)
      ext = "";
    ref_cache = malloc(FILENAME_MAX);
    snprintf(ref_cache, FILENAME_MAX, "%s%s/hts-ref/%%2s/%%2s/%%s", base, ext);
  }
  return ref_cache;
}


x86 assembly (clang, -O0):
<get_cache_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1163 <get_cache_path+0x33>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1296 <get_cache_path+0x166>
movq   $0x0,-0x10(%rbp)
lea    0xe98(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1196 <get_cache_path+0x66>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d1 <get_cache_path+0xa1>
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cc <get_cache_path+0x9c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cc <get_cache_path+0x9c>
lea    0xe51(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11d1 <get_cache_path+0xa1>
cmpq   $0x0,-0x18(%rbp)
je     11ec <get_cache_path+0xbc>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11fc <get_cache_path+0xcc>
lea    0xe2e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1217 <get_cache_path+0xe7>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1227 <get_cache_path+0xf7>
lea    0xe0a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1242 <get_cache_path+0x112>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    124d <get_cache_path+0x11d>
lea    0xde4(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1263 <get_cache_path+0x133>
lea    0xdaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xda1(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_cache_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1154 <get_cache_path+0x24>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    11f9 <get_cache_path+0xc9>
lea    0xeaf(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116d <get_cache_path+0x3d>
mov    %rax,%r15
cmpb   $0x0,(%rax)
jne    11c8 <get_cache_path+0x98>
lea    0xea0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118f <get_cache_path+0x5f>
mov    %rax,%r15
cmpb   $0x0,(%rax)
je     118f <get_cache_path+0x5f>
lea    0xe8c(%rip),%r14
jmp    11cf <get_cache_path+0x9f>
lea    0xe8b(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a8 <get_cache_path+0x78>
mov    %rax,%r15
cmpb   $0x0,(%rax)
jne    11c8 <get_cache_path+0x98>
lea    0xe79(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c1 <get_cache_path+0x91>
mov    %rax,%r15
cmpb   $0x0,(%rax)
jne    11c8 <get_cache_path+0x98>
lea    0xe65(%rip),%r15
lea    0xe3a(%rip),%r14
mov    0x2e12(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe49(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"REF_CACHE\00"
@.str.1 = [15 x i8] c"XDG_CACHE_HOME\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [8 x i8] c"/.cache\00"
@.str.4 = [7 x i8] c"TMPDIR\00"
@.str.5 = [5 x i8] c"TEMP\00"
@.str.6 = [5 x i8] c"/tmp\00"
@.str.7 = [1 x i8] zeroinitializer
@FILENAME_MAX = global i32 0
@.str.8 = [27 x i8] c"%s%s/hts-ref/%%2s/%%2s/%%s\00"
define i8* @get_cache_path() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i8*, i8** %1
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %73
12: ; preds = %7, %0
store i8* null, i8** %2
%13 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %32, label %21
21: ; preds = %16, %12
%22 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %22, i8** %3
%23 = load i8*, i8** %3
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %31
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %31
31: ; preds = %30, %25, %21
br label %32
32: ; preds = %31, %16
%33 = load i8*, i8** %3
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i8*, i8** %3
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %35, %32
%41 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i8* %41, i8** %3
br label %42
42: ; preds = %40, %35
%43 = load i8*, i8** %3
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load i8*, i8** %3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %45, %42
%51 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i8* %51, i8** %3
br label %52
52: ; preds = %50, %45
%53 = load i8*, i8** %3
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %60
55: ; preds = %52
%56 = load i8*, i8** %3
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp ne i32 %58, 0
br i1 %59, label %61, label %60
60: ; preds = %55, %52
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %61
61: ; preds = %60, %55
%62 = load i8*, i8** %2
%63 = icmp ne i8* %62, null
br i1 %63, label %65, label %64
64: ; preds = %61
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %65
65: ; preds = %64, %61
%66 = load i32, i32* @FILENAME_MAX
%67 = call i8* @malloc(i32 %66)
store i8* %67, i8** %1
%68 = load i8*, i8** %1
%69 = load i32, i32* @FILENAME_MAX
%70 = load i8*, i8** %3
%71 = load i8*, i8** %2
%72 = call i32 @snprintf(i8* %68, i32 %69, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %70, i8* %71)
br label %73
73: ; preds = %65, %7
%74 = load i8*, i8** %1
ret i8* %74
}

LLVM IR (-O2):
@.str = [10 x i8] c"REF_CACHE\00"
@.str.1 = [15 x i8] c"XDG_CACHE_HOME\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [8 x i8] c"/.cache\00"
@.str.4 = [7 x i8] c"TMPDIR\00"
@.str.5 = [5 x i8] c"TEMP\00"
@.str.6 = [5 x i8] c"/tmp\00"
@.str.7 = [1 x i8] zeroinitializer
@FILENAME_MAX = global i32 0
@.str.8 = [27 x i8] c"%s%s/hts-ref/%%2s/%%2s/%%s\00"
define i8* @get_cache_path() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %37
6: ; preds = %3, %0
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %9, %6
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i8, i8* %13
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %15, %12
%19 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i8, i8* %19
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %18, %21
%25 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i8, i8* %25
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27, %24
br label %31
31: ; preds = %15, %9, %21, %30, %27
%32 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), %27 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), %30 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), %21 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), %9 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %15 ]
%33 = phi i8* [ %25, %27 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), %30 ], [ %19, %21 ], [ %7, %9 ], [ %13, %15 ]
%34 = load i32, i32* @FILENAME_MAX
%35 = tail call i8* @malloc(i32 %34)
%36 = tail call i32 @snprintf(i8* %35, i32 %34, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i8* %33, i8* %32)
br label %37
37: ; preds = %31, %3
%38 = phi i8* [ %35, %31 ], [ %1, %3 ]
ret i8* %38
}