#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 passwd {
  char *pw_dir;
};

/* Variables and functions */
char *getenv(char *);
struct passwd *getpwuid(int);
int getuid();
char *strdup(char *);
char *__imlib_FileHomeDir(int uid) {
  static int usr_uid = -1;
  static char *usr_s = NULL;
  char *s;
  struct passwd *pwd;
  s = getenv("HOME");
  if (s)
    return strdup(s);
  if (usr_uid < 0)
    usr_uid = getuid();
  if ((uid == usr_uid) && (usr_s)) {
    return (strdup(usr_s));
  }
  pwd = getpwuid(uid);
  if (pwd) {
    s = strdup(pwd->pw_dir);
    if (uid == usr_uid)
      usr_s = strdup(s);
    return (s);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<__imlib_FileHomeDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
lea    0xeae(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1178 <__imlib_FileHomeDir+0x38>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    121f <__imlib_FileHomeDir+0xdf>
cmpl   $0x0,0x2ec1(%rip)
jge    1192 <__imlib_FileHomeDir+0x52>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,0x2eae(%rip)
mov    -0xc(%rbp),%eax
cmp    0x2ea5(%rip),%eax
jne    11c4 <__imlib_FileHomeDir+0x84>
cmpq   $0x0,0x2ea7(%rip)
je     11c4 <__imlib_FileHomeDir+0x84>
mov    0x2e9a(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    121f <__imlib_FileHomeDir+0xdf>
mov    -0xc(%rbp),%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1217 <__imlib_FileHomeDir+0xd7>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cmp    0x2e4c(%rip),%eax
jne    120a <__imlib_FileHomeDir+0xca>
mov    -0x18(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,0x2e46(%rip)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121f <__imlib_FileHomeDir+0xdf>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__imlib_FileHomeDir>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xeb3(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     115c <__imlib_FileHomeDir+0x1c>
mov    %rax,%rdi
jmp    1183 <__imlib_FileHomeDir+0x43>
mov    0x2ede(%rip),%eax
test   %eax,%eax
jns    1173 <__imlib_FileHomeDir+0x33>
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,0x2ecd(%rip)
cmp    %ebx,%eax
jne    118f <__imlib_FileHomeDir+0x4f>
mov    0x2ed2(%rip),%rdi
test   %rdi,%rdi
je     118f <__imlib_FileHomeDir+0x4f>
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <strdup@plt>
mov    %ebx,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     11bf <__imlib_FileHomeDir+0x7f>
mov    (%rax),%rdi
call   1060 <strdup@plt>
mov    %rax,%r14
cmp    %ebx,0x2e94(%rip)
jne    11c2 <__imlib_FileHomeDir+0x82>
mov    %r14,%rdi
call   1060 <strdup@plt>
mov    %rax,0x2e93(%rip)
jmp    11c2 <__imlib_FileHomeDir+0x82>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@__imlib_FileHomeDir.usr_uid = internal global i32 -1
@__imlib_FileHomeDir.usr_s = internal global i8* null
@.str = [5 x i8] c"HOME\00"
define i8* @__imlib_FileHomeDir(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.passwd*
store i32 %0, i32* %3
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = call i8* @strdup(i8* %10)
store i8* %11, i8** %2
br label %46
12: ; preds = %1
%13 = load i32, i32* @__imlib_FileHomeDir.usr_uid
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (...) @getuid()
store i32 %16, i32* @__imlib_FileHomeDir.usr_uid
br label %17
17: ; preds = %15, %12
%18 = load i32, i32* %3
%19 = load i32, i32* @__imlib_FileHomeDir.usr_uid
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = load i8*, i8** @__imlib_FileHomeDir.usr_s
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** @__imlib_FileHomeDir.usr_s
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %2
br label %46
27: ; preds = %21, %17
%28 = load i32, i32* %3
%29 = call %struct.passwd* @getpwuid(i32 %28)
store %struct.passwd* %29, %struct.passwd** %5
%30 = load %struct.passwd*, %struct.passwd** %5
%31 = icmp ne %struct.passwd* %30, null
br i1 %31, label %32, label %45
32: ; preds = %27
%33 = load %struct.passwd*, %struct.passwd** %5
%34 = getelementptr inbounds %struct.passwd, %struct.passwd* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %4
%37 = load i32, i32* %3
%38 = load i32, i32* @__imlib_FileHomeDir.usr_uid
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = load i8*, i8** %4
%42 = call i8* @strdup(i8* %41)
store i8* %42, i8** @__imlib_FileHomeDir.usr_s
br label %43
43: ; preds = %40, %32
%44 = load i8*, i8** %4
store i8* %44, i8** %2
br label %46
45: ; preds = %27
store i8* null, i8** %2
br label %46
46: ; preds = %45, %43, %24, %9
%47 = load i8*, i8** %2
ret i8* %47
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@__imlib_FileHomeDir.usr_uid = internal unnamed_addr global i32 -1
@__imlib_FileHomeDir.usr_s = internal unnamed_addr global i8* null
@.str = [5 x i8] c"HOME\00"
define noalias i8* @__imlib_FileHomeDir(i32 %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i8* @strdup(i8* %2)
br label %30
6: ; preds = %1
%7 = load i32, i32* @__imlib_FileHomeDir.usr_uid
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 (...) @getuid()
store i32 %10, i32* @__imlib_FileHomeDir.usr_uid
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ %10, %9 ], [ %7, %6 ]
%13 = icmp eq i32 %12, %0
%14 = load i8*, i8** @__imlib_FileHomeDir.usr_s
%15 = icmp ne i8* %14, null
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i8* @strdup(i8* %14)
br label %30
19: ; preds = %11
%20 = tail call %struct.passwd* @getpwuid(i32 %0)
%21 = icmp eq %struct.passwd* %20, null
br i1 %21, label %30, label %22
22: ; preds = %19
%23 = getelementptr inbounds %struct.passwd, %struct.passwd* %20, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = tail call i8* @strdup(i8* %24)
%26 = load i32, i32* @__imlib_FileHomeDir.usr_uid
%27 = icmp eq i32 %26, %0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = tail call i8* @strdup(i8* %25)
store i8* %29, i8** @__imlib_FileHomeDir.usr_s
br label %30
30: ; preds = %19, %22, %28, %17, %4
%31 = phi i8* [ %5, %4 ], [ %18, %17 ], [ %25, %28 ], [ %25, %22 ], [ null, %19 ]
ret i8* %31
}