#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 *calloc(scalar_t__, int);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
char *path_append(const char *basedir, const char *append) {
  char *r = calloc(strlen(basedir) + strlen(append) + 1 + 1, sizeof(char));
  char sep[] = {'/'};
  strcat(r, basedir);
  strcat(r, sep);
  strcat(r, append);
  return r;
}


x86 assembly (clang, -O0):
<path_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    0xe87(%rip),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    -0x19(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_append>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
movb   $0x2f,0xf(%rsp)
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
lea    0xf(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.path_append.sep = [1 x i8] c"/"
define i8* @path_append(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %8, %10
%12 = add nsw i64 %11, 1
%13 = add nsw i64 %12, 1
%14 = call i8* @calloc(i64 %13, i32 1)
store i8* %14, i8** %5
%15 = bitcast [1 x i8]* %6 to i8*
%16 = load i8*, i8** %5
%17 = load i8*, i8** %3
%18 = call i32 @strcat(i8* %16, i8* %17)
%19 = load i8*, i8** %5
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %5
%23 = load i8*, i8** %4
%24 = call i32 @strcat(i8* %22, i8* %23)
%25 = load i8*, i8** %5
ret i8* %25
}

LLVM IR (-O2):
define i8* @path_append(i8* %0, i8* %1) {
%3 = alloca [1 x i8]
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add i64 %4, 2
%7 = add i64 %6, %5
%8 = tail call i8* @calloc(i64 %7, i32 1)
%9 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
store i8 47, i8* %9
%10 = tail call i32 @strcat(i8* %8, i8* %0)
%11 = call i32 @strcat(i8* %8, i8* %9)
%12 = call i32 @strcat(i8* %8, i8* %1)
ret i8* %8
}