#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void join_path(char *destination, char *first, char *second) {
  memset(destination, 0, 255);
  if (first != NULL && strlen(first) > 0) {
    strcpy(destination, first);
    if (destination[strlen(destination) - 1] != '/') {
      int l = strlen(destination);
      destination[l] = '/';
      destination[l + 1] = '\0';
    }
  }
  strcat(destination, second);
}


x86 assembly (clang, -O0):
<join_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11e6 <join_path+0xa6>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    11e6 <join_path+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11e1 <join_path+0xa1>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11e6 <join_path+0xa6>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_path>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0xff,%edx
call   1050 <memset@plt>
test   %r15,%r15
je     1197 <join_path+0x57>
mov    %r15,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1197 <join_path+0x57>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     1197 <join_path+0x57>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movw   $0x2f,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <strcat@plt>

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

LLVM IR (-O2):
define void @join_path(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @memset(i8* %0, i32 0, i32 255)
%5 = icmp eq i8* %1, null
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %6
%10 = tail call i32 @strcpy(i8* %0, i8* %1)
%11 = tail call i32 @strlen(i8* %0)
%12 = add nsw i32 %11, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 47
br i1 %16, label %24, label %17
17: ; preds = %9
%18 = tail call i32 @strlen(i8* %0)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 47, i8* %20
%21 = add nsw i32 %18, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %9, %17, %6, %3
%25 = tail call i32 @strcat(i8* %0, i8* %2)
ret void
}