#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*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
const char *mc_home_path(void) {
  static char buffer[256] = {0};
  if (!buffer[0]) {
    char *s = getenv("HOME");
    if (s && *s) {
      int len = strlen(s);
      if (('/' == s[len - 1]) || ('\\' == s[len - 1])) {
        strncpy(buffer, s, len - 1);
      } else {
        strncpy(buffer, s, len);
      }
    } else {
      strcpy(buffer, "/tmp/home");
    }
  }
  return buffer;
}


x86 assembly (clang, -O0):
<mc_home_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpb   $0x0,0x2f01(%rip)
jne    1213 <mc_home_path+0xd3>
lea    0xea4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11fb <mc_home_path+0xbb>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fb <mc_home_path+0xbb>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2f,%eax
cmp    %ecx,%eax
je     11c8 <mc_home_path+0x88>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x5c,%eax
cmp    %ecx,%eax
jne    11e3 <mc_home_path+0xa3>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
sub    $0x1,%edx
lea    0x2e77(%rip),%rdi
call   1040 <strncpy@plt>
jmp    11f6 <mc_home_path+0xb6>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0x2e5f(%rip),%rdi
call   1040 <strncpy@plt>
jmp    120e <mc_home_path+0xce>
lea    0x2e4e(%rip),%rdi
lea    0xdfc(%rip),%rsi
call   1050 <strcpy@plt>
jmp    1213 <mc_home_path+0xd3>
lea    0x2e36(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mc_home_path>:
push   %rbx
cmpb   $0x0,0x2f08(%rip)
jne    11a4 <mc_home_path+0x64>
lea    0xeaf(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1191 <mc_home_path+0x51>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     1191 <mc_home_path+0x51>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %eax,%rdx
mov    -0x1(%rbx,%rdx,1),%cl
cmp    $0x5c,%cl
je     117c <mc_home_path+0x3c>
cmp    $0x2f,%cl
jne    11ad <mc_home_path+0x6d>
add    $0xffffffffffffffff,%rdx
lea    0x2ec9(%rip),%rdi
mov    %rbx,%rsi
call   1040 <strncpy@plt>
jmp    11a4 <mc_home_path+0x64>
lea    0x2eb8(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1050 <strcpy@plt>
lea    0x2ea5(%rip),%rax
pop    %rbx
ret
lea    0x2e9c(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
jmp    11a4 <mc_home_path+0x64>

LLVM IR (-O0):
@mc_home_path.buffer = internal global [256 x i8] zeroinitializer
@.str = [5 x i8] c"HOME\00"
@.str.1 = [10 x i8] c"/tmp/home\00"
define i8* @mc_home_path() {
%1 = alloca i8*
%2 = alloca i32
%3 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0)
%4 = icmp ne i8 %3, 0
br i1 %4, label %47, label %5
5: ; preds = %0
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %1
%7 = load i8*, i8** %1
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %44
9: ; preds = %5
%10 = load i8*, i8** %1
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %44
14: ; preds = %9
%15 = load i8*, i8** %1
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %2
%17 = load i8*, i8** %1
%18 = load i32, i32* %2
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 47, %23
br i1 %24, label %34, label %25
25: ; preds = %14
%26 = load i8*, i8** %1
%27 = load i32, i32* %2
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 92, %32
br i1 %33, label %34, label %39
34: ; preds = %25, %14
%35 = load i8*, i8** %1
%36 = load i32, i32* %2
%37 = sub nsw i32 %36, 1
%38 = call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0), i8* %35, i32 %37)
br label %43
39: ; preds = %25
%40 = load i8*, i8** %1
%41 = load i32, i32* %2
%42 = call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0), i8* %40, i32 %41)
br label %43
43: ; preds = %39, %34
br label %46
44: ; preds = %9, %5
%45 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %44, %43
br label %47
47: ; preds = %46, %0
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@mc_home_path.buffer = internal global [256 x i8] zeroinitializer
@.str = [5 x i8] c"HOME\00"
@.str.1 = [10 x i8] c"/tmp/home\00"
define i8* @mc_home_path() {
%1 = load i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0)
%2 = icmp eq i8 %1, 0
br i1 %2, label %3, label %21
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %4)
%11 = add nsw i32 %10, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %4, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %17 [
i8 47, label %15
i8 92, label %15
]
15: ; preds = %9, %9
%16 = tail call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0), i8* %4, i32 %11)
br label %21
17: ; preds = %9
%18 = tail call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0), i8* %4, i32 %10)
br label %21
19: ; preds = %6, %3
%20 = tail call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %17, %15, %0
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @mc_home_path.buffer, i64 0, i64 0)
}