#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 *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
void path_concat(char **path, const char *parent, const char *name) {
  size_t len_parent, len_name;
  char *s;
  len_parent = strlen(parent);
  len_name = strlen(name);
  *path = s = malloc(len_parent + len_name + 2);
  memcpy(s, parent, len_parent);
  s += len_parent;
  s[0] = '/';
  s++;
  memcpy(s, name, len_name);
  s += len_name;
  s[0] = 0;
}


x86 assembly (clang, -O0):
<path_concat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x28(%rbp),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_concat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
lea    (%rbx,%rbp,1),%r15
movb   $0x2f,0x0(%rbp,%rbx,1)
lea    (%rbx,%rbp,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   1040 <memcpy@plt>
movb   $0x0,0x1(%r13,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @path_concat(i8** nocapture writeonly %0, i8* %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = add i64 %4, 2
%7 = add i64 %6, %5
%8 = tail call i8* @malloc(i64 %7)
store i8* %8, i8** %0
%9 = tail call i32 @memcpy(i8* %8, i8* %1, i64 %4)
%10 = getelementptr inbounds i8, i8* %8, i64 %4
store i8 47, i8* %10
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = tail call i32 @memcpy(i8* %11, i8* %2, i64 %5)
%13 = getelementptr inbounds i8, i8* %11, i64 %5
store i8 0, i8* %13
ret void
}