#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 */
struct path {
  int dummy;
};

/* Variables and functions */
int ENOENT;
int ENOMEM;
char *getenv(char *);
int /*<<< orphan*/ path_add_component(struct path *, char *);
int /*<<< orphan*/ path_delete(struct path *);
int path_new_from_string(struct path **, char const *);
int xdg_get_config_home(struct path **path) {
  int ret = 0;
  *path = NULL;
  const char *config_home = getenv("XDG_CONFIG_HOME");
  if (config_home)
    ret = path_new_from_string(path, config_home);
  if (ret == ENOMEM)
    return ENOMEM;
  if (*path == NULL) {
    const char *home = getenv("HOME");
    if (home) {
      ret = path_new_from_string(path, home);
      if (ret == ENOMEM)
        return ENOMEM;
      if (*path == NULL)
        return ENOENT;
      if (!path_add_component(*path, ".config")) {
        path_delete(*path);
        *path = NULL;
        return ENOMEM;
      }
    } else
      return ENOENT;
  }
  return 0;
}


x86 assembly (clang, -O0):
<xdg_get_config_home>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
lea    0xe9b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1189 <xdg_get_config_home+0x49>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <path_new_from_string@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%eax
jne    11ac <xdg_get_config_home+0x6c>
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <xdg_get_config_home+0x14d>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1286 <xdg_get_config_home+0x146>
lea    0xe4a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1270 <xdg_get_config_home+0x130>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <path_new_from_string@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2df1(%rip),%rcx
cmp    (%rcx),%eax
jne    1208 <xdg_get_config_home+0xc8>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <xdg_get_config_home+0x14d>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1227 <xdg_get_config_home+0xe7>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <xdg_get_config_home+0x14d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xddb(%rip),%rsi
call   1060 <path_add_component@plt>
cmp    $0x0,%eax
jne    126b <xdg_get_config_home+0x12b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <path_delete@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <xdg_get_config_home+0x14d>
jmp    1281 <xdg_get_config_home+0x141>
mov    0x2d59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <xdg_get_config_home+0x14d>
jmp    1286 <xdg_get_config_home+0x146>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xdg_get_config_home>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movq   $0x0,(%rdi)
lea    0xeab(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116c <xdg_get_config_home+0x2c>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <path_new_from_string@plt>
jmp    116e <xdg_get_config_home+0x2e>
xor    %eax,%eax
mov    0x2e6b(%rip),%r14
cmp    (%r14),%eax
je     11df <xdg_get_config_home+0x9f>
xor    %eax,%eax
cmpq   $0x0,(%rbx)
jne    11df <xdg_get_config_home+0x9f>
lea    0xe82(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11d6 <xdg_get_config_home+0x96>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <path_new_from_string@plt>
cmp    (%r14),%eax
je     11df <xdg_get_config_home+0x9f>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     11d6 <xdg_get_config_home+0x96>
lea    0xe5e(%rip),%rsi
call   1060 <path_add_component@plt>
mov    %eax,%ecx
mov    $0x0,%eax
test   %ecx,%ecx
jne    11df <xdg_get_config_home+0x9f>
mov    (%rbx),%rdi
call   1050 <path_delete@plt>
movq   $0x0,(%rbx)
mov    (%r14),%eax
jmp    11df <xdg_get_config_home+0x9f>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.path = type { i32 }
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@ENOMEM = global i32 0
@.str.1 = [5 x i8] c"HOME\00"
@ENOENT = global i32 0
@.str.2 = [8 x i8] c".config\00"
define i32 @xdg_get_config_home(%struct.path** %0) {
%2 = alloca i32
%3 = alloca %struct.path**
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store %struct.path** %0, %struct.path*** %3
store i32 0, i32* %4
%7 = load %struct.path**, %struct.path*** %3
store %struct.path* null, %struct.path** %7
%8 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load %struct.path**, %struct.path*** %3
%13 = load i8*, i8** %5
%14 = call i32 @path_new_from_string(%struct.path** %12, i8* %13)
store i32 %14, i32* %4
br label %15
15: ; preds = %11, %1
%16 = load i32, i32* %4
%17 = load i32, i32* @ENOMEM
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i32, i32* @ENOMEM
store i32 %20, i32* %2
br label %60
21: ; preds = %15
%22 = load %struct.path**, %struct.path*** %3
%23 = load %struct.path*, %struct.path** %22
%24 = icmp eq %struct.path* %23, null
br i1 %24, label %25, label %59
25: ; preds = %21
%26 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %56
29: ; preds = %25
%30 = load %struct.path**, %struct.path*** %3
%31 = load i8*, i8** %6
%32 = call i32 @path_new_from_string(%struct.path** %30, i8* %31)
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = load i32, i32* @ENOMEM
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = load i32, i32* @ENOMEM
store i32 %37, i32* %2
br label %60
38: ; preds = %29
%39 = load %struct.path**, %struct.path*** %3
%40 = load %struct.path*, %struct.path** %39
%41 = icmp eq %struct.path* %40, null
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = load i32, i32* @ENOENT
store i32 %43, i32* %2
br label %60
44: ; preds = %38
%45 = load %struct.path**, %struct.path*** %3
%46 = load %struct.path*, %struct.path** %45
%47 = call i32 @path_add_component(%struct.path* %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%48 = icmp ne i32 %47, 0
br i1 %48, label %55, label %49
49: ; preds = %44
%50 = load %struct.path**, %struct.path*** %3
%51 = load %struct.path*, %struct.path** %50
%52 = call i32 @path_delete(%struct.path* %51)
%53 = load %struct.path**, %struct.path*** %3
store %struct.path* null, %struct.path** %53
%54 = load i32, i32* @ENOMEM
store i32 %54, i32* %2
br label %60
55: ; preds = %44
br label %58
56: ; preds = %25
%57 = load i32, i32* @ENOENT
store i32 %57, i32* %2
br label %60
58: ; preds = %55
br label %59
59: ; preds = %58, %21
store i32 0, i32* %2
br label %60
60: ; preds = %59, %56, %49, %42, %36, %19
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
%struct.path = type { i32 }
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@ENOMEM = global i32 0
@.str.1 = [5 x i8] c"HOME\00"
@ENOENT = global i32 0
@.str.2 = [8 x i8] c".config\00"
define i32 @xdg_get_config_home(%struct.path** %0) {
store %struct.path* null, %struct.path** %0
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @path_new_from_string(%struct.path** %0, i8* %2)
br label %6
6: ; preds = %4, %1
%7 = phi i32 [ %5, %4 ], [ 0, %1 ]
%8 = load i32, i32* @ENOMEM
%9 = icmp eq i32 %7, %8
br i1 %9, label %34, label %10
10: ; preds = %6
%11 = load %struct.path*, %struct.path** %0
%12 = icmp eq %struct.path* %11, null
br i1 %12, label %13, label %34
13: ; preds = %10
%14 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %32, label %16
16: ; preds = %13
%17 = tail call i32 @path_new_from_string(%struct.path** %0, i8* %14)
%18 = load i32, i32* @ENOMEM
%19 = icmp eq i32 %17, %18
br i1 %19, label %34, label %20
20: ; preds = %16
%21 = load %struct.path*, %struct.path** %0
%22 = icmp eq %struct.path* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i32, i32* @ENOENT
br label %34
25: ; preds = %20
%26 = tail call i32 @path_add_component(%struct.path* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load %struct.path*, %struct.path** %0
%30 = tail call i32 @path_delete(%struct.path* %29)
store %struct.path* null, %struct.path** %0
%31 = load i32, i32* @ENOMEM
br label %34
32: ; preds = %13
%33 = load i32, i32* @ENOENT
br label %34
34: ; preds = %16, %23, %28, %32, %10, %25, %6
%35 = phi i32 [ %7, %6 ], [ 0, %25 ], [ 0, %10 ], [ %17, %16 ], [ %24, %23 ], [ %31, %28 ], [ %33, %32 ]
ret i32 %35
}