#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ mkdir_p(char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, scalar_t__);
int /*<<< orphan*/ strncpy(char *, char *, int);
FILE *hscore_open(char *flags) {
  char full_path[256];
  memset(full_path, '\0', 256);
  if (getenv("HOME") == NULL)
    strncpy(full_path, "/tmp", 256);
  else
    strncpy(full_path, getenv("HOME"), 256);
  strncat(full_path,
          "/"
          ".local/share/nflood/",
          (256 - strlen(full_path)));
  mkdir_p(full_path);
  strncat(full_path, "nflood.scores", (256 - strlen(full_path)));
  return fopen(full_path, flags);
}


x86 assembly (clang, -O0):
<hscore_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0xe67(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    11c5 <hscore_open+0x55>
lea    -0x110(%rbp),%rdi
lea    0xe4f(%rip),%rsi
mov    $0x100,%edx
call   1040 <strncpy@plt>
jmp    11f3 <hscore_open+0x83>
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
lea    0xe26(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x118(%rbp),%rdi
mov    %rax,%rsi
mov    $0x100,%edx
call   1040 <strncpy@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x128(%rbp),%rdi
mov    $0x100,%edx
sub    %rax,%rdx
lea    0xde7(%rip),%rsi
call   1070 <strncat@plt>
lea    -0x110(%rbp),%rdi
call   1080 <mkdir_p@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x120(%rbp),%rdi
mov    $0x100,%edx
sub    %rax,%rdx
lea    0xdbc(%rip),%rsi
call   1070 <strncat@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <fopen@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hscore_open>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    0xe6b(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a7 <hscore_open+0x37>
mov    %rsp,%rdi
mov    %rax,%rsi
jmp    11b1 <hscore_open+0x41>
lea    0xe57(%rip),%rsi
mov    %rsp,%rdi
mov    $0x100,%edx
call   1040 <strncpy@plt>
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    $0x100,%ebx
mov    $0x100,%edx
sub    %rax,%rdx
lea    0xe30(%rip),%rsi
mov    %r15,%rdi
call   1070 <strncat@plt>
mov    %r15,%rdi
call   1080 <mkdir_p@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
sub    %rax,%rbx
lea    0xe24(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1070 <strncat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <fopen@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [22 x i8] c"/.local/share/nflood/\00"
@.str.3 = [14 x i8] c"nflood.scores\00"
define i32* @hscore_open(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
store i8* %0, i8** %2
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i8 signext 0, i32 256)
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i32 @strncpy(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 256)
br label %15
11: ; preds = %1
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @strncpy(i8* %12, i8* %13, i32 256)
br label %15
15: ; preds = %11, %8
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%18 = call i64 @strlen(i8* %17)
%19 = sub nsw i64 256, %18
%20 = call i32 @strncat(i8* %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%22 = call i32 @mkdir_p(i8* %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%25 = call i64 @strlen(i8* %24)
%26 = sub nsw i64 256, %25
%27 = call i32 @strncat(i8* %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%29 = load i8*, i8** %2
%30 = call i32* @fopen(i8* %28, i8* %29)
ret i32* %30
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [22 x i8] c"/.local/share/nflood/\00"
@.str.3 = [14 x i8] c"nflood.scores\00"
define noalias i32* @hscore_open(i8* nocapture %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i8 signext 0, i32 256)
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @strncpy(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 256)
br label %11
9: ; preds = %1
%10 = call i32 @strncpy(i8* %3, i8* %5, i32 256)
br label %11
11: ; preds = %9, %7
%12 = call i64 @strlen(i8* %3)
%13 = sub nsw i64 256, %12
%14 = call i32 @strncat(i8* %3, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 %13)
%15 = call i32 @mkdir_p(i8* %3)
%16 = call i64 @strlen(i8* %3)
%17 = sub nsw i64 256, %16
%18 = call i32 @strncat(i8* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 %17)
%19 = call i32* @fopen(i8* %3, i8* %0)
ret i32* %19
}