#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 */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void tildeReplacer(char **argv, int count, char *home, int position) {
  char *arg = argv[count];
  char *newArg = (char *)malloc(strlen(arg) + strlen(home));
  strcpy(newArg, home);
  strcat(newArg, &arg[position]);
  argv[count] = newArg;
  return;
}


x86 assembly (clang, -O0):
<tildeReplacer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1060 <strcat@plt>
mov    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tildeReplacer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbp
mov    %rdi,%r15
movslq %esi,%r13
mov    (%rdi,%r13,8),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
movslq %r14d,%rsi
add    %r12,%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,(%r15,%r13,8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @tildeReplacer(i8** %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8**, i8*** %5
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
store i8* %15, i8** %9
%16 = load i8*, i8** %9
%17 = call i64 @strlen(i8* %16)
%18 = load i8*, i8** %7
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %17, %19
%21 = call i64 @malloc(i64 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %10
%23 = load i8*, i8** %10
%24 = load i8*, i8** %7
%25 = call i32 @strcpy(i8* %23, i8* %24)
%26 = load i8*, i8** %10
%27 = load i8*, i8** %9
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i32 @strcat(i8* %26, i8* %30)
%32 = load i8*, i8** %10
%33 = load i8**, i8*** %5
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
store i8* %32, i8** %36
ret void
}

LLVM IR (-O2):
define void @tildeReplacer(i8** nocapture %0, i32 %1, i8* %2, i32 %3) {
%5 = sext i32 %1 to i64
%6 = getelementptr inbounds i8*, i8** %0, i64 %5
%7 = load i8*, i8** %6
%8 = tail call i64 @strlen(i8* dereferenceable(1) %7)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%10 = add nsw i64 %9, %8
%11 = tail call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @strcpy(i8* %12, i8* %2)
%14 = sext i32 %3 to i64
%15 = getelementptr inbounds i8, i8* %7, i64 %14
%16 = tail call i32 @strcat(i8* %12, i8* %15)
store i8* %12, i8** %6
ret void
}