#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 */
char *getenv(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *xmalloc(int, char *);
char *xstrdup(char *, char *);
char *get_home() {
  char *home;
  char *path;
  char *other;
  if ((path = getenv("HOME")) && path[0] != '\0') {
    return xstrdup(path, "get_home: xstrdup");
  }
  if ((path = getenv("USERPROFILE")) && path[0] != '\0') {
    return xstrdup(path, "get_home: xstrdup");
  }
  if ((path = getenv("HOMEDRIVE")) && path[0] != '\0') {
    if ((other = getenv("HOMEPATH")) && other[0] != '\0') {
      home = xmalloc((strlen(path) + strlen(other) + 1) * sizeof(*home),
                     "get_home: malloc");
      strcpy(home, path);
      strcat(home, other);
      return home;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<get_home>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ab <get_home+0x4b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ab <get_home+0x4b>
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1070 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    12ad <get_home+0x14d>
lea    0xe65(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ee <get_home+0x8e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ee <get_home+0x8e>
mov    -0x18(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1070 <xstrdup@plt>
mov    %rax,-0x8(%rbp)
jmp    12ad <get_home+0x14d>
lea    0xe2e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12a5 <get_home+0x145>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12a5 <get_home+0x145>
lea    0xe0e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12a0 <get_home+0x140>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12a0 <get_home+0x140>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
lea    0xdc6(%rip),%rsi
call   1060 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12ad <get_home+0x14d>
jmp    12a5 <get_home+0x145>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_home>:
push   %r15
push   %r14
push   %rbx
lea    0xe94(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     117b <get_home+0x1b>
cmpb   $0x0,(%rax)
jne    1191 <get_home+0x31>
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a5 <get_home+0x45>
cmpb   $0x0,(%rax)
je     11a5 <get_home+0x45>
lea    0xe6d(%rip),%rsi
mov    %rax,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <xstrdup@plt>
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1218 <get_home+0xb8>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1218 <get_home+0xb8>
lea    0xe68(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1218 <get_home+0xb8>
mov    %rax,%r14
cmpb   $0x0,(%rax)
je     1218 <get_home+0xb8>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x1,%edi
lea    0xe3e(%rip),%rsi
call   1060 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
jmp    121b <get_home+0xbb>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [18 x i8] c"get_home: xstrdup\00"
@.str.2 = [12 x i8] c"USERPROFILE\00"
@.str.3 = [10 x i8] c"HOMEDRIVE\00"
@.str.4 = [9 x i8] c"HOMEPATH\00"
@.str.5 = [17 x i8] c"get_home: malloc\00"
define i8* @get_home() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = call i8* @xstrdup(i8* %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %1
br label %66
16: ; preds = %7, %0
%17 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i8* %17, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i8*, i8** %3
%27 = call i8* @xstrdup(i8* %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i8* %27, i8** %1
br label %66
28: ; preds = %19, %16
%29 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i8* %29, i8** %3
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %65
31: ; preds = %28
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %65
37: ; preds = %31
%38 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
store i8* %38, i8** %4
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %64
40: ; preds = %37
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %64
46: ; preds = %40
%47 = load i8*, i8** %3
%48 = call i32 @strlen(i8* %47)
%49 = load i8*, i8** %4
%50 = call i32 @strlen(i8* %49)
%51 = add nsw i32 %48, %50
%52 = add nsw i32 %51, 1
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 1
%55 = trunc i64 %54 to i32
%56 = call i8* @xmalloc(i32 %55, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i8* %56, i8** %2
%57 = load i8*, i8** %2
%58 = load i8*, i8** %3
%59 = call i32 @strcpy(i8* %57, i8* %58)
%60 = load i8*, i8** %2
%61 = load i8*, i8** %4
%62 = call i32 @strcat(i8* %60, i8* %61)
%63 = load i8*, i8** %2
store i8* %63, i8** %1
br label %66
64: ; preds = %40, %37
br label %65
65: ; preds = %64, %31, %28
store i8* null, i8** %1
br label %66
66: ; preds = %65, %46, %25, %13
%67 = load i8*, i8** %1
ret i8* %67
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [18 x i8] c"get_home: xstrdup\00"
@.str.2 = [12 x i8] c"USERPROFILE\00"
@.str.3 = [10 x i8] c"HOMEDRIVE\00"
@.str.4 = [9 x i8] c"HOMEPATH\00"
@.str.5 = [17 x i8] c"get_home: malloc\00"
define 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 %8, label %3
3: ; preds = %0
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i8* @xstrdup(i8* %1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %36
8: ; preds = %3, %0
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = load i8, i8* %9
%13 = icmp eq i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i8* @xstrdup(i8* %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %36
16: ; preds = %11, %8
%17 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %36, label %19
19: ; preds = %16
%20 = load i8, i8* %17
%21 = icmp eq i8 %20, 0
br i1 %21, label %36, label %22
22: ; preds = %19
%23 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %36, label %25
25: ; preds = %22
%26 = load i8, i8* %23
%27 = icmp eq i8 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %25
%29 = tail call i32 @strlen(i8* %17)
%30 = tail call i32 @strlen(i8* %23)
%31 = add i32 %29, 1
%32 = add i32 %31, %30
%33 = tail call i8* @xmalloc(i32 %32, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%34 = tail call i32 @strcpy(i8* %33, i8* %17)
%35 = tail call i32 @strcat(i8* %33, i8* %23)
br label %36
36: ; preds = %16, %19, %25, %22, %28, %14, %6
%37 = phi i8* [ %7, %6 ], [ %15, %14 ], [ %33, %28 ], [ null, %22 ], [ null, %25 ], [ null, %19 ], [ null, %16 ]
ret i8* %37
}