#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 */
char *concat(char *, char *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *strdup(char *);
char *get_xdg_data_home() {
  char *s;
  if ((s = getenv("XDG_DATA_HOME")) != NULL) {
    return strdup(s);
  } else if ((s = getenv("HOME")) != NULL) {
    char *suffix = "/.local/share";
    return concat(s, suffix);
  } else {
    char *a = concat("/home/", getenv("USER"));
    char *b = concat(a, "/.local/share");
    free(a);
    return b;
  }
}


x86 assembly (clang, -O0):
<get_xdg_data_home>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1174 <get_xdg_data_home+0x34>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11f3 <get_xdg_data_home+0xb3>
lea    0xe8e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11af <get_xdg_data_home+0x6f>
lea    0xe79(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <concat@plt>
mov    %rax,-0x8(%rbp)
jmp    11f3 <get_xdg_data_home+0xb3>
lea    0xe6d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rsi
lea    0xe57(%rip),%rdi
call   1050 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1050 <concat@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_xdg_data_home>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1164 <get_xdg_data_home+0x24>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <strdup@plt>
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     118b <get_xdg_data_home+0x4b>
lea    0xe92(%rip),%rsi
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <concat@plt>
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe7e(%rip),%rdi
mov    %rax,%rsi
call   1050 <concat@plt>
mov    %rax,%rbx
lea    0xe5e(%rip),%rsi
mov    %rax,%rdi
call   1050 <concat@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"XDG_DATA_HOME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [14 x i8] c"/.local/share\00"
@.str.3 = [7 x i8] c"/home/\00"
@.str.4 = [5 x i8] c"USER\00"
define i8* @get_xdg_data_home() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i8*, i8** %2
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %1
br label %26
11: ; preds = %0
%12 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %2
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8** %3
%15 = load i8*, i8** %2
%16 = load i8*, i8** %3
%17 = call i8* @concat(i8* %15, i8* %16)
store i8* %17, i8** %1
br label %26
18: ; preds = %11
%19 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%20 = call i8* @concat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %19)
store i8* %20, i8** %4
%21 = load i8*, i8** %4
%22 = call i8* @concat(i8* %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i8* %22, i8** %5
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
%25 = load i8*, i8** %5
store i8* %25, i8** %1
br label %26
26: ; preds = %18, %14, %8
%27 = load i8*, i8** %1
ret i8* %27
}

LLVM IR (-O2):
@.str = [14 x i8] c"XDG_DATA_HOME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [14 x i8] c"/.local/share\00"
@.str.3 = [7 x i8] c"/home/\00"
@.str.4 = [5 x i8] c"USER\00"
define i8* @get_xdg_data_home() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i8* @strdup(i8* %1)
br label %15
5: ; preds = %0
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = tail call i8* @concat(i8* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %15
10: ; preds = %5
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i8* @concat(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%13 = tail call i8* @concat(i8* %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call i32 @free(i8* %12)
br label %15
15: ; preds = %10, %8, %3
%16 = phi i8* [ %4, %3 ], [ %9, %8 ], [ %13, %10 ]
ret i8* %16
}