#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*/ conf;

/* Variables and functions */
int /*<<< orphan*/ F_OK;
int PATH_MAX;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
char *getenv(char *);
int snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
char *config_file(void) {
  char *xdg_home, *home;
  char conf[PATH_MAX];
  int ret;
  xdg_home = getenv("XDG_CONFIG_HOME");
  if (xdg_home && *xdg_home) {
    ret = snprintf(conf, sizeof(conf), "%s/dfc/dfcrc", xdg_home);
    if (ret < 0)
      return NULL;
    if ((size_t)ret >= sizeof(conf))
      goto trunc_err;
    if (access(conf, F_OK) == 0)
      return strdup(conf);
  }
  home = getenv("HOME");
  if (home && *home) {
    ret = snprintf(conf, sizeof(conf), "%s/.config/dfc/dfcrc", home);
    if (ret < 0)
      return NULL;
    if ((size_t)ret >= sizeof(conf))
      goto trunc_err;
    if (access(conf, F_OK) == 0)
      return strdup(conf);
    ret = snprintf(conf, sizeof(conf), "%s/.dfcrc", home);
    if (ret < 0)
      return NULL;
    if ((size_t)ret >= sizeof(conf))
      goto trunc_err;
    if (access(conf, F_OK) == 0)
      return strdup(conf);
  }
  return NULL;
trunc_err:
  (void)fprintf(stderr,
                "Config file path is longer than %lu and was truncated. "
                "Please, open a bug report.\n",
                sizeof(conf));
  return NULL;
}


x86 assembly (clang, -O0):
<config_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe71(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     123e <config_file+0xee>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     123e <config_file+0xee>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
lea    0xe48(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11ee <config_file+0x9e>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    13b8 <config_file+0x268>
mov    -0x40(%rbp),%rcx
movslq -0x2c(%rbp),%rax
cmp    %rcx,%rax
jb     1204 <config_file+0xb4>
jmp    138e <config_file+0x23e>
mov    -0x38(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    1239 <config_file+0xe9>
mov    -0x38(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    13b8 <config_file+0x268>
jmp    123e <config_file+0xee>
lea    0xdc6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     137a <config_file+0x22a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     137a <config_file+0x22a>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
lea    0xd9f(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    12a4 <config_file+0x154>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    13b8 <config_file+0x268>
mov    -0x40(%rbp),%rcx
movslq -0x2c(%rbp),%rax
cmp    %rcx,%rax
jb     12ba <config_file+0x16a>
jmp    138e <config_file+0x23e>
mov    -0x38(%rbp),%rdi
mov    0x2d03(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    12ef <config_file+0x19f>
mov    -0x38(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    13b8 <config_file+0x268>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rcx
lea    0xd2e(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    132a <config_file+0x1da>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    13b8 <config_file+0x268>
mov    -0x40(%rbp),%rcx
movslq -0x2c(%rbp),%rax
cmp    %rcx,%rax
jb     1340 <config_file+0x1f0>
jmp    138e <config_file+0x23e>
mov    -0x38(%rbp),%rdi
mov    0x2c7d(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jne    1375 <config_file+0x225>
mov    -0x38(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    13b8 <config_file+0x268>
jmp    137a <config_file+0x22a>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    13b8 <config_file+0x268>
mov    -0x40(%rbp),%rax
mov    0x2c3f(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,%edx
lea    0xc98(%rip),%rsi
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e8e(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe80(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11cf <config_file+0x7f>
cmpb   $0x0,(%rax)
je     11cf <config_file+0x7f>
lea    0xe7a(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
call   1040 <snprintf@plt>
test   %eax,%eax
js     1277 <config_file+0x127>
cmp    %r14d,%eax
jae    125f <config_file+0x10f>
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <access@plt>
test   %rax,%rax
je     1255 <config_file+0x105>
lea    0xe35(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1277 <config_file+0x127>
mov    %rax,%r15
cmpb   $0x0,(%rax)
je     1277 <config_file+0x127>
lea    0xe26(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rcx
call   1040 <snprintf@plt>
test   %eax,%eax
js     1277 <config_file+0x127>
cmp    %r14d,%eax
jae    125f <config_file+0x10f>
mov    0x2db3(%rip),%r12
mov    (%r12),%esi
mov    %rbx,%rdi
call   1060 <access@plt>
test   %rax,%rax
je     1255 <config_file+0x105>
lea    0xe05(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rcx
call   1040 <snprintf@plt>
test   %eax,%eax
js     1277 <config_file+0x127>
cmp    %r14d,%eax
jae    125f <config_file+0x10f>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1060 <access@plt>
test   %rax,%rax
jne    1277 <config_file+0x127>
mov    %rbx,%rdi
call   1070 <strdup@plt>
jmp    1279 <config_file+0x129>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    %r14d,%edx
call   1050 <fprintf@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [13 x i8] c"%s/dfc/dfcrc\00"
@F_OK = global i32 0
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [21 x i8] c"%s/.config/dfc/dfcrc\00"
@.str.4 = [10 x i8] c"%s/.dfcrc\00"
@stderr = global i32 0
@.str.5 = [83 x i8] c"Config file path is longer than %lu and was truncated. Please, open a bug report.\0A\00"
define i8* @config_file() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i8, i64 %9
store i64 %9, i64* %5
%12 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %2
%13 = load i8*, i8** %2
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %39
15: ; preds = %0
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %39
20: ; preds = %15
%21 = trunc i64 %9 to i32
%22 = load i8*, i8** %2
%23 = call i32 @snprintf(i8* %11, i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i8* null, i8** %1
store i32 1, i32* %7
br label %90
27: ; preds = %20
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = icmp uge i64 %29, %9
br i1 %30, label %31, label %32
31: ; preds = %27
br label %86
32: ; preds = %27
%33 = load i32, i32* @F_OK
%34 = call i64 @access(i8* %11, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i8* @strdup(i8* %11)
store i8* %37, i8** %1
store i32 1, i32* %7
br label %90
38: ; preds = %32
br label %39
39: ; preds = %38, %15, %0
%40 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %40, i8** %3
%41 = load i8*, i8** %3
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %85
43: ; preds = %39
%44 = load i8*, i8** %3
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %85
48: ; preds = %43
%49 = trunc i64 %9 to i32
%50 = load i8*, i8** %3
%51 = call i32 @snprintf(i8* %11, i32 %49, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %50)
store i32 %51, i32* %6
%52 = load i32, i32* %6
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %48
store i8* null, i8** %1
store i32 1, i32* %7
br label %90
55: ; preds = %48
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = icmp uge i64 %57, %9
br i1 %58, label %59, label %60
59: ; preds = %55
br label %86
60: ; preds = %55
%61 = load i32, i32* @F_OK
%62 = call i64 @access(i8* %11, i32 %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i8* @strdup(i8* %11)
store i8* %65, i8** %1
store i32 1, i32* %7
br label %90
66: ; preds = %60
%67 = trunc i64 %9 to i32
%68 = load i8*, i8** %3
%69 = call i32 @snprintf(i8* %11, i32 %67, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %68)
store i32 %69, i32* %6
%70 = load i32, i32* %6
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %66
store i8* null, i8** %1
store i32 1, i32* %7
br label %90
73: ; preds = %66
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = icmp uge i64 %75, %9
br i1 %76, label %77, label %78
77: ; preds = %73
br label %86
78: ; preds = %73
%79 = load i32, i32* @F_OK
%80 = call i64 @access(i8* %11, i32 %79)
%81 = icmp eq i64 %80, 0
br i1 %81, label %82, label %84
82: ; preds = %78
%83 = call i8* @strdup(i8* %11)
store i8* %83, i8** %1
store i32 1, i32* %7
br label %90
84: ; preds = %78
br label %85
85: ; preds = %84, %43, %39
store i8* null, i8** %1
store i32 1, i32* %7
br label %90
86: ; preds = %77, %59, %31
%87 = load i32, i32* @stderr
%88 = trunc i64 %9 to i32
%89 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.5, i64 0, i64 0), i32 %88)
store i8* null, i8** %1
store i32 1, i32* %7
br label %90
90: ; preds = %86, %85, %82, %72, %64, %54, %36, %26
%91 = load i8*, i8** %4
%92 = load i8*, i8** %1
ret i8* %92
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [13 x i8] c"%s/dfc/dfcrc\00"
@F_OK = global i32 0
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [21 x i8] c"%s/.config/dfc/dfcrc\00"
@.str.4 = [10 x i8] c"%s/.dfcrc\00"
@stderr = global i32 0
@.str.5 = [83 x i8] c"Config file path is longer than %lu and was truncated. Please, open a bug report.\0A\00"
define noalias i8* @config_file() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%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 %20, label %6
6: ; preds = %0
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %6
%10 = call i32 @snprintf(i8* %3, i32 %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%11 = icmp slt i32 %10, 0
br i1 %11, label %51, label %12
12: ; preds = %9
%13 = icmp ult i32 %10, %1
br i1 %13, label %14, label %48
14: ; preds = %12
%15 = load i32, i32* @F_OK
%16 = call i64 @access(i8* %3, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i8* @strdup(i8* %3)
br label %51
20: ; preds = %14, %6, %0
%21 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %51, label %23
23: ; preds = %20
%24 = load i8, i8* %21
%25 = icmp eq i8 %24, 0
br i1 %25, label %51, label %26
26: ; preds = %23
%27 = call i32 @snprintf(i8* %3, i32 %1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%28 = icmp slt i32 %27, 0
br i1 %28, label %51, label %29
29: ; preds = %26
%30 = icmp ult i32 %27, %1
br i1 %30, label %31, label %48
31: ; preds = %29
%32 = load i32, i32* @F_OK
%33 = call i64 @access(i8* %3, i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i8* @strdup(i8* %3)
br label %51
37: ; preds = %31
%38 = call i32 @snprintf(i8* %3, i32 %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%39 = icmp slt i32 %38, 0
br i1 %39, label %51, label %40
40: ; preds = %37
%41 = icmp ult i32 %38, %1
br i1 %41, label %42, label %48
42: ; preds = %40
%43 = load i32, i32* @F_OK
%44 = call i64 @access(i8* %3, i32 %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = call i8* @strdup(i8* %3)
br label %51
48: ; preds = %40, %29, %12
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.5, i64 0, i64 0), i32 %1)
br label %51
51: ; preds = %20, %23, %42, %37, %26, %9, %48, %46, %35, %18
%52 = phi i8* [ null, %48 ], [ %19, %18 ], [ %36, %35 ], [ %47, %46 ], [ null, %9 ], [ null, %26 ], [ null, %37 ], [ null, %42 ], [ null, %23 ], [ null, %20 ]
ret i8* %52
}