#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 */
struct stat {
  int st_mode;
};

/* Variables and functions */
int S_IFDIR;
int S_IFMT;
int S_IRGRP;
int S_IROTH;
int S_IRWXU;
scalar_t__ calloc(scalar_t__, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int mkdir(char *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
char *get_filename(void) {
  char *home;
  char *path;
  struct stat sb;
  home = getenv("HOME");
  path = (char *)calloc((strlen(home) + strlen("/.license/default") + 1),
                        sizeof(char));
  path[0] = '\0';
  strcat(path, home);
  strcat(path, "/.license/");
  if (stat(path, &sb) == -1) {
    if (mkdir(path, (S_IRWXU | S_IRGRP | S_IROTH)) == -1) {
      fprintf(stderr, "Failed to make directory.\n");
      return NULL;
    }
  } else if ((sb.st_mode & S_IFMT) != S_IFDIR) {
    fprintf(stderr, "File exists and is not a directory: %s\n", path);
    return NULL;
  }
  strcat(path, "default");
  return path;
}


x86 assembly (clang, -O0):
<get_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe69(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    124a <get_filename+0xda>
mov    -0x18(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    0x2dc0(%rip),%rax
or     (%rax),%esi
mov    0x2daf(%rip),%rax
or     (%rax),%esi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1245 <get_filename+0xd5>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12aa <get_filename+0x13a>
jmp    1292 <get_filename+0x122>
mov    -0x20(%rbp),%eax
mov    0x2d84(%rip),%rcx
and    (%rcx),%eax
mov    0x2d53(%rip),%rcx
cmp    (%rcx),%eax
je     128d <get_filename+0x11d>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12aa <get_filename+0x13a>
jmp    1292 <get_filename+0x122>
mov    -0x18(%rbp),%rdi
lea    0xd72(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x12(%rax),%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
je     11fe <get_filename+0x8e>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
mov    0x2dd4(%rip),%rcx
cmp    (%rcx),%eax
je     1226 <get_filename+0xb6>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %ebx,%ebx
jmp    1250 <get_filename+0xe0>
mov    0x2de3(%rip),%rax
mov    0x2dbc(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2da9(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1040 <mkdir@plt>
cmp    $0xffffffff,%eax
je     1237 <get_filename+0xc7>
lea    0xe26(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
jmp    1250 <get_filename+0xe0>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [18 x i8] c"/.license/default\00"
@.str.2 = [11 x i8] c"/.license/\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str.3 = [27 x i8] c"Failed to make directory.\0A\00"
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
@.str.4 = [40 x i8] c"File exists and is not a directory: %s\0A\00"
@.str.5 = [8 x i8] c"default\00"
define i8* @get_filename() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = call i64 @strlen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%9 = add nsw i64 %7, %8
%10 = add nsw i64 %9, 1
%11 = call i64 @calloc(i64 %10, i32 1)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 0, i8* %14
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = call i32 @strcat(i8* %15, i8* %16)
%18 = load i8*, i8** %3
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%20 = load i8*, i8** %3
%21 = call i32 @stat(i8* %20, %struct.stat* %4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %36
23: ; preds = %0
%24 = load i8*, i8** %3
%25 = load i32, i32* @S_IRWXU
%26 = load i32, i32* @S_IRGRP
%27 = or i32 %25, %26
%28 = load i32, i32* @S_IROTH
%29 = or i32 %27, %28
%30 = call i32 @mkdir(i8* %24, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i8* null, i8** %1
br label %52
35: ; preds = %23
br label %48
36: ; preds = %0
%37 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%38 = load i32, i32* %37
%39 = load i32, i32* @S_IFMT
%40 = and i32 %38, %39
%41 = load i32, i32* @S_IFDIR
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %3
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %45)
store i8* null, i8** %1
br label %52
47: ; preds = %36
br label %48
48: ; preds = %47, %35
%49 = load i8*, i8** %3
%50 = call i32 @strcat(i8* %49, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%51 = load i8*, i8** %3
store i8* %51, i8** %1
br label %52
52: ; preds = %48, %43, %32
%53 = load i8*, i8** %1
ret i8* %53
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"HOME\00"
@.str.2 = [11 x i8] c"/.license/\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@stderr = global i32 0
@.str.3 = [27 x i8] c"Failed to make directory.\0A\00"
@S_IFMT = global i32 0
@S_IFDIR = global i32 0
@.str.4 = [40 x i8] c"File exists and is not a directory: %s\0A\00"
@.str.5 = [8 x i8] c"default\00"
define i8* @get_filename() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%5 = add nsw i64 %4, 18
%6 = tail call i64 @calloc(i64 %5, i32 1)
%7 = inttoptr i64 %6 to i8*
store i8 0, i8* %7
%8 = tail call i32 @strcat(i8* %7, i8* %3)
%9 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @stat(i8* %7, %struct.stat* %1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %23
12: ; preds = %0
%13 = load i32, i32* @S_IRWXU
%14 = load i32, i32* @S_IRGRP
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = tail call i32 @mkdir(i8* %7, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %33
20: ; preds = %12
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %35
23: ; preds = %0
%24 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%25 = load i32, i32* %24
%26 = load i32, i32* @S_IFMT
%27 = and i32 %26, %25
%28 = load i32, i32* @S_IFDIR
%29 = icmp eq i32 %27, %28
br i1 %29, label %33, label %30
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %7)
br label %35
33: ; preds = %23, %12
%34 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
br label %35
35: ; preds = %33, %30, %20
%36 = phi i8* [ null, %20 ], [ %7, %33 ], [ null, %30 ]
ret i8* %36
}