#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*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strlen(char const *);
char *xmalloc(scalar_t__);
char *game_get_highscore_file(void) {
  const char *home = getenv("HOME");
  const char *file = ".nyancat-console";
  char *filepath = xmalloc(strlen(home) + strlen(file) + 2);
  sprintf(filepath, "%s/%s", home, file);
  return filepath;
}


x86 assembly (clang, -O0):
<game_get_highscore_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe76(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<game_get_highscore_file>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x12(%rax),%rdi
call   1050 <xmalloc@plt>
mov    %rax,%rbx
lea    0xea8(%rip),%rsi
lea    0xe90(%rip),%rcx
mov    %rax,%rdi
mov    %r14,%rdx
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [17 x i8] c".nyancat-console\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i8* @game_get_highscore_file() {
%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** %1
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %1
%6 = call i64 @strlen(i8* %5)
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %6, %8
%10 = add nsw i64 %9, 2
%11 = call i8* @xmalloc(i64 %10)
store i8* %11, i8** %3
%12 = load i8*, i8** %3
%13 = load i8*, i8** %1
%14 = load i8*, i8** %2
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %14)
%16 = load i8*, i8** %3
ret i8* %16
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [17 x i8] c".nyancat-console\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i8* @game_get_highscore_file() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%3 = add nsw i64 %2, 18
%4 = tail call i8* @xmalloc(i64 %3)
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
ret i8* %4
}