#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 *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *getHomeDir(char *home) {
  if (home != NULL) {
    free(home);
  }
  home = (char *)malloc(strlen(getenv("HOME")) + strlen("/.wiCon") + 1);
  strcpy(home, getenv("HOME"));
  strcat(home, "/.wiCon");
  mkdir(home, 0755);
  printf("home: %s\n", home);
  return home;
}


x86 assembly (clang, -O0):
<getHomeDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a0 <getHomeDir+0x20>
mov    -0x8(%rbp),%rdi
call   1040 <free@plt>
lea    0xe59(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1070 <strlen@plt>
mov    %rax,-0x18(%rbp)
lea    0xe46(%rip),%rdi
call   1070 <strlen@plt>
mov    -0x18(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xe19(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x10(%rbp),%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    $0x1ed,%esi
call   1060 <mkdir@plt>
mov    -0x8(%rbp),%rsi
lea    0xdec(%rip),%rdi
call   1080 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getHomeDir>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     118e <getHomeDir+0xe>
call   1040 <free@plt>
lea    0xe6b(%rip),%r14
mov    %r14,%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1070 <strlen@plt>
lea    0x8(%rax),%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1060 <mkdir@plt>
lea    0xe26(%rip),%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [8 x i8] c"/.wiCon\00"
@.str.2 = [10 x i8] c"home: %s\0A\00"
define i8* @getHomeDir(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i32 @free(i8* %0)
br label %5
5: ; preds = %3, %1
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%8 = add nsw i64 %7, 8
%9 = tail call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @strcpy(i8* %10, i8* %11)
%13 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @mkdir(i8* %10, i32 493)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %10)
ret i8* %10
}