#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *dir_path(char *temp, char *parent, char *child) {
  int len;
  temp = (char *)calloc(strlen(parent) + strlen(child) + 5, sizeof(char *));
  strcpy(temp, parent);
  strcat(temp, child);
  len = strlen(temp);
  if (*(temp + len - 1) != '/') {
    *(temp + len) = '/';
    *(temp + len + 1) = '\0';
  }
  return temp;
}


x86 assembly (clang, -O0):
<dir_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%edi
add    %eax,%edi
add    $0x5,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl -0x1(%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11d4 <dir_path+0x94>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_path>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x5,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rbx,%rax,1)
je     119d <dir_path+0x5d>
movw   $0x2f,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @dir_path(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
%10 = load i8*, i8** %6
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %9, %11
%13 = add nsw i32 %12, 5
%14 = call i64 @calloc(i32 %13, i32 8)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %4
%20 = load i8*, i8** %6
%21 = call i32 @strcat(i8* %19, i8* %20)
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %7
%24 = load i8*, i8** %4
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 -1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 47
br i1 %31, label %32, label %42
32: ; preds = %3
%33 = load i8*, i8** %4
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
store i8 47, i8* %36
%37 = load i8*, i8** %4
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = getelementptr inbounds i8, i8* %40, i64 1
store i8 0, i8* %41
br label %42
42: ; preds = %32, %3
%43 = load i8*, i8** %4
ret i8* %43
}

LLVM IR (-O2):
define i8* @dir_path(i8* nocapture readnone %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %1)
%5 = tail call i32 @strlen(i8* %2)
%6 = add i32 %4, 5
%7 = add i32 %6, %5
%8 = tail call i64 @calloc(i32 %7, i32 8)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @strcpy(i8* %9, i8* %1)
%11 = tail call i32 @strcat(i8* %9, i8* %2)
%12 = tail call i32 @strlen(i8* %9)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %9, i64 %13
%15 = getelementptr inbounds i8, i8* %14, i64 -1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 47
br i1 %17, label %20, label %18
18: ; preds = %3
store i8 47, i8* %14
%19 = getelementptr inbounds i8, i8* %14, i64 1
store i8 0, i8* %19
br label %20
20: ; preds = %18, %3
ret i8* %9
}