#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 */
scalar_t__ FILENAME_MAX;
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, scalar_t__, char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
void get_config_dir(char *buf) {
  if (NULL != getenv("XDG_CONFIG_HOME")) {
    strncpy(buf, getenv("XDG_CONFIG_HOME"), FILENAME_MAX - 14);
  } else {
    snprintf(buf, FILENAME_MAX - 14, "%s/.config", getenv("HOME"));
  }
}


x86 assembly (clang, -O0):
<get_config_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1189 <get_config_dir+0x59>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xe9b(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x10(%rbp),%rdi
mov    %rax,%rsi
mov    0x2e70(%rip),%rax
mov    (%rax),%rdx
sub    $0xe,%rdx
call   1040 <strncpy@plt>
jmp    11c6 <get_config_dir+0x96>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%rax
sub    $0xe,%rax
mov    %rax,-0x18(%rbp)
lea    0xe61(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %rax,%rcx
lea    0xe4f(%rip),%rdx
call   1050 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_config_dir>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
mov    0x2e9e(%rip),%rcx
mov    (%rcx),%rbx
add    $0xfffffffffffffff2,%rbx
test   %rax,%rax
je     116b <get_config_dir+0x3b>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strncpy@plt>
lea    0xe99(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe92(%rip),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <snprintf@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@FILENAME_MAX = global i64 0
@.str.1 = [11 x i8] c"%s/.config\00"
@.str.2 = [5 x i8] c"HOME\00"
define void @get_config_dir(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i8* null, %3
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i8*, i8** %2
%7 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = load i64, i64* @FILENAME_MAX
%9 = sub nsw i64 %8, 14
%10 = call i32 @strncpy(i8* %6, i8* %7, i64 %9)
br label %17
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = load i64, i64* @FILENAME_MAX
%14 = sub nsw i64 %13, 14
%15 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @snprintf(i8* %12, i64 %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %11, %5
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@FILENAME_MAX = global i64 0
@.str.1 = [11 x i8] c"%s/.config\00"
@.str.2 = [5 x i8] c"HOME\00"
define void @get_config_dir(i8* %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
%4 = load i64, i64* @FILENAME_MAX
%5 = add nsw i64 %4, -14
br i1 %3, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @strncpy(i8* %0, i8* %2, i64 %5)
br label %11
8: ; preds = %1
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @snprintf(i8* %0, i64 %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %8, %6
ret void
}