#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*/ copy_str(char **, size_t *, char const *);
bool path_join(char *buf, size_t len, const char *path1, const char *path2) {
  if (!copy_str(&buf, &len, path1))
    return false;
  if ((buf[-1] != '/') && (path2[0] != '/')) {
    const char sep[] = {'/', '\0'};
    if (!copy_str(&buf, &len, sep))
      return false;
  }
  if (!copy_str(&buf, &len, path2))
    return false;
  return true;
}


x86 assembly (clang, -O0):
<path_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <copy_str@plt>
cmp    $0x0,%eax
jne    114e <path_join+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <path_join+0xc2>
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
je     11a5 <path_join+0x95>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11a5 <path_join+0x95>
mov    0xe8a(%rip),%ax
mov    %ax,-0x2a(%rbp)
lea    -0x2a(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <copy_str@plt>
cmp    $0x0,%eax
jne    11a0 <path_join+0x90>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <path_join+0xc2>
jmp    11a5 <path_join+0x95>
mov    -0x28(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <copy_str@plt>
cmp    $0x0,%eax
jne    11cb <path_join+0xbb>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <path_join+0xc2>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_join>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdi,0x8(%rsp)
mov    %rsi,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <copy_str@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1181 <path_join+0x71>
mov    0x8(%rsp),%rax
cmpb   $0x2f,-0x1(%rax)
je     1167 <path_join+0x57>
cmpb   $0x2f,(%rbx)
je     1167 <path_join+0x57>
movw   $0x2f,0x6(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x6(%rsp),%rdx
call   1030 <copy_str@plt>
test   %eax,%eax
je     1181 <path_join+0x71>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1030 <copy_str@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.path_join.sep = [2 x i8] c"/\00"
define i32 @path_join(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [2 x i8]
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i8*, i8** %8
%12 = call i32 @copy_str(i8** %6, i64* %7, i8* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %4
store i32 0, i32* %5
br label %40
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 -1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 47
br i1 %20, label %21, label %34
21: ; preds = %15
%22 = load i8*, i8** %9
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 47
br i1 %26, label %27, label %34
27: ; preds = %21
%28 = bitcast [2 x i8]* %10 to i8*
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %10, i64 0, i64 0
%30 = call i32 @copy_str(i8** %6, i64* %7, i8* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %27
store i32 0, i32* %5
br label %40
33: ; preds = %27
br label %34
34: ; preds = %33, %21, %15
%35 = load i8*, i8** %9
%36 = call i32 @copy_str(i8** %6, i64* %7, i8* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %34
store i32 0, i32* %5
br label %40
39: ; preds = %34
store i32 1, i32* %5
br label %40
40: ; preds = %39, %38, %32, %14
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
define i32 @path_join(i8* %0, i64 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i16
store i8* %0, i8** %5
store i64 %1, i64* %6
%8 = call i32 @copy_str(i8** %5, i64* %6, i8* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %4
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %22, label %15
15: ; preds = %10
%16 = load i8, i8* %3
%17 = icmp eq i8 %16, 47
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = bitcast i16* %7 to i8*
store i16 47, i16* %7
%20 = call i32 @copy_str(i8** %5, i64* %6, i8* %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18, %15, %10
%23 = call i32 @copy_str(i8** %5, i64* %6, i8* %3)
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %18, %22, %4
%27 = phi i32 [ 0, %18 ], [ 0, %4 ], [ %25, %22 ]
ret i32 %27
}