#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char *getenv(char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
char *strcat(char *, char *);
char *getconf(void) {
  struct stat buf;
  char *home;
  char *xdg_c_h;
  char *conf;
  if ((xdg_c_h = getenv("XDG_CONFIG_HOME")) != NULL) {
    if ((conf = strcat(xdg_c_h, "/dfc/dfcrc")) == NULL) {
      (void)fputs("strcat failed while guessing "
                  "configuration file\n",
                  stderr);
      return NULL;
    }
    if (stat(conf, &buf) == 0)
      return conf;
    else
      return NULL;
  } else {
    if ((home = getenv("HOME")) != NULL) {
      if ((conf = strcat(home, "/.config/dfc/dfcrc")) == NULL) {
        (void)fputs("strcat failed while guessing "
                    "configuration file location\n",
                    stderr);
        return NULL;
      }
      if (stat(conf, &buf) == 0)
        return conf;
      else {
        if ((home = getenv("HOME")) == NULL)
          return NULL;
        if ((conf = strcat(home, "/.dfcrc")) == NULL) {
          (void)fputs("strcat failed while guessing"
                      " configuration file\n",
                      stderr);
          return NULL;
        }
        if (stat(conf, &buf) == 0)
          return conf;
        else
          return NULL;
      }
    } else
      return NULL;
  }
}


x86 assembly (clang, -O0):
<getconf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11d3 <getconf+0x93>
mov    -0x20(%rbp),%rdi
lea    0xedc(%rip),%rsi
call   1060 <strcat@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11a2 <getconf+0x62>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
call   1040 <fputs@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f1 <getconf+0x1b1>
mov    -0x28(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    11c6 <getconf+0x86>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12f1 <getconf+0x1b1>
movq   $0x0,-0x8(%rbp)
jmp    12f1 <getconf+0x1b1>
lea    0xe31(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12e9 <getconf+0x1a9>
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1060 <strcat@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    122d <getconf+0xed>
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
lea    0xe39(%rip),%rdi
call   1040 <fputs@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f1 <getconf+0x1b1>
mov    -0x28(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    1251 <getconf+0x111>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12f1 <getconf+0x1b1>
lea    0xdb3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1278 <getconf+0x138>
movq   $0x0,-0x8(%rbp)
jmp    12f1 <getconf+0x1b1>
mov    -0x18(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1060 <strcat@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12b8 <getconf+0x178>
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
lea    0xd6a(%rip),%rdi
call   1040 <fputs@plt>
movq   $0x0,-0x8(%rbp)
jmp    12f1 <getconf+0x1b1>
mov    -0x28(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jne    12dc <getconf+0x19c>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12f1 <getconf+0x1b1>
movq   $0x0,-0x8(%rbp)
jmp    12f1 <getconf+0x1b1>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getconf>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117d <getconf+0x4d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
movabs $0x6366642f6366642f,%rcx
64 66 63
mov    %rcx,(%rbx,%rax,1)
movl   $0x637263,0x7(%rbx,%rax,1)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
xor    %r14d,%r14d
test   %rax,%rax
cmove  %rbx,%r14
jmp    11f0 <getconf+0xc0>
lea    0xe87(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ed <getconf+0xbd>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
movups 0xe70(%rip),%xmm0
movups %xmm0,(%r14,%rax,1)
movl   $0x637263,0xf(%r14,%rax,1)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1050 <stat@plt>
test   %rax,%rax
je     11f0 <getconf+0xc0>
lea    0xe46(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ed <getconf+0xbd>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
movabs $0x63726366642e2f,%rcx
mov    %rcx,(%rbx,%rax,1)
jmp    1166 <getconf+0x36>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [11 x i8] c"/dfc/dfcrc\00"
@.str.2 = [49 x i8] c"strcat failed while guessing configuration file\0A\00"
@stderr = global i32 0
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [19 x i8] c"/.config/dfc/dfcrc\00"
@.str.5 = [58 x i8] c"strcat failed while guessing configuration file location\0A\00"
@.str.6 = [8 x i8] c"/.dfcrc\00"
define i8* @getconf() {
%1 = alloca i8*
%2 = alloca %struct.stat
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %22
8: ; preds = %0
%9 = load i8*, i8** %4
%10 = call i8* @strcat(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %13)
store i8* null, i8** %1
br label %57
15: ; preds = %8
%16 = load i8*, i8** %5
%17 = call i64 @stat(i8* %16, %struct.stat* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i8*, i8** %5
store i8* %20, i8** %1
br label %57
21: ; preds = %15
store i8* null, i8** %1
br label %57
22: ; preds = %0
%23 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %23, i8** %3
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %56
25: ; preds = %22
%26 = load i8*, i8** %3
%27 = call i8* @strcat(i8* %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i8* %27, i8** %5
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 @fputs(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.5, i64 0, i64 0), i32 %30)
store i8* null, i8** %1
br label %57
32: ; preds = %25
%33 = load i8*, i8** %5
%34 = call i64 @stat(i8* %33, %struct.stat* %2)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load i8*, i8** %5
store i8* %37, i8** %1
br label %57
38: ; preds = %32
%39 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %39, i8** %3
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %42
41: ; preds = %38
store i8* null, i8** %1
br label %57
42: ; preds = %38
%43 = load i8*, i8** %3
%44 = call i8* @strcat(i8* %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i8* %44, i8** %5
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = call i32 @fputs(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0), i32 %47)
store i8* null, i8** %1
br label %57
49: ; preds = %42
%50 = load i8*, i8** %5
%51 = call i64 @stat(i8* %50, %struct.stat* %2)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = load i8*, i8** %5
store i8* %54, i8** %1
br label %57
55: ; preds = %49
store i8* null, i8** %1
br label %57
56: ; preds = %22
store i8* null, i8** %1
br label %57
57: ; preds = %56, %55, %53, %46, %41, %36, %29, %21, %19, %12
%58 = load i8*, i8** %1
ret i8* %58
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [11 x i8] c"/dfc/dfcrc\00"
@stderr = global i32 0
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [19 x i8] c"/.config/dfc/dfcrc\00"
define i8* @getconf() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = tail call i64 @strlen(i8* %3)
%7 = getelementptr i8, i8* %3, i64 %6
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(11) %7, i8* align 1 dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 11, i1 false)
br label %23
8: ; preds = %0
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %28, label %11
11: ; preds = %8
%12 = tail call i64 @strlen(i8* %9)
%13 = getelementptr i8, i8* %9, i64 %12
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(19) %13, i8* align 1 dereferenceable(19) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 19, i1 false)
%14 = call i64 @stat(i8* %9, %struct.stat* %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %28, label %16
16: ; preds = %11
%17 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %28, label %19
19: ; preds = %16
%20 = call i64 @strlen(i8* %17)
%21 = getelementptr i8, i8* %17, i64 %20
%22 = bitcast i8* %21 to i64*
store i64 27991793939525167, i64* %22
br label %23
23: ; preds = %5, %19
%24 = phi i8* [ %17, %19 ], [ %3, %5 ]
%25 = call i64 @stat(i8* %24, %struct.stat* %1)
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i8* %24, i8* null
br label %28
28: ; preds = %23, %8, %16, %11
%29 = phi i8* [ %9, %11 ], [ null, %16 ], [ null, %8 ], [ %27, %23 ]
ret i8* %29
}