#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 PATH_MAX;
int /*<<< orphan*/ memcpy(char *, char *, size_t);
size_t strlen(char *);
void join_path(char *out, char *a, char *b) {
  out[0] = '\0';
  size_t len_a = strlen(a);
  size_t len_b = strlen(b);
  if (len_a >= PATH_MAX - 1 || len_b >= PATH_MAX - len_a - 1) {
    return;
  }
  memcpy(out, a, len_a);
  out[len_a] = '/';
  memcpy(out + len_a + 1, b, len_b);
  out[len_a + len_b + 1] = '\0';
}


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),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e90(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    1190 <join_path+0x70>
mov    -0x28(%rbp),%rax
mov    0x2e74(%rip),%rcx
movslq (%rcx),%rcx
sub    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jb     1195 <join_path+0x75>
jmp    11dc <join_path+0xbc>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
add    -0x28(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_path>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
movb   $0x0,(%rdi)
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    0x2e9e(%rip),%rax
movslq (%rax),%rax
lea    -0x1(%rax),%rcx
cmp    %rcx,%rbx
jae    119b <join_path+0x7b>
mov    %rbx,%rcx
not    %rcx
add    %rcx,%rax
cmp    %rax,%r12
jae    119b <join_path+0x7b>
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
movb   $0x2f,(%r15,%rbx,1)
lea    (%r15,%rbx,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
add    %r12,%rbx
movb   $0x0,0x1(%r15,%rbx,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@PATH_MAX = global i32 0
define void @join_path(i8* %0, i8* %1, i8* %2) {
store i8 0, i8* %0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = load i32, i32* @PATH_MAX
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = icmp ult i64 %4, %8
br i1 %9, label %10, label %23
10: ; preds = %3
%11 = sext i32 %6 to i64
%12 = xor i64 %4, -1
%13 = add i64 %11, %12
%14 = icmp ult i64 %5, %13
br i1 %14, label %15, label %23
15: ; preds = %10
%16 = tail call i32 @memcpy(i8* %0, i8* %1, i64 %4)
%17 = getelementptr inbounds i8, i8* %0, i64 %4
store i8 47, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = tail call i32 @memcpy(i8* %18, i8* %2, i64 %5)
%20 = add nuw i64 %4, 1
%21 = add i64 %20, %5
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %3, %10, %15
ret void
}