#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 */
scalar_t__ ENOENT;
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *get_yanglint_dir();
scalar_t__ linenoiseHistoryLoad(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(scalar_t__);
scalar_t__ strlen(char *);
void load_config(void) {
  char *yl_dir, *history_file;
  if ((yl_dir = get_yanglint_dir()) == NULL) {
    return;
  }
  history_file = malloc(strlen(yl_dir) + 9);
  if (!history_file) {
    fprintf(stderr, "Memory allocation failed (%s).\n", strerror(errno));
    free(yl_dir);
    return;
  }
  sprintf(history_file, "%s/history", yl_dir);
  if (access(history_file, F_OK) && (errno == ENOENT)) {
    fprintf(stdout, "No saved history.\n");
  } else if (linenoiseHistoryLoad(history_file)) {
    fprintf(stderr, "Failed to load history.\n");
  }
  free(history_file);
  free(yl_dir);
}


x86 assembly (clang, -O0):
<load_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <get_yanglint_dir@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    11b2 <load_config+0x22>
jmp    12ba <load_config+0x12a>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x9,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1213 <load_config+0x83>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    12ba <load_config+0x12a>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdfe(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0x0,%rax
je     1279 <load_config+0xe9>
mov    0x2d8e(%rip),%rax
mov    (%rax),%rax
mov    0x2d6c(%rip),%rcx
cmp    (%rcx),%rax
jne    1279 <load_config+0xe9>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12a8 <load_config+0x118>
mov    -0x10(%rbp),%rdi
call   1060 <linenoiseHistoryLoad@plt>
cmp    $0x0,%rax
je     12a3 <load_config+0x113>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12a8 <load_config+0x118>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_config>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <get_yanglint_dir@plt>
test   %rax,%rax
je     120e <load_config+0x7e>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x9(%rax),%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     1244 <load_config+0xb4>
mov    %rax,%rbx
lea    0xe59(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   10a0 <sprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <access@plt>
test   %rax,%rax
je     1216 <load_config+0x86>
mov    0x2de9(%rip),%rax
mov    (%rax),%rax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%rax
jne    1216 <load_config+0x86>
lea    0xe26(%rip),%rsi
mov    0x2dc4(%rip),%rax
jmp    1231 <load_config+0xa1>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1060 <linenoiseHistoryLoad@plt>
test   %rax,%rax
je     123a <load_config+0xaa>
lea    0xe14(%rip),%rsi
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    126f <load_config+0xdf>
mov    0x2d95(%rip),%rax
mov    (%rax),%ebx
mov    0x2d84(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
lea    0xd9d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"Memory allocation failed (%s).\0A\00"
@errno = global i64 0
@.str.1 = [11 x i8] c"%s/history\00"
@F_OK = global i32 0
@ENOENT = global i64 0
@stdout = global i32 0
@.str.2 = [19 x i8] c"No saved history.\0A\00"
@.str.3 = [25 x i8] c"Failed to load history.\0A\00"
define void @load_config() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* (...) @get_yanglint_dir()
store i8* %3, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %6
5: ; preds = %0
br label %48
6: ; preds = %0
%7 = load i8*, i8** %1
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 9
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = icmp ne i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %6
%14 = load i32, i32* @stderr
%15 = load i64, i64* @errno
%16 = call i8* @strerror(i64 %15)
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %1
%19 = call i32 @free(i8* %18)
br label %48
20: ; preds = %6
%21 = load i8*, i8** %2
%22 = load i8*, i8** %1
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i8*, i8** %2
%25 = load i32, i32* @F_OK
%26 = call i64 @access(i8* %24, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %20
%29 = load i64, i64* @errno
%30 = load i64, i64* @ENOENT
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* @stdout
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %43
35: ; preds = %28, %20
%36 = load i8*, i8** %2
%37 = call i64 @linenoiseHistoryLoad(i8* %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %39, %35
br label %43
43: ; preds = %42, %32
%44 = load i8*, i8** %2
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %1
%47 = call i32 @free(i8* %46)
br label %48
48: ; preds = %43, %13, %5
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Memory allocation failed (%s).\0A\00"
@errno = global i64 0
@.str.1 = [11 x i8] c"%s/history\00"
@F_OK = global i32 0
@ENOENT = global i64 0
@stdout = global i32 0
@.str.2 = [19 x i8] c"No saved history.\0A\00"
@.str.3 = [25 x i8] c"Failed to load history.\0A\00"
define void @load_config() {
%1 = tail call i8* (...) @get_yanglint_dir()
%2 = icmp eq i8* %1, null
br i1 %2, label %34, label %3
3: ; preds = %0
%4 = tail call i64 @strlen(i8* %1)
%5 = add nsw i64 %4, 9
%6 = tail call i8* @malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = load i64, i64* @errno
%11 = tail call i8* @strerror(i64 %10)
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %32
13: ; preds = %3
%14 = tail call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%15 = load i32, i32* @F_OK
%16 = tail call i64 @access(i8* %6, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load i64, i64* @errno
%20 = load i64, i64* @ENOENT
%21 = icmp eq i64 %19, %20
br i1 %21, label %25, label %22
22: ; preds = %18, %13
%23 = tail call i64 @linenoiseHistoryLoad(i8* %6)
%24 = icmp eq i64 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22, %18
%26 = phi i32* [ @stdout, %18 ], [ @stderr, %22 ]
%27 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %18 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), %22 ]
%28 = load i32, i32* %26
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* %27)
br label %30
30: ; preds = %25, %22
%31 = tail call i32 @free(i8* %6)
br label %32
32: ; preds = %8, %30
%33 = tail call i32 @free(i8* %1)
br label %34
34: ; preds = %32, %0
ret void
}