#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__ ecalloc(int, int);
char *lgetenv(char *);
char *save(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char *histfile_name() {
  char *home;
  char *name;
  int len;
  name = lgetenv("LESSHISTFILE");
  if (name != 0 && *name != '\0') {
    if (strcmp(name, "-") == 0 || strcmp(name, "/dev/null") == 0)
      return (0);
    return (save(name));
  }
  home = lgetenv("HOME");
  if (home == 0 || *home == '\0') {
    return (0);
  }
  len = strlen(home) + strlen(".lesshst") + 2;
  name = (char *)ecalloc(len, sizeof(char));
  snprintf((name), (len), ("%s/%s"), (home), (".lesshst"));
  return (name);
}


x86 assembly (clang, -O0):
<histfile_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
call   1080 <lgetenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e6 <histfile_name+0x86>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e6 <histfile_name+0x86>
mov    -0x18(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11c7 <histfile_name+0x67>
mov    -0x18(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11d4 <histfile_name+0x74>
movq   $0x0,-0x8(%rbp)
jmp    127a <histfile_name+0x11a>
mov    -0x18(%rbp),%rdi
call   1060 <save@plt>
mov    %rax,-0x8(%rbp)
jmp    127a <histfile_name+0x11a>
lea    0xe2c(%rip),%rdi
call   1080 <lgetenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1211 <histfile_name+0xb1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    121e <histfile_name+0xbe>
movq   $0x0,-0x8(%rbp)
jmp    127a <histfile_name+0x11a>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
lea    0xded(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1030 <ecalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rcx
lea    0xdc1(%rip),%rdx
lea    0xdb1(%rip),%r8
call   1050 <snprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<histfile_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe92(%rip),%rdi
call   1080 <lgetenv@plt>
test   %rax,%rax
je     11be <histfile_name+0x5e>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11be <histfile_name+0x5e>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     121e <histfile_name+0xbe>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     121e <histfile_name+0xbe>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <save@plt>
lea    0xe54(%rip),%rdi
call   1080 <lgetenv@plt>
test   %rax,%rax
je     121e <histfile_name+0xbe>
mov    %rax,%r14
cmpb   $0x0,(%rax)
je     121e <histfile_name+0xbe>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xe36(%rip),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%ebp
add    $0x2,%ebp
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <ecalloc@plt>
mov    %rax,%rbx
lea    0xe1b(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rcx
mov    %r15,%r8
call   1050 <snprintf@plt>
jmp    1220 <histfile_name+0xc0>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"LESSHISTFILE\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [10 x i8] c"/dev/null\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [9 x i8] c".lesshst\00"
@.str.5 = [6 x i8] c"%s/%s\00"
define i8* @histfile_name() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = call i8* @lgetenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %25
8: ; preds = %0
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17, %13
store i8* null, i8** %1
br label %49
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = call i8* @save(i8* %23)
store i8* %24, i8** %1
br label %49
25: ; preds = %8, %0
%26 = call i8* @lgetenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i8* %26, i8** %2
%27 = load i8*, i8** %2
%28 = icmp eq i8* %27, null
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = load i8*, i8** %2
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29, %25
store i8* null, i8** %1
br label %49
35: ; preds = %29
%36 = load i8*, i8** %2
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%39 = add nsw i32 %37, %38
%40 = add nsw i32 %39, 2
store i32 %40, i32* %4
%41 = load i32, i32* %4
%42 = call i64 @ecalloc(i32 %41, i32 1)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %3
%44 = load i8*, i8** %3
%45 = load i32, i32* %4
%46 = load i8*, i8** %2
%47 = call i32 @snprintf(i8* %44, i32 %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %46, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%48 = load i8*, i8** %3
store i8* %48, i8** %1
br label %49
49: ; preds = %35, %34, %22, %21
%50 = load i8*, i8** %1
ret i8* %50
}

LLVM IR (-O2):
@.str = [13 x i8] c"LESSHISTFILE\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [10 x i8] c"/dev/null\00"
@.str.3 = [5 x i8] c"HOME\00"
@.str.4 = [9 x i8] c".lesshst\00"
@.str.5 = [6 x i8] c"%s/%s\00"
define i8* @histfile_name() {
%1 = tail call i8* @lgetenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %14, label %3
3: ; preds = %0
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %28, label %9
9: ; preds = %6
%10 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = tail call i8* @save(i8* %1)
br label %28
14: ; preds = %3, %0
%15 = tail call i8* @lgetenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %28, label %17
17: ; preds = %14
%18 = load i8, i8* %15
%19 = icmp eq i8 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = tail call i32 @strlen(i8* %15)
%22 = tail call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%23 = add i32 %21, 2
%24 = add i32 %23, %22
%25 = tail call i64 @ecalloc(i32 %24, i32 1)
%26 = inttoptr i64 %25 to i8*
%27 = tail call i32 @snprintf(i8* %26, i32 %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %14, %17, %6, %9, %20, %12
%29 = phi i8* [ %13, %12 ], [ %26, %20 ], [ null, %9 ], [ null, %6 ], [ null, %17 ], [ null, %14 ]
ret i8* %29
}