#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*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *pathAppend(const char *path, const char *path2) {
  size_t pathLen = strlen(path);
  size_t additionalSpace = 0;
  if (path[pathLen - 1] != '/')
    additionalSpace = 1;
  char *newPath = malloc(pathLen + strlen(path2) + additionalSpace + 1);
  strcpy(newPath, path);
  if (additionalSpace)
    newPath[pathLen] = '/';
  strcpy(newPath + pathLen + additionalSpace, path2);
  return newPath;
}


x86 assembly (clang, -O0):
<pathAppend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1176 <pathAppend+0x46>
movq   $0x1,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x20(%rbp)
je     11c3 <pathAppend+0x93>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathAppend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%r15
mov    -0x1(%rax,%r12,1),%bpl
xor    %r13d,%r13d
cmp    $0x2f,%bpl
setne  %r13b
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r15,%rax
lea    (%rax,%r13,1),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
cmp    $0x2f,%bpl
je     118a <pathAppend+0x5a>
movb   $0x2f,(%rbx,%r15,1)
mov    %rbx,%rdi
add    %r15,%rdi
add    %r13,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @pathAppend(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %5
store i64 0, i64* %6
%10 = load i8*, i8** %3
%11 = load i64, i64* %5
%12 = sub i64 %11, 1
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 47
br i1 %16, label %17, label %18
17: ; preds = %2
store i64 1, i64* %6
br label %18
18: ; preds = %17, %2
%19 = load i64, i64* %5
%20 = load i8*, i8** %4
%21 = call i64 @strlen(i8* %20)
%22 = add i64 %19, %21
%23 = load i64, i64* %6
%24 = add i64 %22, %23
%25 = add i64 %24, 1
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = load i8*, i8** %3
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i64, i64* %6
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %18
%33 = load i8*, i8** %7
%34 = load i64, i64* %5
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8 47, i8* %35
br label %36
36: ; preds = %32, %18
%37 = load i8*, i8** %7
%38 = load i64, i64* %5
%39 = getelementptr inbounds i8, i8* %37, i64 %38
%40 = load i64, i64* %6
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = load i8*, i8** %4
%43 = call i32 @strcpy(i8* %41, i8* %42)
%44 = load i8*, i8** %7
ret i8* %44
}

LLVM IR (-O2):
define i8* @pathAppend(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add i64 %3, -1
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 47
%8 = xor i1 %7, true
%9 = zext i1 %8 to i64
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = add i64 %3, 1
%12 = add i64 %11, %10
%13 = add i64 %12, %9
%14 = tail call i8* @malloc(i64 %13)
%15 = tail call i32 @strcpy(i8* %14, i8* %0)
br i1 %7, label %18, label %16
16: ; preds = %2
%17 = getelementptr inbounds i8, i8* %14, i64 %3
store i8 47, i8* %17
br label %18
18: ; preds = %16, %2
%19 = getelementptr inbounds i8, i8* %14, i64 %3
%20 = getelementptr inbounds i8, i8* %19, i64 %9
%21 = tail call i32 @strcpy(i8* %20, i8* %1)
ret i8* %14
}