#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 int32_t;

/* Variables and functions */
char *calloc(int, int);
int snepulator_directory(char **);
int snprintf(char *, int, char *, char *);
int32_t config_path(char **path_ptr) {
  static char *path = NULL;
  if (path == NULL) {
    char *dir;
    int len;
    if (snepulator_directory(&dir) == -1) {
      return -1;
    }
    len = snprintf(NULL, 0, "%s/snepulator.cfg", dir) + 1;
    path = calloc(len, 1);
    snprintf(path, len, "%s/snepulator.cfg", dir);
  }
  *path_ptr = path;
  return 0;
}


x86 assembly (clang, -O0):
<config_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,0x2efc(%rip)
jne    11b2 <config_path+0x82>
lea    -0x18(%rbp),%rdi
call   1030 <snepulator_directory@plt>
cmp    $0xffffffff,%eax
jne    1168 <config_path+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c7 <config_path+0x97>
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xe87(%rip),%rdx
call   1040 <snprintf@plt>
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,0x2ea8(%rip)
mov    0x2ea1(%rip),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xe53(%rip),%rdx
call   1040 <snprintf@plt>
mov    0x2e87(%rip),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_path>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2efe(%rip),%rax
test   %rax,%rax
jne    119d <config_path+0x6d>
lea    0x8(%rsp),%rdi
call   1030 <snepulator_directory@plt>
cmp    $0xffffffff,%eax
je     11ab <config_path+0x7b>
mov    0x8(%rsp),%rcx
lea    0xe9e(%rip),%r14
xor    %edi,%edi
xor    %esi,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
lea    0x1(%rax),%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,0x2ebc(%rip)
mov    0x8(%rsp),%rcx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1040 <snprintf@plt>
mov    0x2ea3(%rip),%rax
mov    %rax,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xffffffff,%eax
jmp    11a2 <config_path+0x72>

LLVM IR (-O0):
@config_path.path = internal global i8* null
@.str = [18 x i8] c"%s/snepulator.cfg\00"
define i32 @config_path(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
store i8** %0, i8*** %3
%6 = load i8*, i8** @config_path.path
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = call i32 @snepulator_directory(i8** %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 -1, i32* %2
br label %25
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = call i8* @calloc(i32 %16, i32 1)
store i8* %17, i8** @config_path.path
%18 = load i8*, i8** @config_path.path
%19 = load i32, i32* %5
%20 = load i8*, i8** %4
%21 = call i32 @snprintf(i8* %18, i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %12, %1
%23 = load i8*, i8** @config_path.path
%24 = load i8**, i8*** %3
store i8* %23, i8** %24
store i32 0, i32* %2
br label %25
25: ; preds = %22, %11
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@config_path.path = internal unnamed_addr global i8* null
@.str = [18 x i8] c"%s/snepulator.cfg\00"
define i32 @config_path(i8** nocapture writeonly %0) {
%2 = alloca i8*
%3 = load i8*, i8** @config_path.path
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = bitcast i8** %2 to i8*
%7 = call i32 @snepulator_directory(i8** %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = call i32 @snprintf(i8* null, i32 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = add nsw i32 %11, 1
%13 = call i8* @calloc(i32 %12, i32 1)
store i8* %13, i8** @config_path.path
%14 = load i8*, i8** %2
%15 = call i32 @snprintf(i8* %13, i32 %12, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** @config_path.path
br label %18
17: ; preds = %5
br label %20
18: ; preds = %9, %1
%19 = phi i8* [ %16, %9 ], [ %3, %1 ]
store i8* %19, i8** %0
br label %20
20: ; preds = %17, %18
%21 = phi i32 [ -1, %17 ], [ 0, %18 ]
ret i32 %21
}