#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__ asprintf(char **, char const *, char *, char *);
int /*<<< orphan*/ err(int, char *);
char *getenv(char *);
size_t strlen(char *);
char *get_history_filename(void) {
  char *filename;
  char *homedir;
  const char *format;
  if (!(homedir = getenv("HOME")))
    err(1, "$HOME is not defined");
  format = homedir[strlen(homedir)] == '/' ? "%s%s" : "%s/%s";
  if (asprintf(&filename, format, homedir, ".umenu_history2") < 0)
    err(1, NULL);
  return filename;
}


x86 assembly (clang, -O0):
<get_history_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1173 <get_history_filename+0x33>
mov    $0x1,%edi
lea    0xe97(%rip),%rsi
call   1050 <err@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
movsbl (%rax,%rcx,1),%edx
lea    0xe89(%rip),%rax
lea    0xe7d(%rip),%rcx
cmp    $0x2f,%edx
cmove  %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x8(%rbp),%rdi
lea    0xe6a(%rip),%rcx
call   1060 <asprintf@plt>
cmp    $0x0,%rax
jge    11d8 <get_history_filename+0x98>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <err@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_history_filename>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116a <get_history_filename+0x2a>
lea    0xea5(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmpb   $0x2f,(%rbx,%rax,1)
lea    0xe9d(%rip),%rax
lea    0xe9b(%rip),%rsi
cmove  %rax,%rsi
lea    0xe96(%rip),%rcx
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
call   1060 <asprintf@plt>
test   %rax,%rax
jns    11ad <get_history_filename+0x6d>
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <err@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [21 x i8] c"$HOME is not defined\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [16 x i8] c".umenu_history2\00"
define i8* @get_history_filename() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = load i8*, i8** %2
%10 = load i8*, i8** %2
%11 = call i64 @strlen(i8* %10)
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 47
%16 = zext i1 %15 to i64
%17 = select i1 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = load i8*, i8** %2
%20 = call i64 @asprintf(i8** %1, i8* %18, i8* %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %8
%23 = call i32 @err(i32 1, i8* null)
br label %24
24: ; preds = %22, %8
%25 = load i8*, i8** %1
ret i8* %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [21 x i8] c"$HOME is not defined\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [16 x i8] c".umenu_history2\00"
define i8* @get_history_filename() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%9 = getelementptr inbounds i8, i8* %3, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 47
%12 = select i1 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%13 = call i64 @asprintf(i8** %1, i8* %12, i8* %3, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = call i32 @err(i32 1, i8* null)
br label %17
17: ; preds = %15, %7
%18 = load i8*, i8** %1
ret i8* %18
}