#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 *e_mkfilename(char *dr, char *fn) {
  char *fl;
  if (!fn)
    return (NULL);
  if (!dr) {
    fl = malloc(strlen(fn) + 1);
    strcpy(fl, fn);
    return (fl);
  }
  fl = malloc(strlen(dr) + strlen(fn) + 2);
  strcpy(fl, dr);
  if (dr[0] != '\0' && dr[strlen(dr) - 1] != '/')
    strcat(fl, "/");
  strcat(fl, fn);
  return (fl);
}


x86 assembly (clang, -O0):
<e_mkfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <e_mkfilename+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1236 <e_mkfilename+0xf6>
cmpq   $0x0,-0x10(%rbp)
jne    11a4 <e_mkfilename+0x64>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1236 <e_mkfilename+0xf6>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
add    %eax,%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1221 <e_mkfilename+0xe1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1221 <e_mkfilename+0xe1>
mov    -0x20(%rbp),%rdi
lea    0xde4(%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):
<e_mkfilename>:
push   %r15
push   %r14
push   %rbx
test   %rsi,%rsi
je     11b4 <e_mkfilename+0x74>
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     11b9 <e_mkfilename+0x79>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
cmpb   $0x0,(%rbx)
je     11a7 <e_mkfilename+0x67>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     11a7 <e_mkfilename+0x67>
lea    0xe61(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
jmp    11d7 <e_mkfilename+0x97>
xor    %r15d,%r15d
jmp    11d7 <e_mkfilename+0x97>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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