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

/* Variables and functions */
int /*<<< orphan*/ R_OK;
scalar_t__ access(char const *, int /*<<< orphan*/);
char *getenv(char *);
char *malloc(size_t);
int parse_config(char const *);
int /*<<< orphan*/ printf(char *);
scalar_t__ snprintf(char *, size_t, char *, char *, char const *);
int strlen(char const *);
int load_config(const char *name) {
  if (access(name, R_OK) == 0)
    return parse_config(name);
  char *env;
  char *path;
  env = getenv("XDG_CONFIG_HOME");
  if (env) {
    size_t sz = strlen(env) + 1 + strlen("ncnyaa") + 1 + strlen(name) + 1;
    path = malloc(sz);
    if (path && snprintf(path, sz, "%s/ncnyaa/%s", env, name) &&
        access(path, R_OK) == 0)
      return parse_config(path);
  }
  env = getenv("HOME");
  if (env) {
    size_t sz =
        strlen(env) + 1 + strlen(".config/ncnyaa") + 1 + strlen(name) + 1;
    path = malloc(sz);
    if (path && snprintf(path, sz, "%s/.config/ncnyaa/%s", env, name) &&
        access(path, R_OK) == 0)
      return parse_config(path);
  }
  printf("No configuration file found.\n");
  return 0;
}


x86 assembly (clang, -O0):
<load_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0x0,%rax
jne    11a9 <load_config+0x39>
mov    -0x10(%rbp),%rdi
call   1080 <parse_config@plt>
mov    %eax,-0x4(%rbp)
jmp    1354 <load_config+0x1e4>
lea    0xe50(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1275 <load_config+0x105>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
lea    0xe4b(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1270 <load_config+0x100>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xddc(%rip),%rdx
call   1060 <snprintf@plt>
cmp    $0x0,%rax
je     1270 <load_config+0x100>
mov    -0x20(%rbp),%rdi
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0x0,%rax
jne    1270 <load_config+0x100>
mov    -0x20(%rbp),%rdi
call   1080 <parse_config@plt>
mov    %eax,-0x4(%rbp)
jmp    1354 <load_config+0x1e4>
jmp    1275 <load_config+0x105>
lea    0xd8f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1341 <load_config+0x1d1>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
lea    0xd77(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     133c <load_config+0x1cc>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xd2c(%rip),%rdx
call   1060 <snprintf@plt>
cmp    $0x0,%rax
je     133c <load_config+0x1cc>
mov    -0x20(%rbp),%rdi
mov    0x2cc6(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0x0,%rax
jne    133c <load_config+0x1cc>
mov    -0x20(%rbp),%rdi
call   1080 <parse_config@plt>
mov    %eax,-0x4(%rbp)
jmp    1354 <load_config+0x1e4>
jmp    1341 <load_config+0x1d1>
lea    0xcf9(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_config>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e5b(%rip),%r13
mov    0x0(%r13),%esi
call   1090 <access@plt>
test   %rax,%rax
je     12b4 <load_config+0x144>
lea    0xe62(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1219 <load_config+0xa9>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0xe68(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %r15d,%ebp
add    %ebp,%eax
add    $0x3,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1219 <load_config+0xa9>
mov    %rax,%r15
lea    0xe22(%rip),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
test   %rax,%rax
je     1219 <load_config+0xa9>
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1090 <access@plt>
test   %rax,%rax
je     12b9 <load_config+0x149>
lea    0xdeb(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1297 <load_config+0x127>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0xdde(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %r15d,%ebp
add    %ebp,%eax
add    $0x3,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1297 <load_config+0x127>
mov    %rax,%r15
lea    0xdbc(%rip),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
test   %rax,%rax
je     1297 <load_config+0x127>
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1090 <access@plt>
test   %rax,%rax
je     12b9 <load_config+0x149>
lea    0xda3(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
jmp    12bc <load_config+0x14c>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <parse_config@plt>

LLVM IR (-O0):
@R_OK = global i32 0
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [7 x i8] c"ncnyaa\00"
@.str.2 = [13 x i8] c"%s/ncnyaa/%s\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [15 x i8] c".config/ncnyaa\00"
@.str.5 = [21 x i8] c"%s/.config/ncnyaa/%s\00"
@.str.6 = [30 x i8] c"No configuration file found.\0A\00"
define i32 @load_config(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = load i32, i32* @R_OK
%10 = call i64 @access(i8* %8, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @parse_config(i8* %13)
store i32 %14, i32* %2
br label %89
15: ; preds = %1
%16 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %51
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 1
%23 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%24 = add nsw i32 %22, %23
%25 = add nsw i32 %24, 1
%26 = load i8*, i8** %3
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %25, %27
%29 = add nsw i32 %28, 1
%30 = sext i32 %29 to i64
store i64 %30, i64* %6
%31 = load i64, i64* %6
%32 = call i8* @malloc(i64 %31)
store i8* %32, i8** %5
%33 = load i8*, i8** %5
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %50
35: ; preds = %19
%36 = load i8*, i8** %5
%37 = load i64, i64* %6
%38 = load i8*, i8** %4
%39 = load i8*, i8** %3
%40 = call i64 @snprintf(i8* %36, i64 %37, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %35
%43 = load i8*, i8** %5
%44 = load i32, i32* @R_OK
%45 = call i64 @access(i8* %43, i32 %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i8*, i8** %5
%49 = call i32 @parse_config(i8* %48)
store i32 %49, i32* %2
br label %89
50: ; preds = %42, %35, %19
br label %51
51: ; preds = %50, %15
%52 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %52, i8** %4
%53 = load i8*, i8** %4
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %87
55: ; preds = %51
%56 = load i8*, i8** %4
%57 = call i32 @strlen(i8* %56)
%58 = add nsw i32 %57, 1
%59 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%60 = add nsw i32 %58, %59
%61 = add nsw i32 %60, 1
%62 = load i8*, i8** %3
%63 = call i32 @strlen(i8* %62)
%64 = add nsw i32 %61, %63
%65 = add nsw i32 %64, 1
%66 = sext i32 %65 to i64
store i64 %66, i64* %7
%67 = load i64, i64* %7
%68 = call i8* @malloc(i64 %67)
store i8* %68, i8** %5
%69 = load i8*, i8** %5
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %86
71: ; preds = %55
%72 = load i8*, i8** %5
%73 = load i64, i64* %7
%74 = load i8*, i8** %4
%75 = load i8*, i8** %3
%76 = call i64 @snprintf(i8* %72, i64 %73, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %74, i8* %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %86
78: ; preds = %71
%79 = load i8*, i8** %5
%80 = load i32, i32* @R_OK
%81 = call i64 @access(i8* %79, i32 %80)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = load i8*, i8** %5
%85 = call i32 @parse_config(i8* %84)
store i32 %85, i32* %2
br label %89
86: ; preds = %78, %71, %55
br label %87
87: ; preds = %86, %51
%88 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %2
br label %89
89: ; preds = %87, %83, %47, %12
%90 = load i32, i32* %2
ret i32 %90
}

LLVM IR (-O2):
@R_OK = global i32 0
@.str = [16 x i8] c"XDG_CONFIG_HOME\00"
@.str.1 = [7 x i8] c"ncnyaa\00"
@.str.2 = [13 x i8] c"%s/ncnyaa/%s\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [15 x i8] c".config/ncnyaa\00"
@.str.5 = [21 x i8] c"%s/.config/ncnyaa/%s\00"
@str = [29 x i8] c"No configuration file found.\00"
define i32 @load_config(i8* %0) {
%2 = load i32, i32* @R_OK
%3 = tail call i64 @access(i8* %0, i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @parse_config(i8* %0)
br label %53
7: ; preds = %1
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %29, label %10
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %8)
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @strlen(i8* %0)
%14 = add i32 %11, 3
%15 = add i32 %14, %12
%16 = add i32 %15, %13
%17 = sext i32 %16 to i64
%18 = tail call i8* @malloc(i64 %17)
%19 = icmp eq i8* %18, null
br i1 %19, label %29, label %20
20: ; preds = %10
%21 = tail call i64 @snprintf(i8* %18, i64 %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = load i32, i32* @R_OK
%25 = tail call i64 @access(i8* %18, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = tail call i32 @parse_config(i8* %18)
br label %53
29: ; preds = %10, %20, %23, %7
%30 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i8* %30, null
br i1 %31, label %51, label %32
32: ; preds = %29
%33 = tail call i32 @strlen(i8* %30)
%34 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%35 = tail call i32 @strlen(i8* %0)
%36 = add i32 %33, 3
%37 = add i32 %36, %34
%38 = add i32 %37, %35
%39 = sext i32 %38 to i64
%40 = tail call i8* @malloc(i64 %39)
%41 = icmp eq i8* %40, null
br i1 %41, label %51, label %42
42: ; preds = %32
%43 = tail call i64 @snprintf(i8* %40, i64 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i8* %30, i8* %0)
%44 = icmp eq i64 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %42
%46 = load i32, i32* @R_OK
%47 = tail call i64 @access(i8* %40, i32 %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = tail call i32 @parse_config(i8* %40)
br label %53
51: ; preds = %32, %42, %45, %29
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %53
53: ; preds = %49, %27, %51, %5
%54 = phi i32 [ %6, %5 ], [ 0, %51 ], [ %50, %49 ], [ %28, %27 ]
ret i32 %54
}