#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 *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *utils_get_rcpath(void) {
  char *home;
  char *rcpath;
  int home_len;
  home = getenv("HOME");
  if (home) {
    home_len = strlen(home);
  } else {
    home_len = 0;
  }
  rcpath = malloc(sizeof(char) * (home_len + 10));
  if (home) {
    strcpy(rcpath, home);
  } else {
    rcpath[0] = '\0';
  }
  if (home_len > 0) {
    if (rcpath[home_len - 1] == '/') {
      rcpath[home_len - 1] = '\0';
    }
  }
  strcat(rcpath, "/");
  strcat(rcpath, ".mensarc");
  return rcpath;
}


x86 assembly (clang, -O0):
<utils_get_rcpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1184 <utils_get_rcpath+0x34>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
jmp    118b <utils_get_rcpath+0x3b>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xa,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11bf <utils_get_rcpath+0x6f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    11c6 <utils_get_rcpath+0x76>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
cmpl   $0x0,-0x14(%rbp)
jle    1200 <utils_get_rcpath+0xb0>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11fb <utils_get_rcpath+0xab>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1200 <utils_get_rcpath+0xb0>
mov    -0x10(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utils_get_rcpath>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a3 <utils_get_rcpath+0x53>
mov    %rax,%r15
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%r14d
lea    0xa(%r14),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
test   %r14d,%r14d
jle    11b3 <utils_get_rcpath+0x63>
add    $0xffffffff,%r14d
cmpb   $0x2f,(%rbx,%r14,1)
jne    11b3 <utils_get_rcpath+0x63>
mov    %rbx,%rax
add    %r14,%rax
jmp    11b0 <utils_get_rcpath+0x60>
mov    $0xa,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [9 x i8] c".mensarc\00"
define i8* @utils_get_rcpath() {
%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 %5
3: ; preds = %0
%4 = tail call dereferenceable_or_null(10) i8* @malloc(i32 10)
br label %17
5: ; preds = %0
%6 = tail call i32 @strlen(i8* %1)
%7 = add nsw i32 %6, 10
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i32 @strcpy(i8* %8, i8* %1)
%10 = icmp sgt i32 %6, 0
br i1 %10, label %11, label %20
11: ; preds = %5
%12 = add nsw i32 %6, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %8, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 47
br i1 %16, label %17, label %20
17: ; preds = %11, %3
%18 = phi i8* [ %4, %3 ], [ %14, %11 ]
%19 = phi i8* [ %4, %3 ], [ %8, %11 ]
store i8 0, i8* %18
br label %20
20: ; preds = %17, %11, %5
%21 = phi i8* [ %8, %11 ], [ %8, %5 ], [ %19, %17 ]
%22 = tail call i32 @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @strcat(i8* %21, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
ret i8* %21
}