#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 *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
char *strdup(char const *);
int strlen(char const *);
char *XcursorLibraryPath(void) {
  const char *env_var;
  char *path = NULL;
  int pathlen = 0;
  env_var = getenv("XCURSOR_PATH");
  if (env_var) {
    path = strdup(env_var);
  } else {
    env_var = getenv("XDG_DATA_HOME");
    if (env_var) {
      pathlen = strlen(env_var) +
                strlen("/icons"
                       ":"
                       "~/.icons:/usr/share/icons:/usr/share/pixmaps:~/"
                       ".cursors:/usr/share/cursors/xorg-x11:"
                       "/usr/X11R6/lib/X11/icons") +
                1;
      path = malloc(pathlen);
      snprintf(path, pathlen, "%s%s", env_var,
               "/icons"
               ":"
               "~/.icons:/usr/share/icons:/usr/share/pixmaps:~/.cursors:/usr/"
               "share/cursors/xorg-x11:"
               "/usr/X11R6/lib/X11/icons");
    } else {
      path = strdup("~/.local/share"
                    "/icons"
                    ":"
                    "~/.icons:/usr/share/icons:/usr/share/pixmaps:~/.cursors:/"
                    "usr/share/cursors/xorg-x11:"
                    "/usr/X11R6/lib/X11/icons");
    }
  }
  return path;
}


x86 assembly (clang, -O0):
<XcursorLibraryPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe92(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1194 <XcursorLibraryPath+0x44>
mov    -0x8(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    1218 <XcursorLibraryPath+0xc8>
lea    0xe72(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1203 <XcursorLibraryPath+0xb3>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
lea    0xe6c(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rcx
lea    0xe29(%rip),%rdx
lea    0xe35(%rip),%r8
call   1050 <snprintf@plt>
jmp    1213 <XcursorLibraryPath+0xc3>
lea    0xe16(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    1218 <XcursorLibraryPath+0xc8>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XcursorLibraryPath>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117a <XcursorLibraryPath+0x2a>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <strdup@plt>
lea    0xe8c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11de <XcursorLibraryPath+0x8e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
lea    0xe8e(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%r14,%rax,1),%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe5b(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %rbx,%rcx
mov    %r15,%r8
call   1050 <snprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe3b(%rip),%rdi
jmp    116b <XcursorLibraryPath+0x1b>

LLVM IR (-O0):
@.str = [13 x i8] c"XCURSOR_PATH\00"
@.str.1 = [14 x i8] c"XDG_DATA_HOME\00"
@.str.2 = [116 x i8] c"/icons:~/.icons:/usr/share/icons:/usr/share/pixmaps:~/.cursors:/usr/share/cursors/xorg-x11:/usr/X11R6/lib/X11/icons\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [130 x i8] c"~/.local/share/icons:~/.icons:/usr/share/icons:/usr/share/pixmaps:~/.cursors:/usr/share/cursors/xorg-x11:/usr/X11R6/lib/X11/icons\00"
define i8* @XcursorLibraryPath() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
store i8* null, i8** %2
store i32 0, i32* %3
%4 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 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 %10
7: ; preds = %0
%8 = load i8*, i8** %1
%9 = call i8* @strdup(i8* %8)
store i8* %9, i8** %2
br label %29
10: ; preds = %0
%11 = call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i8* %11, i8** %1
%12 = load i8*, i8** %1
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = load i8*, i8** %1
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @strlen(i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.2, i64 0, i64 0))
%18 = add nsw i32 %16, %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %2
%22 = load i8*, i8** %2
%23 = load i32, i32* %3
%24 = load i8*, i8** %1
%25 = call i32 @snprintf(i8* %22, i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.2, i64 0, i64 0))
br label %28
26: ; preds = %10
%27 = call i8* @strdup(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.4, i64 0, i64 0))
store i8* %27, i8** %2
br label %28
28: ; preds = %26, %14
br label %29
29: ; preds = %28, %7
%30 = load i8*, i8** %2
ret i8* %30
}

LLVM IR (-O2):
@.str = [13 x i8] c"XCURSOR_PATH\00"
@.str.1 = [14 x i8] c"XDG_DATA_HOME\00"
@.str.2 = [116 x i8] c"/icons:~/.icons:/usr/share/icons:/usr/share/pixmaps:~/.cursors:/usr/share/cursors/xorg-x11:/usr/X11R6/lib/X11/icons\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [130 x i8] c"~/.local/share/icons:~/.icons:/usr/share/icons:/usr/share/pixmaps:~/.cursors:/usr/share/cursors/xorg-x11:/usr/X11R6/lib/X11/icons\00"
define i8* @XcursorLibraryPath() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 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 %17
5: ; preds = %0
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %6)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.2, i64 0, i64 0))
%11 = add i32 %9, 1
%12 = add i32 %11, %10
%13 = tail call i8* @malloc(i32 %12)
%14 = tail call i32 @snprintf(i8* %13, i32 %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([116 x i8], [116 x i8]* @.str.2, i64 0, i64 0))
br label %17
15: ; preds = %5
%16 = tail call dereferenceable_or_null(130) i8* @strdup(i8* getelementptr inbounds ([130 x i8], [130 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %8, %15, %3
%18 = phi i8* [ %4, %3 ], [ %13, %8 ], [ %16, %15 ]
ret i8* %18
}