#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 */
typedef int /*<<< orphan*/ iniPath;

/* Variables and functions */
scalar_t__ fileExists(char *);
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *, ...);
const char *getIniFilePath(void) {
  if (fileExists("fs.ini")) {
    return "fs.ini";
  }
  const char *faststackConfig = "faststack/config.ini";
  char *xdgPath = getenv("XDG_CONFIG_HOME");
  static char iniPath[128];
  if (xdgPath) {
    snprintf(iniPath, sizeof(iniPath), "%s/%s", xdgPath, faststackConfig);
  } else {
    char *homePath = getenv("HOME");
    if (!homePath) {
      homePath = "~";
    }
    snprintf(iniPath, sizeof(iniPath), "%s/%s/%s", homePath, ".config",
             faststackConfig);
  }
  return iniPath;
}


x86 assembly (clang, -O0):
<getIniFilePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
call   1040 <fileExists@plt>
cmp    $0x0,%rax
je     115e <getIniFilePath+0x2e>
lea    0xeab(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1205 <getIniFilePath+0xd5>
lea    0xea2(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xeac(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ab <getIniFilePath+0x7b>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0x2ebd(%rip),%rdi
mov    $0x80,%esi
lea    0xe92(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    11fa <getIniFilePath+0xca>
lea    0xe75(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d1 <getIniFilePath+0xa1>
lea    0xe5f(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%r9
lea    0x2e70(%rip),%rdi
mov    $0x80,%esi
lea    0xe42(%rip),%rdx
lea    0xe44(%rip),%r8
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    0x2e4f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIniFilePath>:
push   %rbx
lea    0xec8(%rip),%rbx
mov    %rbx,%rdi
call   1040 <fileExists@plt>
test   %rax,%rax
jne    11c4 <getIniFilePath+0x94>
lea    0xed0(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117f <getIniFilePath+0x4f>
lea    0x2ef3(%rip),%rbx
lea    0xecd(%rip),%rdx
lea    0xe9c(%rip),%r8
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    11c4 <getIniFilePath+0x94>
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe97(%rip),%rcx
cmovne %rax,%rcx
lea    0x2eb0(%rip),%rbx
lea    0xe87(%rip),%rdx
lea    0xe89(%rip),%r8
lea    0xe52(%rip),%r9
mov    %rbx,%rdi
mov    $0x80,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"fs.ini\00"
@.str.1 = [21 x i8] c"faststack/config.ini\00"
@.str.2 = [16 x i8] c"XDG_CONFIG_HOME\00"
@getIniFilePath.iniPath = internal global [128 x i8] zeroinitializer
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [2 x i8] c"~\00"
@.str.6 = [9 x i8] c"%s/%s/%s\00"
@.str.7 = [8 x i8] c".config\00"
define i8* @getIniFilePath() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i64 @fileExists(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %1
br label %26
8: ; preds = %0
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8** %2
%9 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i8*, i8** %2
%15 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getIniFilePath.iniPath, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %13, i8* %14)
br label %25
16: ; preds = %8
%17 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %16
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8** %4
br label %21
21: ; preds = %20, %16
%22 = load i8*, i8** %4
%23 = load i8*, i8** %2
%24 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getIniFilePath.iniPath, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %12
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getIniFilePath.iniPath, i64 0, i64 0), i8** %1
br label %26
26: ; preds = %25, %7
%27 = load i8*, i8** %1
ret i8* %27
}

LLVM IR (-O2):
@.str = [7 x i8] c"fs.ini\00"
@.str.1 = [21 x i8] c"faststack/config.ini\00"
@.str.2 = [16 x i8] c"XDG_CONFIG_HOME\00"
@getIniFilePath.iniPath = internal global [128 x i8] zeroinitializer
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [5 x i8] c"HOME\00"
@.str.5 = [2 x i8] c"~\00"
@.str.6 = [9 x i8] c"%s/%s/%s\00"
@.str.7 = [8 x i8] c".config\00"
define i8* @getIniFilePath() {
%1 = tail call i64 @fileExists(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %13
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getIniFilePath.iniPath, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %13
8: ; preds = %3
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%10 = icmp eq i8* %9, null
%11 = select i1 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %9
%12 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @getIniFilePath.iniPath, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %6, %8, %0
%14 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @getIniFilePath.iniPath, i64 0, i64 0), %8 ], [ getelementptr inbounds ([128 x i8], [128 x i8]* @getIniFilePath.iniPath, i64 0, i64 0), %6 ]
ret i8* %14
}