#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 *calloc(int, int);
char const *getenv(char *);
int /*<<< orphan*/ strncat(char *, char const *, int);
char *expandTilde(const char in_PATH[]) {
  char *expanded = calloc(1024, sizeof(char));
  if (in_PATH[0] == '~') {
    strncat(expanded, getenv("HOME"), 1023);
    strncat(expanded, &in_PATH[1], 1023);
  } else {
    strncat(expanded, &in_PATH[0], 1023);
  }
  return expanded;
}


x86 assembly (clang, -O0):
<expandTilde>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x400,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    119f <expandTilde+0x6f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe92(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rsi
mov    $0x3ff,%edx
call   1040 <strncat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
mov    $0x3ff,%edx
call   1040 <strncat@plt>
jmp    11b1 <expandTilde+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x3ff,%edx
call   1040 <strncat@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expandTilde>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x400,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
cmpb   $0x7e,(%rbx)
jne    116e <expandTilde+0x3e>
lea    0xeab(%rip),%rdi
call   1030 <getenv@plt>
mov    %r14,%rdi
mov    %rax,%rsi
mov    $0x3ff,%edx
call   1040 <strncat@plt>
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1040 <strncat@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
define i8* @expandTilde(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = call i8* @calloc(i32 1024, i32 1)
store i8* %4, i8** %3
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 126
br i1 %9, label %10, label %18
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @strncat(i8* %11, i8* %12, i32 1023)
%14 = load i8*, i8** %3
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i32 @strncat(i8* %14, i8* %16, i32 1023)
br label %23
18: ; preds = %1
%19 = load i8*, i8** %3
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = call i32 @strncat(i8* %19, i8* %21, i32 1023)
br label %23
23: ; preds = %18, %10
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
define i8* @expandTilde(i8* %0) {
%2 = tail call dereferenceable_or_null(1024) i8* @calloc(i32 1024, i32 1)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 126
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @strncat(i8* %2, i8* %6, i32 1023)
%8 = getelementptr inbounds i8, i8* %0, i64 1
br label %9
9: ; preds = %1, %5
%10 = phi i8* [ %8, %5 ], [ %0, %1 ]
%11 = tail call i32 @strncat(i8* %2, i8* %10, i32 1023)
ret i8* %2
}