#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(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
char *pathToFile(char *directory, char *file) {
  char *filePath = malloc(strlen(directory) + strlen(file) + 2);
  int i;
  for (i = 0; directory[i] != '\0'; i++) {
    if (directory[i + 1] == '\0' && directory[i] != '/')
      strcat(directory, "/");
  }
  strcat(filePath, directory);
  strcat(filePath, file);
  return filePath;
}


x86 assembly (clang, -O0):
<pathToFile>:
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,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11d8 <pathToFile+0xa8>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    11c5 <pathToFile+0x95>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11c5 <pathToFile+0x95>
mov    -0x8(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1050 <strcat@plt>
jmp    11ca <pathToFile+0x9a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <pathToFile+0x41>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathToFile>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x2,%rdi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    0x0(%r13),%cl
test   %cl,%cl
je     11a6 <pathToFile+0x76>
lea    0x1(%r13),%rbx
lea    0xe8e(%rip),%r12
jmp    118a <pathToFile+0x5a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
mov    %eax,%ecx
test   %al,%al
je     11a6 <pathToFile+0x76>
movzbl (%rbx),%eax
test   %al,%al
jne    1180 <pathToFile+0x50>
cmp    $0x2f,%cl
je     1180 <pathToFile+0x50>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
movzbl (%rbx),%eax
jmp    1180 <pathToFile+0x50>
mov    %r15,%rdi
mov    %r13,%rsi
call   1050 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @pathToFile(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %3, 2
%6 = add i64 %5, %4
%7 = tail call i8* @malloc(i64 %6)
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %25, label %10
10: ; preds = %2, %22
%11 = phi i64 [ %13, %22 ], [ 0, %2 ]
%12 = phi i8 [ %23, %22 ], [ %8, %2 ]
%13 = add nuw nsw i64 %11, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
%17 = icmp eq i8 %12, 47
%18 = select i1 %16, i1 true, i1 %17
br i1 %18, label %22, label %19
19: ; preds = %10
%20 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = load i8, i8* %14
br label %22
22: ; preds = %10, %19
%23 = phi i8 [ %15, %10 ], [ %21, %19 ]
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %10
25: ; preds = %22, %2
%26 = tail call i32 @strcat(i8* %7, i8* %0)
%27 = tail call i32 @strcat(i8* %7, i8* %1)
ret i8* %7
}