#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 SIZE_MAX;
int /*<<< orphan*/ assert(int);
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *path_join(const char *first, const char *second) {
  size_t flen = strlen(first);
  size_t slen = strlen(second);
  do {
    assert(flen <= SIZE_MAX - 2);
  } while (0);
  do {
    assert(flen + 2 <= SIZE_MAX - slen);
  } while (0);
  size_t len = flen + slen + 1;
  char *rv = malloc(len + 1);
  do {
    assert(rv != NULL);
  } while (0);
  memcpy(rv, first, flen);
  rv[flen] = '/';
  memcpy(rv + flen + 1, second, slen);
  rv[len] = '\0';
  return rv;
}


x86 assembly (clang, -O0):
<path_join>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e63(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
jmp    1192 <path_join+0x52>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    0x2e37(%rip),%rcx
movslq (%rcx),%rcx
sub    -0x20(%rbp),%rcx
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
add    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_join>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%r13
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
mov    0x2e6d(%rip),%rbx
movslq (%rbx),%rax
add    $0xfffffffffffffffe,%rax
xor    %edi,%edi
cmp    %rax,%r13
setbe  %dil
call   1040 <assert@plt>
lea    0x2(%r13),%rax
movslq (%rbx),%rcx
sub    %r12,%rcx
xor    %edi,%edi
cmp    %rcx,%rax
setbe  %dil
call   1040 <assert@plt>
lea    (%r12,%r13,1),%rbp
lea    (%r12,%r13,1),%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <memcpy@plt>
movb   $0x2f,(%rbx,%r13,1)
lea    (%rbx,%r13,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
movb   $0x0,0x1(%rbx,%rbp,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SIZE_MAX = global i32 0
define i8* @path_join(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %5
%11 = load i8*, i8** %4
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %6
br label %13
13: ; preds = %2
%14 = load i64, i64* %5
%15 = load i32, i32* @SIZE_MAX
%16 = sub nsw i32 %15, 2
%17 = sext i32 %16 to i64
%18 = icmp ule i64 %14, %17
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
br label %21
21: ; preds = %13
br label %22
22: ; preds = %21
%23 = load i64, i64* %5
%24 = add i64 %23, 2
%25 = load i32, i32* @SIZE_MAX
%26 = sext i32 %25 to i64
%27 = load i64, i64* %6
%28 = sub i64 %26, %27
%29 = icmp ule i64 %24, %28
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
br label %32
32: ; preds = %22
%33 = load i64, i64* %5
%34 = load i64, i64* %6
%35 = add i64 %33, %34
%36 = add i64 %35, 1
store i64 %36, i64* %7
%37 = load i64, i64* %7
%38 = add i64 %37, 1
%39 = call i8* @malloc(i64 %38)
store i8* %39, i8** %8
br label %40
40: ; preds = %32
%41 = load i8*, i8** %8
%42 = icmp ne i8* %41, null
%43 = zext i1 %42 to i32
%44 = call i32 @assert(i32 %43)
br label %45
45: ; preds = %40
%46 = load i8*, i8** %8
%47 = load i8*, i8** %3
%48 = load i64, i64* %5
%49 = call i32 @memcpy(i8* %46, i8* %47, i64 %48)
%50 = load i8*, i8** %8
%51 = load i64, i64* %5
%52 = getelementptr inbounds i8, i8* %50, i64 %51
store i8 47, i8* %52
%53 = load i8*, i8** %8
%54 = load i64, i64* %5
%55 = getelementptr inbounds i8, i8* %53, i64 %54
%56 = getelementptr inbounds i8, i8* %55, i64 1
%57 = load i8*, i8** %4
%58 = load i64, i64* %6
%59 = call i32 @memcpy(i8* %56, i8* %57, i64 %58)
%60 = load i8*, i8** %8
%61 = load i64, i64* %7
%62 = getelementptr inbounds i8, i8* %60, i64 %61
store i8 0, i8* %62
%63 = load i8*, i8** %8
ret i8* %63
}

LLVM IR (-O2):
@SIZE_MAX = global i32 0
define i8* @path_join(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = load i32, i32* @SIZE_MAX
%6 = add nsw i32 %5, -2
%7 = sext i32 %6 to i64
%8 = icmp ule i64 %3, %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = add i64 %3, 2
%12 = load i32, i32* @SIZE_MAX
%13 = sext i32 %12 to i64
%14 = sub i64 %13, %4
%15 = icmp ule i64 %11, %14
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = add i64 %4, %3
%19 = add i64 %18, 1
%20 = add i64 %18, 2
%21 = tail call i8* @malloc(i64 %20)
%22 = icmp ne i8* %21, null
%23 = zext i1 %22 to i32
%24 = tail call i32 @assert(i32 %23)
%25 = tail call i32 @memcpy(i8* %21, i8* %0, i64 %3)
%26 = getelementptr inbounds i8, i8* %21, i64 %3
store i8 47, i8* %26
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = tail call i32 @memcpy(i8* %27, i8* %1, i64 %4)
%29 = getelementptr inbounds i8, i8* %21, i64 %19
store i8 0, i8* %29
ret i8* %21
}