#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 const *);
scalar_t__ strlen(char const *);
char *load_noinstall_path(const char *arg, int pathlen) {
  char *newarg, *expanded_path;
  int newpathlen;
  newarg = (char *)malloc(strlen(arg) + 10);
  strcpy(newarg, arg);
  newarg[pathlen] = 0;
  newpathlen = pathlen;
  strcat(newarg, ".libs");
  newpathlen += sizeof(".libs") - 1;
  newarg[newpathlen] = 0;
  expanded_path = newarg;
  return expanded_path;
}


x86 assembly (clang, -O0):
<load_noinstall_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0xa,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1060 <strcat@plt>
movslq -0x24(%rbp),%rax
add    $0x5,%rax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_noinstall_path>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0xa(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
movslq %r14d,%rbx
movb   $0x0,0x0(%rbp,%rbx,1)
lea    0xe8b(%rip),%rsi
mov    %rbp,%rdi
call   1060 <strcat@plt>
add    $0x5,%ebx
movslq %ebx,%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c".libs\00"
define i8* @load_noinstall_path(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 10
%11 = call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = load i8*, i8** %3
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = load i8*, i8** %5
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
%20 = load i32, i32* %4
store i32 %20, i32* %7
%21 = load i8*, i8** %5
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = add i64 %24, 5
%26 = trunc i64 %25 to i32
store i32 %26, i32* %7
%27 = load i8*, i8** %5
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %5
store i8* %31, i8** %6
%32 = load i8*, i8** %6
ret i8* %32
}

LLVM IR (-O2):
@.str = [6 x i8] c".libs\00"
define i8* @load_noinstall_path(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add nsw i64 %3, 10
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @strcpy(i8* %6, i8* %0)
%8 = sext i32 %1 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
store i8 0, i8* %9
%10 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = add i32 %1, 5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %6, i64 %12
store i8 0, i8* %13
ret i8* %6
}