#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);
int /*<<< orphan*/ memset(char *, char, int);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *mergePath(const char *path, const char *file) {
  int totalLen = strlen(path) + strlen(file) + 2;
  int pathLen = strlen(path);
  char *merged = malloc(sizeof(char) * totalLen);
  memset(merged, '\0', totalLen);
  strncpy(merged, path, pathLen);
  strncpy(&merged[pathLen + 1], file, strlen(file));
  merged[pathLen] = '/';
  return merged;
}


x86 assembly (clang, -O0):
<mergePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mergePath>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%ebp
add    $0x2,%ebp
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movslq %r15d,%rbp
lea    (%rbx,%rbp,1),%r15
add    $0x1,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
movb   $0x2f,(%rbx,%rbp,1)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @mergePath(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)
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %9, %11
%13 = add nsw i32 %12, 2
store i32 %13, i32* %5
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i32, i32* %5
%23 = call i32 @memset(i8* %21, i8 signext 0, i32 %22)
%24 = load i8*, i8** %7
%25 = load i8*, i8** %3
%26 = load i32, i32* %6
%27 = call i32 @strncpy(i8* %24, i8* %25, i32 %26)
%28 = load i8*, i8** %7
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8*, i8** %4
%34 = load i8*, i8** %4
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @strncpy(i8* %32, i8* %33, i32 %35)
%37 = load i8*, i8** %7
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 47, i8* %40
%41 = load i8*, i8** %7
ret i8* %41
}

LLVM IR (-O2):
define i8* @mergePath(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add i32 %3, 2
%6 = add i32 %5, %4
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i8* @malloc(i32 %6)
%9 = tail call i32 @memset(i8* %8, i8 signext 0, i32 %6)
%10 = tail call i32 @strncpy(i8* %8, i8* %0, i32 %7)
%11 = add nsw i32 %7, 1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %8, i64 %12
%14 = tail call i32 @strlen(i8* %1)
%15 = tail call i32 @strncpy(i8* %13, i8* %1, i32 %14)
%16 = sext i32 %7 to i64
%17 = getelementptr inbounds i8, i8* %8, i64 %16
store i8 47, i8* %17
ret i8* %8
}