#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 *basname(char const *);
char *dirname(char const *);
int /*<<< orphan*/ free(char *);
char *vstrcat(char *, char *, char const *, char *, char *, char *,
              char const *, int /*<<< orphan*/ *);
char *mkfn(const char *name, const char *dir, const char *ext) {
  char *dn = dirname(name);
  char *bn = basname(name);
  char *fn =
      vstrcat(dn, "/", (dir && *dir ? dir : "."), "/", bn, ".", ext, NULL);
  free(dn);
  free(bn);
  return fn;
}


x86 assembly (clang, -O0):
<mkfn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <dirname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <basname@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119e <mkfn+0x5e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119e <mkfn+0x5e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11ae <mkfn+0x6e>
lea    0xe5d(%rip),%rax
mov    %rax,-0x40(%rbp)
jmp    11ae <mkfn+0x6e>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
mov    -0x28(%rbp),%r8
mov    -0x18(%rbp),%rax
lea    0xe3b(%rip),%rcx
lea    0xe36(%rip),%r9
xor    %esi,%esi
mov    %rcx,%rsi
mov    %rax,(%rsp)
movq   $0x0,0x8(%rsp)
call   1060 <vstrcat@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkfn>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r13
mov    %rdi,%rbx
call   1040 <dirname@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <basname@plt>
mov    %rax,%r12
test   %r13,%r13
je     117c <mkfn+0x3c>
cmpb   $0x0,0x0(%r13)
lea    0xe8c(%rip),%rdx
cmovne %r13,%rdx
jmp    1183 <mkfn+0x43>
lea    0xe7f(%rip),%rdx
lea    0xe76(%rip),%rcx
lea    0xe71(%rip),%r9
mov    %r15,%rdi
mov    %rcx,%rsi
mov    %r12,%r8
push   $0x0
push   %r14
call   1060 <vstrcat@plt>
add    $0x10,%rsp
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define i8* @mkfn(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call i8* @dirname(i8* %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %4
%13 = call i8* @basname(i8* %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %7
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %24
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = load i8*, i8** %5
br label %25
24: ; preds = %17, %3
br label %25
25: ; preds = %24, %22
%26 = phi i8* [ %23, %22 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %24 ]
%27 = load i8*, i8** %8
%28 = load i8*, i8** %6
%29 = call i8* @vstrcat(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32* null)
store i8* %29, i8** %9
%30 = load i8*, i8** %7
%31 = call i32 @free(i8* %30)
%32 = load i8*, i8** %8
%33 = call i32 @free(i8* %32)
%34 = load i8*, i8** %9
ret i8* %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
define i8* @mkfn(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* @dirname(i8* %0)
%5 = tail call i8* @basname(i8* %0)
%6 = icmp eq i8* %1, null
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %1
br label %11
11: ; preds = %7, %3
%12 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %3 ], [ %10, %7 ]
%13 = tail call i8* @vstrcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32* null)
%14 = tail call i32 @free(i8* %4)
%15 = tail call i32 @free(i8* %5)
ret i8* %13
}