#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *makePath(char *path, char *filename) {
  if (path[0] == '.')
    return filename;
  char *result = malloc(1000);
  strcpy(result, path);
  if (result[strlen(result) - 1] != '/')
    strcat(result, "/");
  strcat(result, filename);
  return result;
}


x86 assembly (clang, -O0):
<makePath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    116d <makePath+0x2d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <makePath+0x97>
mov    $0x3e8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11c2 <makePath+0x82>
mov    -0x20(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makePath>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
cmpb   $0x2e,(%rdi)
jne    1152 <makePath+0x12>
mov    %r14,%rbx
jmp    1198 <makePath+0x58>
mov    %rdi,%r15
mov    $0x3e8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     118d <makePath+0x4d>
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @makePath(i8* %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 46
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = tail call dereferenceable_or_null(1000) i8* @malloc(i32 1000)
%7 = tail call i32 @strcpy(i8* %6, i8* %0)
%8 = tail call i32 @strlen(i8* %6)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %16, label %14
14: ; preds = %5
%15 = tail call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %5
%17 = tail call i32 @strcat(i8* %6, i8* %1)
br label %18
18: ; preds = %2, %16
%19 = phi i8* [ %6, %16 ], [ %1, %2 ]
ret i8* %19
}