#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__ endswith(char *, char);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
void join(char *result, char *dirname, char *basename) {
  size_t dirname_length;
  size_t basename_length;
  dirname_length = strlen(dirname);
  basename_length = strlen(basename);
  if (endswith(dirname, '/') && dirname_length > 1) {
    dirname_length--;
  }
  strncpy(result, dirname, dirname_length);
  result[dirname_length] = '/';
  strncpy(result + dirname_length + 1, basename, basename_length);
  result[dirname_length + basename_length + 1] = '\0';
}


x86 assembly (clang, -O0):
<join>:
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   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <endswith@plt>
cmp    $0x0,%rax
je     118d <join+0x5d>
cmpq   $0x1,-0x20(%rbp)
jbe    118d <join+0x5d>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@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   1030 <strncpy@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>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
mov    %r13,%rdi
mov    $0x2f,%esi
call   1040 <endswith@plt>
test   %rax,%rax
setne  %al
cmp    $0x2,%rbx
setae  %cl
and    %al,%cl
movzbl %cl,%eax
sub    %rax,%rbx
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x2f,(%r15,%rbx,1)
lea    (%r15,%rbx,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
add    %r12,%rbx
movb   $0x0,0x1(%r15,%rbx,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @join(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** %5
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %7
%11 = load i8*, i8** %6
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %8
%13 = load i8*, i8** %5
%14 = call i64 @endswith(i8* %13, i8 signext 47)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %3
%17 = load i64, i64* %7
%18 = icmp ugt i64 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i64, i64* %7
%21 = add i64 %20, -1
store i64 %21, i64* %7
br label %22
22: ; preds = %19, %16, %3
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = load i64, i64* %7
%26 = call i32 @strncpy(i8* %23, i8* %24, i64 %25)
%27 = load i8*, i8** %4
%28 = load i64, i64* %7
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 47, i8* %29
%30 = load i8*, i8** %4
%31 = load i64, i64* %7
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8*, i8** %6
%35 = load i64, i64* %8
%36 = call i32 @strncpy(i8* %33, i8* %34, i64 %35)
%37 = load i8*, i8** %4
%38 = load i64, i64* %7
%39 = load i64, i64* %8
%40 = add i64 %38, %39
%41 = add i64 %40, 1
%42 = getelementptr inbounds i8, i8* %37, i64 %41
store i8 0, i8* %42
ret void
}

LLVM IR (-O2):
define void @join(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = tail call i64 @endswith(i8* %1, i8 signext 47)
%7 = icmp ne i64 %6, 0
%8 = icmp ugt i64 %4, 1
%9 = select i1 %7, i1 %8, i1 false
%10 = sext i1 %9 to i64
%11 = add i64 %4, %10
%12 = tail call i32 @strncpy(i8* %0, i8* %1, i64 %11)
%13 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 47, i8* %13
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = tail call i32 @strncpy(i8* %14, i8* %2, i64 %5)
%16 = add i64 %5, 1
%17 = add i64 %16, %11
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 0, i8* %18
ret void
}