#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 */
int /*<<< orphan*/ free(char *);
char *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ strlen(char *);
char *get_config_filename() {
  char *config_home;
  char *config_full_path;
  char *xdg_config_home;
  config_home = (char *)malloc(256);
  config_full_path = (char *)malloc(256);
  xdg_config_home = getenv("XDG_CONFIG_HOME");
  if (xdg_config_home != NULL) {
    if (strlen(xdg_config_home) != 0) {
      (void)snprintf(config_home, 255, "%s/.config", xdg_config_home);
    }
  } else {
    char *home;
    home = getenv("HOME");
    if (home != NULL) {
      (void)snprintf(config_home, 255, "%s/.config", home);
    } else
      return NULL;
  }
  (void)snprintf(config_full_path, 256, "%s/cdfrc", config_home);
  free(config_home);
  return config_full_path;
}


x86 assembly (clang, -O0):
<get_config_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x100,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c0 <get_config_filename+0x70>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     11bb <get_config_filename+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0xff,%esi
lea    0xe5a(%rip),%rdx
call   1060 <snprintf@plt>
jmp    120b <get_config_filename+0xbb>
lea    0xe44(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f9 <get_config_filename+0xa9>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0xff,%esi
lea    0xe21(%rip),%rdx
call   1060 <snprintf@plt>
jmp    1206 <get_config_filename+0xb6>
movq   $0x0,-0x8(%rbp)
jmp    1235 <get_config_filename+0xe5>
jmp    120b <get_config_filename+0xbb>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x100,%esi
lea    0xdfc(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_config_filename>:
push   %r14
push   %rbx
push   %rax
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xe9b(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1176 <get_config_filename+0x36>
cmpb   $0x0,(%rax)
jne    1187 <get_config_filename+0x47>
jmp    119e <get_config_filename+0x5e>
lea    0xe8e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11c8 <get_config_filename+0x88>
lea    0xe82(%rip),%rdx
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
lea    0xe76(%rip),%rdx
mov    %r14,%rdi
mov    $0x100,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %r14d,%r14d
jmp    11bd <get_config_filename+0x7d>

LLVM IR (-O0):
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [11 x i8] c"%s/.config\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [9 x i8] c"%s/cdfrc\00"
define i8* @get_config_filename() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = call i64 @malloc(i32 256)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %2
%8 = call i64 @malloc(i32 256)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %22
13: ; preds = %0
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = load i8*, i8** %4
%20 = call i32 @snprintf(i8* %18, i32 255, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %17, %13
br label %32
22: ; preds = %0
%23 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i8*, i8** %2
%28 = load i8*, i8** %5
%29 = call i32 @snprintf(i8* %27, i32 255, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %31
30: ; preds = %22
store i8* null, i8** %1
br label %39
31: ; preds = %26
br label %32
32: ; preds = %31, %21
%33 = load i8*, i8** %3
%34 = load i8*, i8** %2
%35 = call i32 @snprintf(i8* %33, i32 256, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %2
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %3
store i8* %38, i8** %1
br label %39
39: ; preds = %32, %30
%40 = load i8*, i8** %1
ret i8* %40
}

LLVM IR (-O2):
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [11 x i8] c"%s/.config\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [9 x i8] c"%s/cdfrc\00"
define i8* @get_config_filename() {
%1 = tail call i64 @malloc(i32 256)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i64 @malloc(i32 256)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = load i8, i8* %5
%9 = icmp eq i8 %8, 0
br i1 %9, label %16, label %13
10: ; preds = %0
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %10, %7
%14 = phi i8* [ %5, %7 ], [ %11, %10 ]
%15 = tail call i32 @snprintf(i8* %2, i32 255, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %7
%17 = tail call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%18 = tail call i32 @free(i8* %2)
br label %19
19: ; preds = %10, %16
%20 = phi i8* [ %4, %16 ], [ null, %10 ]
ret i8* %20
}