#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *get_yanglint_dir();
scalar_t__ linenoiseHistorySave(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *);
void store_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 (linenoiseHistorySave(history_file)) {
    fprintf(stderr, "Failed to save history.\n");
  }
  free(history_file);
  free(yl_dir);
}


x86 assembly (clang, -O0):
<store_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    11a2 <store_config+0x22>
jmp    1252 <store_config+0xd2>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x9,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1202 <store_config+0x82>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    1252 <store_config+0xd2>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe0f(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <linenoiseHistorySave@plt>
cmp    $0x0,%rax
je     1240 <store_config+0xc0>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
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):
<store_config>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <get_yanglint_dir@plt>
test   %rax,%rax
je     11ec <store_config+0x6c>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x9(%rax),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11f4 <store_config+0x74>
mov    %rax,%rbx
lea    0xe6d(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1080 <linenoiseHistorySave@plt>
test   %rax,%rax
je     11e2 <store_config+0x62>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    121e <store_config+0x9e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2de5(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdee(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <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 i32 0
@.str.1 = [11 x i8] c"%s/history\00"
@.str.2 = [25 x i8] c"Failed to save history.\0A\00"
define void @store_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 %35
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 i32, i32* @errno
%16 = call i8* @strerror(i32 %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 %35
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 = call i64 @linenoiseHistorySave(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %27, %20
%31 = load i8*, i8** %2
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %1
%34 = call i32 @free(i8* %33)
br label %35
35: ; preds = %30, %13, %5
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"Memory allocation failed (%s).\0A\00"
@errno = global i32 0
@.str.1 = [11 x i8] c"%s/history\00"
@.str.2 = [25 x i8] c"Failed to save history.\0A\00"
define void @store_config() {
%1 = tail call i8* (...) @get_yanglint_dir()
%2 = icmp eq i8* %1, null
br i1 %2, label %24, 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 i32, i32* @errno
%11 = tail call i8* @strerror(i32 %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 %22
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 = tail call i64 @linenoiseHistorySave(i8* %6)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %17, %13
%21 = tail call i32 @free(i8* %6)
br label %22
22: ; preds = %8, %20
%23 = tail call i32 @free(i8* %1)
br label %24
24: ; preds = %22, %0
ret void
}