#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 /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
void joinPath(char *destination, const char *path1, const char *path2) {
  if (path1 == NULL && path2 == NULL) {
    strcpy(destination, "");
    ;
  } else if (path2 == NULL || strlen(path2) == 0) {
    strcpy(destination, path1);
  } else if (path1 == NULL || strlen(path1) == 0) {
    strcpy(destination, path2);
  } else {
    char directory_separator[] = "/";
    const char *last_char = path1;
    while (*last_char != '\0')
      last_char++;
    int append_directory_separator = 0;
    if (strcmp(last_char, directory_separator) != 0) {
      append_directory_separator = 1;
    }
    strcpy(destination, path1);
    if (append_directory_separator)
      strcat(destination, directory_separator);
    strcat(destination, path2);
  }
}


x86 assembly (clang, -O0):
<joinPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117f <joinPath+0x3f>
cmpq   $0x0,-0x18(%rbp)
jne    117f <joinPath+0x3f>
mov    -0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1273 <joinPath+0x133>
cmpq   $0x0,-0x18(%rbp)
je     119d <joinPath+0x5d>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11af <joinPath+0x6f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    126e <joinPath+0x12e>
cmpq   $0x0,-0x10(%rbp)
je     11cd <joinPath+0x8d>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11df <joinPath+0x9f>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1269 <joinPath+0x129>
mov    0xe1a(%rip),%ax
mov    %ax,-0x1a(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1213 <joinPath+0xd3>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11f2 <joinPath+0xb2>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1238 <joinPath+0xf8>
movl   $0x1,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x2c(%rbp)
je     125c <joinPath+0x11c>
mov    -0x8(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
jmp    126e <joinPath+0x12e>
jmp    1273 <joinPath+0x133>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joinPath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsi,%rax
or     %rdx,%rax
jne    1152 <joinPath+0x22>
lea    0xeb6(%rip),%rsi
mov    %r14,%rdi
jmp    11d9 <joinPath+0xa9>
mov    %rdx,%r15
mov    %rsi,%rbx
test   %rdx,%rdx
je     11cb <joinPath+0x9b>
cmpb   $0x0,(%r15)
je     11cb <joinPath+0x9b>
test   %rbx,%rbx
je     11d3 <joinPath+0xa3>
cmpb   $0x0,(%rbx)
je     11d3 <joinPath+0xa3>
movw   $0x2f,0x6(%rsp)
mov    %rbx,%rdi
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rdi)
lea    0x1(%rdi),%rdi
jne    1180 <joinPath+0x50>
lea    0x6(%rsp),%rsi
call   1040 <strcmp@plt>
mov    %rax,%r12
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
test   %r12,%r12
je     11b4 <joinPath+0x84>
lea    0x6(%rsp),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
mov    %rbx,%rsi
jmp    11d9 <joinPath+0xa9>
mov    %r14,%rdi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@__const.joinPath.directory_separator = [2 x i8] c"/\00"
define void @joinPath(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [2 x i8]
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %73
18: ; preds = %12, %3
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = call i64 @strlen(i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %21, %18
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = call i32 @strcpy(i8* %26, i8* %27)
br label %72
29: ; preds = %21
%30 = load i8*, i8** %5
%31 = icmp eq i8* %30, null
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = load i8*, i8** %5
%34 = call i64 @strlen(i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %32, %29
%37 = load i8*, i8** %4
%38 = load i8*, i8** %6
%39 = call i32 @strcpy(i8* %37, i8* %38)
br label %71
40: ; preds = %32
%41 = bitcast [2 x i8]* %7 to i8*
%42 = load i8*, i8** %5
store i8* %42, i8** %8
br label %43
43: ; preds = %48, %40
%44 = load i8*, i8** %8
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %43
%49 = load i8*, i8** %8
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %8
br label %43
51: ; preds = %43
store i32 0, i32* %9
%52 = load i8*, i8** %8
%53 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%54 = call i64 @strcmp(i8* %52, i8* %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %51
store i32 1, i32* %9
br label %57
57: ; preds = %56, %51
%58 = load i8*, i8** %4
%59 = load i8*, i8** %5
%60 = call i32 @strcpy(i8* %58, i8* %59)
%61 = load i32, i32* %9
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %57
%64 = load i8*, i8** %4
%65 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 0
%66 = call i32 @strcat(i8* %64, i8* %65)
br label %67
67: ; preds = %63, %57
%68 = load i8*, i8** %4
%69 = load i8*, i8** %6
%70 = call i32 @strcat(i8* %68, i8* %69)
br label %71
71: ; preds = %67, %36
br label %72
72: ; preds = %71, %25
br label %73
73: ; preds = %72, %15
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define void @joinPath(i8* %0, i8* %1, i8* %2) {
%4 = alloca i16
%5 = icmp eq i8* %1, null
%6 = icmp eq i8* %2, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %37
10: ; preds = %3
br i1 %6, label %14, label %11
11: ; preds = %10
%12 = load i8, i8* %2
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11, %10
%15 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %37
16: ; preds = %11
br i1 %5, label %20, label %17
17: ; preds = %16
%18 = load i8, i8* %1
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17, %16
%21 = tail call i32 @strcpy(i8* %0, i8* %2)
br label %37
22: ; preds = %17
%23 = bitcast i16* %4 to i8*
store i16 47, i16* %4
br label %24
24: ; preds = %22, %24
%25 = phi i8* [ %1, %22 ], [ %26, %24 ]
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %24
29: ; preds = %24
%30 = call i64 @strcmp(i8* %26, i8* %23)
%31 = icmp eq i64 %30, 0
%32 = call i32 @strcpy(i8* %0, i8* %1)
br i1 %31, label %35, label %33
33: ; preds = %29
%34 = call i32 @strcat(i8* %0, i8* %23)
br label %35
35: ; preds = %33, %29
%36 = call i32 @strcat(i8* %0, i8* %2)
br label %37
37: ; preds = %14, %35, %20, %8
ret void
}