#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 */
typedef int /*<<< orphan*/ p;

/* Variables and functions */
int /*<<< orphan*/ error_code(int /*<<< orphan*/, char *);
char *getenv(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
char *mod_home(char *mod) {
  static char p[1024];
  char *home_dir = getenv("mod_root");
  if (!home_dir) {
    error_code(0, "Missing environment variable $mod_root.");
    return NULL;
  }
  snprintf(p, sizeof(p), "%s/%s", home_dir, mod);
  return p;
}


x86 assembly (clang, -O0):
<mod_home>:
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    1172 <mod_home+0x42>
xor    %edi,%edi
lea    0xea9(%rip),%rsi
call   1050 <error_code@plt>
movq   $0x0,-0x8(%rbp)
jmp    119d <mod_home+0x6d>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0x2ecf(%rip),%rdi
mov    $0x400,%esi
lea    0xea4(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2eb7(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mod_home>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116b <mod_home+0x3b>
lea    0x2f01(%rip),%rbx
lea    0xedb(%rip),%rdx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rcx
mov    %r14,%r8
call   1040 <snprintf@plt>
jmp    117b <mod_home+0x4b>
lea    0xe97(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
call   1050 <error_code@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@mod_home.p = internal global [1024 x i8] zeroinitializer
@.str = [9 x i8] c"mod_root\00"
@.str.1 = [40 x i8] c"Missing environment variable $mod_root.\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i8* @mod_home(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @error_code(i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %14
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = load i8*, i8** %3
%13 = call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @mod_home.p, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %12)
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @mod_home.p, i64 0, i64 0), i8** %2
br label %14
14: ; preds = %10, %8
%15 = load i8*, i8** %2
ret i8* %15
}

LLVM IR (-O2):
@mod_home.p = internal global [1024 x i8] zeroinitializer
@.str = [9 x i8] c"mod_root\00"
@.str.1 = [40 x i8] c"Missing environment variable $mod_root.\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define i8* @mod_home(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @error_code(i32 0, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %8
6: ; preds = %1
%7 = tail call i32 @snprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @mod_home.p, i64 0, i64 0), i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %0)
br label %8
8: ; preds = %6, %4
%9 = phi i8* [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @mod_home.p, i64 0, i64 0), %6 ], [ null, %4 ]
ret i8* %9
}