#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 *, char *);
char *getenv(char *);
char *env_get_home_dir(void) {
  char var[80] = "HOME";
  char *home_dir = getenv(var);
  if (home_dir == NULL)
    errx(EXIT_FAILURE, "no %s environment variable set", var);
  return home_dir;
}


x86 assembly (clang, -O0):
<env_get_home_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1050 <memset@plt>
movb   $0x48,-0x50(%rbp)
movb   $0x4f,-0x4f(%rbp)
movb   $0x4d,-0x4e(%rbp)
movb   $0x45,-0x4d(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    1189 <env_get_home_dir+0x59>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    -0x50(%rbp),%rdx
lea    0xe7c(%rip),%rsi
call   1040 <errx@plt>
mov    -0x58(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_get_home_dir>:
push   %rbx
sub    $0x50,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x454d4f48,(%rsp)
mov    %rsp,%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116f <env_get_home_dir+0x4f>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
mov    %rsp,%rdx
call   1040 <errx@plt>
mov    %rbx,%rax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [31 x i8] c"no %s environment variable set\00"
define i8* @env_get_home_dir() {
%1 = alloca [80 x i8]
%2 = alloca i8*
%3 = bitcast [80 x i8]* %1 to i8*
%4 = bitcast i8* %3 to [80 x i8]*
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i32 0, i32 0
store i8 72, i8* %5
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i32 0, i32 1
store i8 79, i8* %6
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i32 0, i32 2
store i8 77, i8* %7
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i32 0, i32 3
store i8 69, i8* %8
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%10 = call i8* @getenv(i8* %9)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = load i32, i32* @EXIT_FAILURE
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%16 = call i32 @errx(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %13, %0
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [31 x i8] c"no %s environment variable set\00"
define i8* @env_get_home_dir() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
store i8 72, i8* %2
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 1
store i8 79, i8* %3
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 2
store i8 77, i8* %4
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 3
store i8 69, i8* %5
%6 = call i8* @getenv(i8* %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @errx(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %11
11: ; preds = %8, %0
ret i8* %6
}