#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 /*<<< orphan*/);
int /*<<< orphan*/ getuid();
int git_release_ssh_get_home_directory(char **out) {
  char *home_directory = getenv("HOME");
  if (!home_directory) {
    struct passwd *pwd = getpwuid(getuid());
    if (pwd) {
      home_directory = pwd->pw_dir;
    } else {
      return 1;
    }
  }
  *out = home_directory;
  return 0;
}


x86 assembly (clang, -O0):
<git_release_ssh_get_home_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1195 <git_release_ssh_get_home_directory+0x65>
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1184 <git_release_ssh_get_home_directory+0x54>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1190 <git_release_ssh_get_home_directory+0x60>
movl   $0x1,-0x4(%rbp)
jmp    11a7 <git_release_ssh_get_home_directory+0x77>
jmp    1195 <git_release_ssh_get_home_directory+0x65>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<git_release_ssh_get_home_directory>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    115b <git_release_ssh_get_home_directory+0x2b>
xor    %eax,%eax
call   1050 <getuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     1162 <git_release_ssh_get_home_directory+0x32>
mov    (%rax),%rax
mov    %rax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.passwd = type { i8* }
@.str = [5 x i8] c"HOME\00"
define i32 @git_release_ssh_get_home_directory(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca %struct.passwd*
store i8** %0, i8*** %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 %20, label %9
9: ; preds = %1
%10 = call i32 (...) @getuid()
%11 = call %struct.passwd* @getpwuid(i32 %10)
store %struct.passwd* %11, %struct.passwd** %5
%12 = load %struct.passwd*, %struct.passwd** %5
%13 = icmp ne %struct.passwd* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load %struct.passwd*, %struct.passwd** %5
%16 = getelementptr inbounds %struct.passwd, %struct.passwd* %15, i32 0, i32 0
%17 = load i8*, i8** %16
store i8* %17, i8** %4
br label %19
18: ; preds = %9
store i32 1, i32* %2
br label %23
19: ; preds = %14
br label %20
20: ; preds = %19, %1
%21 = load i8*, i8** %4
%22 = load i8**, i8*** %3
store i8* %21, i8** %22
store i32 0, i32* %2
br label %23
23: ; preds = %20, %18
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.passwd = type { i8* }
@.str = [5 x i8] c"HOME\00"
define i32 @git_release_ssh_get_home_directory(i8** nocapture writeonly %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 %4, label %11
4: ; preds = %1
%5 = tail call i32 (...) @getuid()
%6 = tail call %struct.passwd* @getpwuid(i32 %5)
%7 = icmp eq %struct.passwd* %6, null
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = getelementptr inbounds %struct.passwd, %struct.passwd* %6, i64 0, i32 0
%10 = load i8*, i8** %9
br label %11
11: ; preds = %8, %1
%12 = phi i8* [ %2, %1 ], [ %10, %8 ]
store i8* %12, i8** %0
br label %13
13: ; preds = %4, %11
%14 = phi i32 [ 0, %11 ], [ 1, %4 ]
ret i32 %14
}