#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*/ get_home_dir();
char *getenv(char const *);
char *joinpath(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
char *strdup(char *);
char *get_xdg_dir(const char *env, char *default_path) {
  char *xdg_dir = getenv(env);
  if (xdg_dir && xdg_dir[0]) {
    xdg_dir = strdup(xdg_dir);
  } else {
    xdg_dir = joinpath(get_home_dir(), default_path, NULL);
  }
  return xdg_dir;
}


x86 assembly (clang, -O0):
<get_xdg_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118a <get_xdg_dir+0x4a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118a <get_xdg_dir+0x4a>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    11a4 <get_xdg_dir+0x64>
mov    $0x0,%al
call   1050 <get_home_dir@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <joinpath@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_xdg_dir>:
push   %rbx
mov    %rsi,%rbx
call   1030 <getenv@plt>
test   %rax,%rax
je     115c <get_xdg_dir+0x1c>
cmpb   $0x0,(%rax)
je     115c <get_xdg_dir+0x1c>
mov    %rax,%rdi
pop    %rbx
jmp    1060 <strdup@plt>
xor    %eax,%eax
call   1050 <get_home_dir@plt>
mov    %eax,%edi
mov    %rbx,%rsi
xor    %edx,%edx
pop    %rbx
jmp    1040 <joinpath@plt>

LLVM IR (-O0):
define i8* @get_xdg_dir(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i8* @getenv(i8* %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i8*, i8** %5
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %5
br label %23
19: ; preds = %10, %2
%20 = call i32 (...) @get_home_dir()
%21 = load i8*, i8** %4
%22 = call i8* @joinpath(i32 %20, i8* %21, i32* null)
store i8* %22, i8** %5
br label %23
23: ; preds = %19, %16
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
define i8* @get_xdg_dir(i8* nocapture %0, i8* %1) {
%3 = tail call i8* @getenv(i8* %0)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i8* @strdup(i8* %3)
br label %13
10: ; preds = %5, %2
%11 = tail call i32 (...) @get_home_dir()
%12 = tail call i8* @joinpath(i32 %11, i8* %1, i32* null)
br label %13
13: ; preds = %10, %8
%14 = phi i8* [ %9, %8 ], [ %12, %10 ]
ret i8* %14
}