#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 *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void replaceHomeDir(char *currDir) {
  char homeDir[50] = "";
  strcpy(homeDir, getenv("HOME"));
  char tmpCurrDir[255] = "";
  strcpy(tmpCurrDir, currDir);
  tmpCurrDir[strlen(homeDir)] = '\0';
  if (strcmp(tmpCurrDir, homeDir) == 0) {
    strncpy(tmpCurrDir, currDir + strlen(homeDir),
            strlen(currDir) - strlen(homeDir) + 1);
    strcpy(currDir, "~");
    strcat(currDir, tmpCurrDir);
  }
}


x86 assembly (clang, -O0):
<replaceHomeDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1070 <memset@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    0xe5f(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x148(%rbp),%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1070 <memset@plt>
lea    -0x140(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
lea    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x140(%rbp,%rax,1)
lea    -0x140(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1293 <replaceHomeDir+0x123>
lea    -0x140(%rbp),%rax
mov    %rax,-0x158(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x168(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x150(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x15c(%rbp)
lea    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x15c(%rbp),%edx
mov    -0x158(%rbp),%rdi
mov    -0x150(%rbp),%rsi
sub    %eax,%edx
add    $0x1,%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xd87(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   1090 <strcat@plt>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replaceHomeDir>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x148,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
lea    0xe71(%rip),%rdi
call   1030 <getenv@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
xorps  %xmm0,%xmm0
movups %xmm0,0x12f(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
lea    0x40(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,0x40(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    129c <replaceHomeDir+0x13c>
mov    %rsp,%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1060 <strlen@plt>
sub    %eax,%ebp
add    $0x1,%ebp
lea    0x40(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
lea    0xd7c(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
add    $0x148,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"~\00"
define void @replaceHomeDir(i8* %0) {
%2 = alloca i8*
%3 = alloca [50 x i8]
%4 = alloca [255 x i8]
store i8* %0, i8** %2
%5 = bitcast [50 x i8]* %3 to i8*
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%7 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @strcpy(i8* %6, i8* %7)
%9 = bitcast [255 x i8]* %4 to i8*
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 %15
store i8 0, i8* %16
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%19 = call i64 @strcmp(i8* %17, i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %40
21: ; preds = %1
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%23 = load i8*, i8** %2
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = load i8*, i8** %2
%29 = call i32 @strlen(i8* %28)
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %29, %31
%33 = add nsw i32 %32, 1
%34 = call i32 @strncpy(i8* %22, i8* %27, i32 %33)
%35 = load i8*, i8** %2
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = load i8*, i8** %2
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%39 = call i32 @strcat(i8* %37, i8* %38)
br label %40
40: ; preds = %21, %1
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [2 x i8] c"~\00"
define void @replaceHomeDir(i8* %0) {
%2 = alloca [50 x i8]
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strcpy(i8* %4, i8* %5)
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* %0)
%9 = call i32 @strlen(i8* %4)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i64 @strcmp(i8* %7, i8* %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %1
%15 = call i32 @strlen(i8* %4)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = call i32 @strlen(i8* %0)
%19 = call i32 @strlen(i8* %4)
%20 = add i32 %18, 1
%21 = sub i32 %20, %19
%22 = call i32 @strncpy(i8* %7, i8* %17, i32 %21)
%23 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @strcat(i8* %0, i8* %7)
br label %25
25: ; preds = %14, %1
ret void
}