#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 */
int /*<<< orphan*/ free(char *);
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, ...);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
char *get_ident_path() {
  char *p = malloc(4096 * sizeof(char));
  char *fn = ".daust";
  char *hd = getenv("HOME");
  char *root = strdup("/");
  if (strcmp(hd, root) == 0) {
    *hd = '\0';
  }
  free(root);
  snprintf(p, 4096, "%s/%s", hd, fn);
  mkdir(p, 0777);
  snprintf(p, 4096, "%s/%s/%s", hd, fn, "ident");
  return p;
}


x86 assembly (clang, -O0):
<get_ident_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe6f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
lea    0xe64(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11cf <get_ident_path+0x5f>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x1000,%esi
lea    0xe21(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x1000,%esi
lea    0xdf1(%rip),%rdx
lea    0xdf3(%rip),%r9
mov    $0x0,%al
call   1060 <snprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ident_path>:
push   %r15
push   %r14
push   %rbx
mov    $0x1000,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xe7e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
lea    0xe74(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11b4 <get_ident_path+0x44>
movb   $0x0,(%r15)
mov    %rbx,%rdi
call   1040 <free@plt>
lea    0xe4e(%rip),%rdx
lea    0xe36(%rip),%rbx
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %r15,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rdi
mov    $0x1ff,%esi
call   1050 <mkdir@plt>
lea    0xe1b(%rip),%rdx
lea    0xe1d(%rip),%r9
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %r15,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c".daust\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [9 x i8] c"%s/%s/%s\00"
@.str.5 = [6 x i8] c"ident\00"
define i8* @get_ident_path() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i8* @malloc(i32 4096)
store i8* %5, i8** %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %6, i8** %3
%7 = call i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = call i64 @strcmp(i8* %8, i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = load i8*, i8** %3
store i8 0, i8* %13
br label %14
14: ; preds = %12, %0
%15 = load i8*, i8** %4
%16 = call i32 @free(i8* %15)
%17 = load i8*, i8** %1
%18 = load i8*, i8** %3
%19 = load i8*, i8** %2
%20 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %17, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %18, i8* %19)
%21 = load i8*, i8** %1
%22 = call i32 @mkdir(i8* %21, i32 511)
%23 = load i8*, i8** %1
%24 = load i8*, i8** %3
%25 = load i8*, i8** %2
%26 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %23, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %24, i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%27 = load i8*, i8** %1
ret i8* %27
}

LLVM IR (-O2):
@.str = [7 x i8] c".daust\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [9 x i8] c"%s/%s/%s\00"
@.str.5 = [6 x i8] c"ident\00"
define i8* @get_ident_path() {
%1 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i64 @strcmp(i8* %2, i8* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i8 0, i8* %2
br label %7
7: ; preds = %6, %0
%8 = tail call i32 @free(i8* %3)
%9 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %1, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @mkdir(i8* %1, i32 511)
%11 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %1, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
ret i8* %1
}