#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 */
char *malloc(int);
char *strcat(char *, char *);
int strlen(char *);
char *pathConcat(char *s1, char *s2) {
  int s1Len = strlen(s1);
  if (s1[s1Len - 1] == '/') {
    s1[s1Len - 1] = '\0';
    s1Len -= 1;
  }
  int s2Len = strlen(s2);
  char *dest = malloc((s1Len + s2Len + 2) * sizeof(char));
  dest[0] = '\0';
  dest = strcat(dest, s1);
  dest = strcat(dest, "/");
  dest = strcat(dest, s2);
  return dest;
}


x86 assembly (clang, -O0):
<pathConcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1180 <pathConcat+0x50>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe37(%rip),%rsi
call   1050 <strcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathConcat>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
cltq
cmpb   $0x2f,-0x1(%r15,%rax,1)
jne    1157 <pathConcat+0x27>
add    $0xffffffffffffffff,%rax
movb   $0x0,(%r15,%rax,1)
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movw   $0x2f,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <strcat@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @pathConcat(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %5
%10 = load i8*, i8** %3
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 47
br i1 %17, label %18, label %26
18: ; preds = %2
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 0, i8* %23
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %5
br label %26
26: ; preds = %18, %2
%27 = load i8*, i8** %4
%28 = call i32 @strlen(i8* %27)
store i32 %28, i32* %6
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = add nsw i32 %29, %30
%32 = add nsw i32 %31, 2
%33 = sext i32 %32 to i64
%34 = mul i64 %33, 1
%35 = trunc i64 %34 to i32
%36 = call i8* @malloc(i32 %35)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 0, i8* %38
%39 = load i8*, i8** %7
%40 = load i8*, i8** %3
%41 = call i8* @strcat(i8* %39, i8* %40)
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = call i8* @strcat(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = load i8*, i8** %4
%46 = call i8* @strcat(i8* %44, i8* %45)
store i8* %46, i8** %7
%47 = load i8*, i8** %7
ret i8* %47
}

LLVM IR (-O2):
define i8* @pathConcat(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 47
br i1 %8, label %9, label %10
9: ; preds = %2
store i8 0, i8* %6
br label %10
10: ; preds = %9, %2
%11 = phi i32 [ %4, %9 ], [ %3, %2 ]
%12 = tail call i32 @strlen(i8* %1)
%13 = add i32 %11, 2
%14 = add i32 %13, %12
%15 = tail call i8* @malloc(i32 %14)
store i8 0, i8* %15
%16 = tail call i8* @strcat(i8* %15, i8* dereferenceable(1) %0)
%17 = tail call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* %15)
%18 = getelementptr i8, i8* %15, i64 %17
%19 = bitcast i8* %18 to i16*
store i16 47, i16* %19
%20 = tail call i8* @strcat(i8* %15, i8* dereferenceable(1) %1)
ret i8* %15
}