#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 */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void appendPathComponent(char *buf, char *source, char *append) {
  char *new_string = (char *)malloc(strlen(source) + strlen(append) + 2);
  strcpy(new_string, source);
  while (*new_string++)
    ;
  new_string -= 2;
  if (*new_string != '/') {
    new_string++;
    *new_string = '/';
  }
  new_string++;
  while (*new_string++ = *append++)
    ;
  strcpy(buf, new_string);
}


x86 assembly (clang, -O0):
<appendPathComponent>:
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   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
cmpb   $0x0,(%rax)
je     1198 <appendPathComponent+0x68>
jmp    117b <appendPathComponent+0x4b>
mov    -0x20(%rbp),%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11c7 <appendPathComponent+0x97>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     1202 <appendPathComponent+0xd2>
jmp    11d3 <appendPathComponent+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appendPathComponent>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1180 <appendPathComponent+0x50>
cmpb   $0x2f,-0x1(%rbx)
jne    1196 <appendPathComponent+0x66>
add    $0xffffffffffffffff,%rbx
jmp    1199 <appendPathComponent+0x69>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
nopl   (%rax)
movzbl (%r15),%eax
add    $0x1,%r15
mov    %al,(%rbx)
add    $0x1,%rbx
test   %al,%al
jne    11a0 <appendPathComponent+0x70>
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

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

LLVM IR (-O2):
define void @appendPathComponent(i8* %0, i8* %1, i8* nocapture %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 i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @strcpy(i8* %9, i8* %1)
br label %11
11: ; preds = %11, %3
%12 = phi i8* [ %9, %3 ], [ %13, %11 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %12
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %11
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %12, i64 -1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 47
br i1 %19, label %21, label %20
20: ; preds = %16
store i8 47, i8* %12
br label %21
21: ; preds = %20, %16
%22 = phi i8* [ %12, %20 ], [ %17, %16 ]
%23 = getelementptr inbounds i8, i8* %22, i64 1
br label %24
24: ; preds = %24, %21
%25 = phi i8* [ %2, %21 ], [ %27, %24 ]
%26 = phi i8* [ %23, %21 ], [ %29, %24 ]
%27 = getelementptr inbounds i8, i8* %25, i64 1
%28 = load i8, i8* %25
%29 = getelementptr inbounds i8, i8* %26, i64 1
store i8 %28, i8* %26
%30 = icmp eq i8 %28, 0
br i1 %30, label %31, label %24
31: ; preds = %24
%32 = tail call i32 @strcpy(i8* %0, i8* %29)
ret void
}