#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 */
char *getenv(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *xmalloc(scalar_t__);
char *get_default_rc_name() {
  char *home;
  char *result;
  char *file = ".fferc";
  result = NULL;
  home = getenv("HOME");
  if (home != NULL) {
    result = xmalloc(strlen(home) + strlen(file) + strlen("/") + 2);
    strcpy(result, home);
    strcat(result, "/");
    strcat(result, file);
  } else {
    result = file;
  }
  return result;
}


x86 assembly (clang, -O0):
<get_default_rc_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11f9 <get_default_rc_name+0xa9>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
lea    0xe5b(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1060 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
jmp    1201 <get_default_rc_name+0xb1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_default_rc_name>:
push   %r14
push   %rbx
push   %rax
lea    0xeac(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a7 <get_default_rc_name+0x57>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x9(%rax),%rdi
call   1060 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
jmp    11ae <get_default_rc_name+0x5e>
lea    0xe52(%rip),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c".fferc\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
define i8* @get_default_rc_name() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* null, i8** %2
%4 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %25
7: ; preds = %0
%8 = load i8*, i8** %1
%9 = call i64 @strlen(i8* %8)
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %9, %11
%13 = call i64 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = add nsw i64 %12, %13
%15 = add nsw i64 %14, 2
%16 = call i8* @xmalloc(i64 %15)
store i8* %16, i8** %2
%17 = load i8*, i8** %2
%18 = load i8*, i8** %1
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %2
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = load i8*, i8** %2
%23 = load i8*, i8** %3
%24 = call i32 @strcat(i8* %22, i8* %23)
br label %27
25: ; preds = %0
%26 = load i8*, i8** %3
store i8* %26, i8** %2
br label %27
27: ; preds = %25, %7
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@.str = [7 x i8] c".fferc\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
define i8* @get_default_rc_name() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i64 @strlen(i8* %1)
%5 = add nsw i64 %4, 9
%6 = tail call i8* @xmalloc(i64 %5)
%7 = tail call i32 @strcpy(i8* %6, i8* %1)
%8 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %0, %3
%11 = phi i8* [ %6, %3 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %0 ]
ret i8* %11
}