#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int /*<<< orphan*/ file_exists(char *);
char *getenv(char *);
char *strdup(char *);
char *get_home(void) {
  char *s;
  s = getenv("HOME");
  if (s == NULL) {
    errx(EXIT_FAILURE, "unknown variable '$HOME'");
  }
  if (!file_exists(s)) {
    errx(EXIT_FAILURE, "your $HOME does not exist");
  }
  return strdup(s);
}


x86 assembly (clang, -O0):
<get_home>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1178 <get_home+0x38>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1050 <errx@plt>
mov    -0x8(%rbp),%rdi
call   1040 <file_exists@plt>
cmp    $0x0,%eax
jne    119f <get_home+0x5f>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1050 <errx@plt>
mov    -0x8(%rbp),%rdi
call   1060 <strdup@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_home>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116a <get_home+0x2a>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
call   1050 <errx@plt>
mov    %rbx,%rdi
call   1040 <file_exists@plt>
test   %eax,%eax
jne    118b <get_home+0x4b>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
call   1050 <errx@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <strdup@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"unknown variable '$HOME'\00"
@.str.2 = [26 x i8] c"your $HOME does not exist\00"
define i8* @get_home() {
%1 = alloca i8*
%2 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %2, i8** %1
%3 = load i8*, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @EXIT_FAILURE
%7 = call i32 @errx(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = load i8*, i8** %1
%10 = call i32 @file_exists(i8* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @errx(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %12, %8
%16 = load i8*, i8** %1
%17 = call i8* @strdup(i8* %16)
ret i8* %17
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"unknown variable '$HOME'\00"
@.str.2 = [26 x i8] c"your $HOME does not exist\00"
define noalias i8* @get_home() {
%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 %6
3: ; preds = %0
%4 = load i32, i32* @EXIT_FAILURE
%5 = tail call i32 @errx(i32 %4, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %3, %0
%7 = tail call i32 @file_exists(i8* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @errx(i32 %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %9, %6
%13 = tail call i8* @strdup(i8* %1)
ret i8* %13
}