#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 */
scalar_t__ check_and_create(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
char *gettext(char *);
int /*<<< orphan*/ imanes_sprintf(char *, scalar_t__, char *, char *, char,
                                  char *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
char *get_user_imanes_dir() {
  char *user_home;
  char *user_imanes_dir;
  user_home = getenv("HOME");
  if (user_home == NULL) {
    fprintf(stderr, gettext("Couldn't find user's home directory. Will not "
                            "load user configuration\n"));
    return NULL;
  }
  user_imanes_dir = (char *)malloc(strlen(user_home) + strlen(".imanes") + 2);
  imanes_sprintf(user_imanes_dir, strlen(user_home) + strlen(".imanes") + 2,
                 "%s%c%s", user_home, '/', ".imanes");
  if (check_and_create(user_imanes_dir))
    return NULL;
  return user_imanes_dir;
}


x86 assembly (clang, -O0):
<get_user_imanes_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <get_user_imanes_dir+0x53>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xe5f(%rip),%rdi
call   1060 <gettext@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rsi
call   1080 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1265 <get_user_imanes_dir+0xf5>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x38(%rbp)
lea    0xe75(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
lea    0xe40(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdi
add    %rax,%rsi
add    $0x2,%rsi
mov    -0x10(%rbp),%rcx
lea    0xe29(%rip),%rdx
mov    $0x2f,%r8d
lea    0xe14(%rip),%r9
call   1070 <imanes_sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <check_and_create@plt>
cmp    $0x0,%rax
je     125d <get_user_imanes_dir+0xed>
movq   $0x0,-0x8(%rbp)
jmp    1265 <get_user_imanes_dir+0xf5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_user_imanes_dir>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11dd <get_user_imanes_dir+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x9(%rax),%rdi
call   1090 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x9(%rax),%rsi
lea    0xea5(%rip),%rdx
lea    0xe96(%rip),%r9
mov    %r14,%rdi
mov    %rbx,%rcx
mov    $0x2f,%r8d
call   1070 <imanes_sprintf@plt>
mov    %r14,%rdi
call   1040 <check_and_create@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
cmove  %r14,%rax
jmp    11fe <get_user_imanes_dir+0x8e>
mov    0x2dfc(%rip),%rax
mov    (%rax),%ebx
lea    0xe18(%rip),%rdi
call   1060 <gettext@plt>
mov    %ebx,%edi
mov    %rax,%rsi
call   1080 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [71 x i8] c"Couldn't find user's home directory. Will not load user configuration\0A\00"
@.str.2 = [8 x i8] c".imanes\00"
@.str.3 = [7 x i8] c"%s%c%s\00"
define i8* @get_user_imanes_dir() {
%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** %2
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i8* @gettext(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @fprintf(i32 %8, i8* %9)
store i8* null, i8** %1
br label %33
11: ; preds = %0
%12 = load i8*, i8** %2
%13 = call i64 @strlen(i8* %12)
%14 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = add nsw i64 %13, %14
%16 = add nsw i64 %15, 2
%17 = call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = load i8*, i8** %2
%21 = call i64 @strlen(i8* %20)
%22 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%23 = add nsw i64 %21, %22
%24 = add nsw i64 %23, 2
%25 = load i8*, i8** %2
%26 = call i32 @imanes_sprintf(i8* %19, i64 %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %25, i8 signext 47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %3
%28 = call i64 @check_and_create(i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %11
store i8* null, i8** %1
br label %33
31: ; preds = %11
%32 = load i8*, i8** %3
store i8* %32, i8** %1
br label %33
33: ; preds = %31, %30, %7
%34 = load i8*, i8** %1
ret i8* %34
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [71 x i8] c"Couldn't find user's home directory. Will not load user configuration\0A\00"
@.str.2 = [8 x i8] c".imanes\00"
@.str.3 = [7 x i8] c"%s%c%s\00"
define i8* @get_user_imanes_dir() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i8* @gettext(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @fprintf(i32 %4, i8* %5)
br label %18
7: ; preds = %0
%8 = tail call i64 @strlen(i8* %1)
%9 = add nsw i64 %8, 9
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i64 @strlen(i8* %1)
%13 = add nsw i64 %12, 9
%14 = tail call i32 @imanes_sprintf(i8* %11, i64 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8 signext 47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i64 @check_and_create(i8* %11)
%16 = icmp eq i64 %15, 0
%17 = select i1 %16, i8* %11, i8* null
br label %18
18: ; preds = %7, %3
%19 = phi i8* [ null, %3 ], [ %17, %7 ]
ret i8* %19
}