#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 *m_makepath(char *dir, char *file) {
  int dirlen, filelen;
  char *path;
  dirlen = strlen(dir);
  filelen = strlen(file);
  path = malloc(dirlen + 1 + filelen + 1);
  if (path) {
    strcpy(path, dir);
    if (dirlen > 0 && dir[dirlen - 1] != '/')
      strcat(path, "/");
    strcat(path, file);
  }
  return path;
}


x86 assembly (clang, -O0):
<m_makepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
add    -0x18(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d6 <m_makepath+0x96>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
cmpl   $0x0,-0x14(%rbp)
jle    11c9 <m_makepath+0x89>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11c9 <m_makepath+0x89>
mov    -0x20(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_makepath>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r12,%rax,1),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a7 <m_makepath+0x67>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
test   %r12d,%r12d
jle    119c <m_makepath+0x5c>
add    $0xffffffff,%r12d
cmpb   $0x2f,(%r15,%r12,1)
je     119c <m_makepath+0x5c>
lea    0xe6c(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @m_makepath(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 i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %22, label %9
9: ; preds = %2
%10 = tail call i32 @strcpy(i8* %7, i8* %0)
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = add nsw i32 %3, -1
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 47
br i1 %17, label %20, label %18
18: ; preds = %12
%19 = tail call i32 @strcat(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %12, %9
%21 = tail call i32 @strcat(i8* %7, i8* %1)
br label %22
22: ; preds = %20, %2
ret i8* %7
}