#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 stat {
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
char *calloc(scalar_t__, int);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int stat(char *, struct stat *);
scalar_t__ strlen(char *);
char *get_config_file(void) {
  struct stat config_dir_stat = {0};
  int result;
  char *env_config_dir;
  char *config_dir;
  char *config_file = NULL;
  env_config_dir = getenv("XDG_CONFIG_HOME");
  if (!env_config_dir || *env_config_dir == '\0') {
    env_config_dir = getenv("HOME");
    config_dir =
        calloc(strlen(env_config_dir) + strlen("/.config/xautoclick") + 1,
               sizeof(char));
    sprintf(config_dir, "%s/.config/xautoclick", env_config_dir);
  } else {
    config_dir = calloc(strlen(env_config_dir) + strlen("/xautoclick") + 1,
                        sizeof(char));
    sprintf(config_dir, "%s/xautoclick", env_config_dir);
  }
  result = stat(config_dir, &config_dir_stat);
  if (result == -1) {
    mkdir(config_dir, 0700);
  }
  config_file =
      calloc(strlen(config_dir) + strlen("/config") + 1, sizeof(char));
  sprintf(config_file, "%s/config", config_dir);
  free(config_dir);
  return config_file;
}


x86 assembly (clang, -O0):
<get_config_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
movq   $0x0,-0x28(%rbp)
lea    0xe59(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11cb <get_config_file+0x4b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1226 <get_config_file+0xa6>
lea    0xe39(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe23(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdf4(%rip),%rsi
call   10a0 <sprintf@plt>
jmp    126c <get_config_file+0xec>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x38(%rbp)
lea    0xde0(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdbf(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1294 <get_config_file+0x114>
mov    -0x20(%rbp),%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x40(%rbp)
lea    0xd8e(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xd5f(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_config_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
lea    0xe78(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11bc <get_config_file+0x4c>
mov    %rax,%r14
cmpb   $0x0,(%rax)
je     11bc <get_config_file+0x4c>
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0xc(%rax),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
lea    0xe6c(%rip),%rsi
jmp    11eb <get_config_file+0x7b>
lea    0xe48(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1060 <strlen@plt>
lea    0x14(%rax),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
lea    0xe25(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1090 <sprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    1215 <get_config_file+0xa5>
mov    %r15,%rdi
mov    $0x1c0,%esi
call   1050 <mkdir@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x8(%rax),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
lea    0xdff(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1090 <sprintf@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [20 x i8] c"/.config/xautoclick\00"
@.str.3 = [22 x i8] c"%s/.config/xautoclick\00"
@.str.4 = [12 x i8] c"/xautoclick\00"
@.str.5 = [14 x i8] c"%s/xautoclick\00"
@.str.6 = [8 x i8] c"/config\00"
@.str.7 = [10 x i8] c"%s/config\00"
define i8* @get_config_file() {
%1 = alloca %struct.stat
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = bitcast %struct.stat* %1 to i8*
store i8* null, i8** %5
%7 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %10, %0
%16 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %3
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* %17)
%19 = call i64 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%20 = add nsw i64 %18, %19
%21 = add nsw i64 %20, 1
%22 = call i8* @calloc(i64 %21, i32 1)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = load i8*, i8** %3
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %36
26: ; preds = %10
%27 = load i8*, i8** %3
%28 = call i64 @strlen(i8* %27)
%29 = call i64 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%30 = add nsw i64 %28, %29
%31 = add nsw i64 %30, 1
%32 = call i8* @calloc(i64 %31, i32 1)
store i8* %32, i8** %4
%33 = load i8*, i8** %4
%34 = load i8*, i8** %3
%35 = call i32 @sprintf(i8* %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %26, %15
%37 = load i8*, i8** %4
%38 = call i32 @stat(i8* %37, %struct.stat* %1)
store i32 %38, i32* %2
%39 = load i32, i32* %2
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i8*, i8** %4
%43 = call i32 @mkdir(i8* %42, i32 448)
br label %44
44: ; preds = %41, %36
%45 = load i8*, i8** %4
%46 = call i64 @strlen(i8* %45)
%47 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%48 = add nsw i64 %46, %47
%49 = add nsw i64 %48, 1
%50 = call i8* @calloc(i64 %49, i32 1)
store i8* %50, i8** %5
%51 = load i8*, i8** %5
%52 = load i8*, i8** %4
%53 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %52)
%54 = load i8*, i8** %4
%55 = call i32 @free(i8* %54)
%56 = load i8*, i8** %5
ret i8* %56
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.3 = [22 x i8] c"%s/.config/xautoclick\00"
@.str.5 = [14 x i8] c"%s/xautoclick\00"
@.str.7 = [10 x i8] c"%s/config\00"
define i8* @get_config_file() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
store i32 0, i32* %3
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %6, %0
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = add nsw i64 %11, 20
%13 = tail call i8* @calloc(i64 %12, i32 1)
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %10)
br label %20
15: ; preds = %6
%16 = tail call i64 @strlen(i8* %4)
%17 = add nsw i64 %16, 12
%18 = tail call i8* @calloc(i64 %17, i32 1)
%19 = tail call i32 @sprintf(i8* dereferenceable(1) %18, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %20
20: ; preds = %15, %9
%21 = phi i8* [ %13, %9 ], [ %18, %15 ]
%22 = call i32 @stat(i8* %21, %struct.stat* %1)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @mkdir(i8* %21, i32 448)
br label %26
26: ; preds = %24, %20
%27 = tail call i64 @strlen(i8* dereferenceable(1) %21)
%28 = add nsw i64 %27, 8
%29 = tail call i8* @calloc(i64 %28, i32 1)
%30 = tail call i32 @sprintf(i8* dereferenceable(1) %29, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %21)
%31 = tail call i32 @free(i8* %21)
ret i8* %29
}