#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 *get_xdg_data_home();
char *getenv(char *);
scalar_t__ malloc(int);
char *strdup(char *);
char **get_search_paths() {
  char *suffix = "/curseofwar/";
  int dirs_num = 7;
  char **path = (char **)malloc(sizeof(char *) * (dirs_num + 1));
  path[0] = strdup("");
  char *s;
  s = get_xdg_data_home();
  path[1] = concat(s, suffix);
  free(s);
  path[2] = concat(getenv("HOME"), "/.curseofwar/");
  path[3] = strdup("/usr/local/share/curseofwar/");
  path[4] = strdup("/usr/share/curseofwar/");
  path[5] = strdup("/usr/share/curseofwar-sdl/");
  path[6] = strdup("/usr/share/curseofwar-common/");
  path[dirs_num] = NULL;
  return path;
}


x86 assembly (clang, -O0):
<get_search_paths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb4(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x7,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xec9(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1080 <get_xdg_data_home@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <concat@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
lea    0xe26(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
lea    0xe1c(%rip),%rsi
call   1050 <concat@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x10(%rax)
lea    0xe13(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x18(%rax)
lea    0xe19(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x20(%rax)
lea    0xe19(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x28(%rax)
lea    0xe1d(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_search_paths>:
push   %r14
push   %rbx
push   %rax
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xee9(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,(%rbx)
xor    %eax,%eax
call   1080 <get_xdg_data_home@plt>
mov    %rax,%r14
lea    0xe92(%rip),%rsi
mov    %rax,%rdi
call   1050 <concat@plt>
mov    %rax,0x8(%rbx)
mov    %r14,%rdi
call   1040 <free@plt>
lea    0xe54(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe4d(%rip),%rsi
mov    %rax,%rdi
call   1050 <concat@plt>
mov    %rax,0x10(%rbx)
lea    0xe48(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,0x18(%rbx)
lea    0xe55(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,0x20(%rbx)
lea    0xe5c(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,0x28(%rbx)
lea    0xe67(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,0x30(%rbx)
movq   $0x0,0x38(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/curseofwar/\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [14 x i8] c"/.curseofwar/\00"
@.str.4 = [29 x i8] c"/usr/local/share/curseofwar/\00"
@.str.5 = [23 x i8] c"/usr/share/curseofwar/\00"
@.str.6 = [27 x i8] c"/usr/share/curseofwar-sdl/\00"
@.str.7 = [30 x i8] c"/usr/share/curseofwar-common/\00"
define i8** @get_search_paths() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %1
store i32 7, i32* %2
%5 = load i32, i32* %2
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = mul i64 8, %7
%9 = trunc i64 %8 to i32
%10 = call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8**
store i8** %11, i8*** %3
%12 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%13 = load i8**, i8*** %3
%14 = getelementptr inbounds i8*, i8** %13, i64 0
store i8* %12, i8** %14
%15 = call i8* (...) @get_xdg_data_home()
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i8*, i8** %1
%18 = call i8* @concat(i8* %16, i8* %17)
%19 = load i8**, i8*** %3
%20 = getelementptr inbounds i8*, i8** %19, i64 1
store i8* %18, i8** %20
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
%23 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = call i8* @concat(i8* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%25 = load i8**, i8*** %3
%26 = getelementptr inbounds i8*, i8** %25, i64 2
store i8* %24, i8** %26
%27 = call i8* @strdup(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%28 = load i8**, i8*** %3
%29 = getelementptr inbounds i8*, i8** %28, i64 3
store i8* %27, i8** %29
%30 = call i8* @strdup(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%31 = load i8**, i8*** %3
%32 = getelementptr inbounds i8*, i8** %31, i64 4
store i8* %30, i8** %32
%33 = call i8* @strdup(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%34 = load i8**, i8*** %3
%35 = getelementptr inbounds i8*, i8** %34, i64 5
store i8* %33, i8** %35
%36 = call i8* @strdup(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%37 = load i8**, i8*** %3
%38 = getelementptr inbounds i8*, i8** %37, i64 6
store i8* %36, i8** %38
%39 = load i8**, i8*** %3
%40 = load i32, i32* %2
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
store i8* null, i8** %42
%43 = load i8**, i8*** %3
ret i8** %43
}

LLVM IR (-O2):
@.str = [13 x i8] c"/curseofwar/\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [14 x i8] c"/.curseofwar/\00"
@.str.4 = [29 x i8] c"/usr/local/share/curseofwar/\00"
@.str.5 = [23 x i8] c"/usr/share/curseofwar/\00"
@.str.6 = [27 x i8] c"/usr/share/curseofwar-sdl/\00"
@.str.7 = [30 x i8] c"/usr/share/curseofwar-common/\00"
define i8** @get_search_paths() {
%1 = tail call i64 @malloc(i32 64)
%2 = inttoptr i64 %1 to i8**
%3 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i8* %3, i8** %2
%4 = tail call i8* (...) @get_xdg_data_home()
%5 = tail call i8* @concat(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds i8*, i8** %2, i64 1
store i8* %5, i8** %6
%7 = tail call i32 @free(i8* %4)
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i8* @concat(i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%10 = getelementptr inbounds i8*, i8** %2, i64 2
store i8* %9, i8** %10
%11 = tail call dereferenceable_or_null(29) i8* @strdup(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %2, i64 3
store i8* %11, i8** %12
%13 = tail call dereferenceable_or_null(23) i8* @strdup(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %2, i64 4
store i8* %13, i8** %14
%15 = tail call dereferenceable_or_null(27) i8* @strdup(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%16 = getelementptr inbounds i8*, i8** %2, i64 5
store i8* %15, i8** %16
%17 = tail call dereferenceable_or_null(30) i8* @strdup(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0))
%18 = getelementptr inbounds i8*, i8** %2, i64 6
store i8* %17, i8** %18
%19 = getelementptr inbounds i8*, i8** %2, i64 7
store i8* null, i8** %19
ret i8** %2
}