#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 errno;
int /*<<< orphan*/ free(char *);
int hlp_path_clean(char *, void *, size_t);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memset(char *, int, size_t);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int hlp_path_join(const char *path1, const char *path2, void *buffer,
                  size_t size) {
  char *aptr = NULL;
  char *auxbuf = NULL;
  size_t buflen;
  int rval;
  buflen = strlen(path1) + strlen(path2) + 2;
  auxbuf = (char *)malloc(buflen);
  if (NULL == auxbuf)
    return errno;
  memset(buffer, (int)'\0', size);
  memset(auxbuf, (int)'\0', buflen);
  aptr = auxbuf;
  strncpy(aptr, path1, strlen(path1));
  aptr += strlen(path1);
  aptr[0] = '/';
  aptr++;
  strncpy(aptr, path2, strlen(path2));
  aptr += strlen(path2);
  aptr[0] = '\0';
  rval = hlp_path_clean(auxbuf, buffer, size);
  free(auxbuf);
  return rval;
}


x86 assembly (clang, -O0):
<hlp_path_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    11d7 <hlp_path_join+0x77>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12bc <hlp_path_join+0x15c>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%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),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <hlp_path_clean@plt>
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hlp_path_join>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1060 <strlen@plt>
add    %ebx,%eax
add    $0x2,%eax
movslq %eax,%rbp
mov    %rbp,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     122c <hlp_path_join+0xcc>
mov    %rax,%rbx
mov    %r15,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1070 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1070 <memset@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%r13
movb   $0x2f,(%rbx,%rax,1)
lea    (%rbx,%rax,1),%rbp
add    $0x1,%rbp
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <strncpy@plt>
mov    %r12,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,0x1(%rax,%r13,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <hlp_path_clean@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    1235 <hlp_path_join+0xd5>
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define i32 @hlp_path_join(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i8* null, i8** %10
store i8* null, i8** %11
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %15, %17
%19 = add nsw i32 %18, 2
%20 = sext i32 %19 to i64
store i64 %20, i64* %12
%21 = load i64, i64* %12
%22 = call i64 @malloc(i64 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %11
%24 = load i8*, i8** %11
%25 = icmp eq i8* null, %24
br i1 %25, label %26, label %28
26: ; preds = %4
%27 = load i32, i32* @errno
store i32 %27, i32* %5
br label %69
28: ; preds = %4
%29 = load i8*, i8** %8
%30 = load i64, i64* %9
%31 = call i32 @memset(i8* %29, i32 0, i64 %30)
%32 = load i8*, i8** %11
%33 = load i64, i64* %12
%34 = call i32 @memset(i8* %32, i32 0, i64 %33)
%35 = load i8*, i8** %11
store i8* %35, i8** %10
%36 = load i8*, i8** %10
%37 = load i8*, i8** %6
%38 = load i8*, i8** %6
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @strncpy(i8* %36, i8* %37, i32 %39)
%41 = load i8*, i8** %6
%42 = call i32 @strlen(i8* %41)
%43 = load i8*, i8** %10
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %43, i64 %44
store i8* %45, i8** %10
%46 = load i8*, i8** %10
%47 = getelementptr inbounds i8, i8* %46, i64 0
store i8 47, i8* %47
%48 = load i8*, i8** %10
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %10
%50 = load i8*, i8** %10
%51 = load i8*, i8** %7
%52 = load i8*, i8** %7
%53 = call i32 @strlen(i8* %52)
%54 = call i32 @strncpy(i8* %50, i8* %51, i32 %53)
%55 = load i8*, i8** %7
%56 = call i32 @strlen(i8* %55)
%57 = load i8*, i8** %10
%58 = sext i32 %56 to i64
%59 = getelementptr inbounds i8, i8* %57, i64 %58
store i8* %59, i8** %10
%60 = load i8*, i8** %10
%61 = getelementptr inbounds i8, i8* %60, i64 0
store i8 0, i8* %61
%62 = load i8*, i8** %11
%63 = load i8*, i8** %8
%64 = load i64, i64* %9
%65 = call i32 @hlp_path_clean(i8* %62, i8* %63, i64 %64)
store i32 %65, i32* %13
%66 = load i8*, i8** %11
%67 = call i32 @free(i8* %66)
%68 = load i32, i32* %13
store i32 %68, i32* %5
br label %69
69: ; preds = %28, %26
%70 = load i32, i32* %5
ret i32 %70
}

LLVM IR (-O2):
@errno = global i32 0
define i32 @hlp_path_join(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @strlen(i8* %1)
%7 = add i32 %5, 2
%8 = add i32 %7, %6
%9 = sext i32 %8 to i64
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = load i32, i32* @errno
br label %31
15: ; preds = %4
%16 = tail call i32 @memset(i8* %2, i32 0, i64 %3)
%17 = tail call i32 @memset(i8* %11, i32 0, i64 %9)
%18 = tail call i32 @strlen(i8* %0)
%19 = tail call i32 @strncpy(i8* %11, i8* %0, i32 %18)
%20 = tail call i32 @strlen(i8* %0)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %11, i64 %21
store i8 47, i8* %22
%23 = getelementptr inbounds i8, i8* %22, i64 1
%24 = tail call i32 @strlen(i8* %1)
%25 = tail call i32 @strncpy(i8* %23, i8* %1, i32 %24)
%26 = tail call i32 @strlen(i8* %1)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
store i8 0, i8* %28
%29 = tail call i32 @hlp_path_clean(i8* %11, i8* %2, i64 %3)
%30 = tail call i32 @free(i8* %11)
br label %31
31: ; preds = %15, %13
%32 = phi i32 [ %14, %13 ], [ %29, %15 ]
ret i32 %32
}