#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 */
int /*<<< orphan*/ memcpy(char *, char const *, size_t const);
int pathname_concat(char *pathname_out, size_t pathname_out_len,
                    const char *pathname_lib, const size_t pathname_lib_len,
                    const char *pathname_module,
                    const size_t pathname_module_len, const char *pathname_ext,
                    const size_t pathname_ext_len) {
  char *pathname_out_p = pathname_out;
  if (pathname_lib_len + pathname_module_len + pathname_ext_len + 1 >
      pathname_out_len) {
    return -1;
  }
  pathname_out_p = pathname_out;
  memcpy(pathname_out_p, pathname_lib, pathname_lib_len);
  pathname_out_p += pathname_lib_len;
  memcpy(pathname_out_p, pathname_module, pathname_module_len);
  pathname_out_p += pathname_module_len;
  *pathname_out_p++ = '.';
  memcpy(pathname_out_p, pathname_ext, pathname_ext_len);
  pathname_out_p += pathname_ext_len;
  *pathname_out_p++ = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<pathname_concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
add    -0x38(%rbp),%rax
add    0x18(%rbp),%rax
add    $0x1,%rax
cmp    -0x18(%rbp),%rax
jbe    1166 <pathname_concat+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <pathname_concat+0xe0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x38(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
movb   $0x2e,(%rax)
mov    -0x40(%rbp),%rdi
mov    0x10(%rbp),%rsi
mov    0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    0x18(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathname_concat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r13
mov    0x48(%rsp),%r14
lea    (%rcx,%r9,1),%rax
lea    (%r14,%rax,1),%rcx
add    $0x1,%rcx
mov    $0xffffffff,%eax
cmp    %rsi,%rcx
ja     1184 <pathname_concat+0x74>
mov    %r9,%r15
mov    %r8,%r12
mov    %rdi,%rbx
mov    %rdx,%rsi
mov    %r13,%rdx
call   1030 <memcpy@plt>
add    %r13,%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <memcpy@plt>
lea    (%rbx,%r15,1),%rbp
lea    (%r15,%rbx,1),%rdi
add    $0x1,%rdi
movb   $0x2e,(%r15,%rbx,1)
mov    0x40(%rsp),%rsi
mov    %r14,%rdx
call   1030 <memcpy@plt>
movb   $0x0,0x1(%r14,%rbp,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pathname_concat(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5, i8* %6, i64 %7) {
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i8*
store i8* %0, i8** %10
store i64 %1, i64* %11
store i8* %2, i8** %12
store i64 %3, i64* %13
store i8* %4, i8** %14
store i64 %5, i64* %15
store i8* %6, i8** %16
store i64 %7, i64* %17
%19 = load i8*, i8** %10
store i8* %19, i8** %18
%20 = load i64, i64* %13
%21 = load i64, i64* %15
%22 = add i64 %20, %21
%23 = load i64, i64* %17
%24 = add i64 %22, %23
%25 = add i64 %24, 1
%26 = load i64, i64* %11
%27 = icmp ugt i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %8
store i32 -1, i32* %9
br label %56
29: ; preds = %8
%30 = load i8*, i8** %10
store i8* %30, i8** %18
%31 = load i8*, i8** %18
%32 = load i8*, i8** %12
%33 = load i64, i64* %13
%34 = call i32 @memcpy(i8* %31, i8* %32, i64 %33)
%35 = load i64, i64* %13
%36 = load i8*, i8** %18
%37 = getelementptr inbounds i8, i8* %36, i64 %35
store i8* %37, i8** %18
%38 = load i8*, i8** %18
%39 = load i8*, i8** %14
%40 = load i64, i64* %15
%41 = call i32 @memcpy(i8* %38, i8* %39, i64 %40)
%42 = load i64, i64* %15
%43 = load i8*, i8** %18
%44 = getelementptr inbounds i8, i8* %43, i64 %42
store i8* %44, i8** %18
%45 = load i8*, i8** %18
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %18
store i8 46, i8* %45
%47 = load i8*, i8** %18
%48 = load i8*, i8** %16
%49 = load i64, i64* %17
%50 = call i32 @memcpy(i8* %47, i8* %48, i64 %49)
%51 = load i64, i64* %17
%52 = load i8*, i8** %18
%53 = getelementptr inbounds i8, i8* %52, i64 %51
store i8* %53, i8** %18
%54 = load i8*, i8** %18
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %18
store i8 0, i8* %54
store i32 0, i32* %9
br label %56
56: ; preds = %29, %28
%57 = load i32, i32* %9
ret i32 %57
}

LLVM IR (-O2):
define i32 @pathname_concat(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5, i8* %6, i64 %7) {
%9 = add i64 %3, 1
%10 = add i64 %9, %5
%11 = add i64 %10, %7
%12 = icmp ugt i64 %11, %1
br i1 %12, label %21, label %13
13: ; preds = %8
%14 = tail call i32 @memcpy(i8* %0, i8* %2, i64 %3)
%15 = getelementptr inbounds i8, i8* %0, i64 %3
%16 = tail call i32 @memcpy(i8* %15, i8* %4, i64 %5)
%17 = getelementptr inbounds i8, i8* %15, i64 %5
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 46, i8* %17
%19 = tail call i32 @memcpy(i8* %18, i8* %6, i64 %7)
%20 = getelementptr inbounds i8, i8* %18, i64 %7
store i8 0, i8* %20
br label %21
21: ; preds = %8, %13
%22 = phi i32 [ 0, %13 ], [ -1, %8 ]
ret i32 %22
}