#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 *mhs_strconcat(char const *, char const *, char const *, ...);
char *mhs_strdup(char const *);
scalar_t__ strchr(char const *, char);
int strlen(char const *);
char *create_file_name(const char *dir, const char *file_name) {
  if ((!dir) || (!file_name))
    return (NULL);
  if (strchr(file_name, '/'))
    return (mhs_strdup(file_name));
  else {
    if (dir[strlen(dir) - 1] == '/')
      return (mhs_strconcat(dir, file_name, NULL));
    else
      return (mhs_strconcat(dir, "/", file_name, NULL));
  }
}


x86 assembly (clang, -O0):
<create_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1166 <create_file_name+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1173 <create_file_name+0x33>
movq   $0x0,-0x8(%rbp)
jmp    1201 <create_file_name+0xc1>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     119d <create_file_name+0x5d>
mov    -0x18(%rbp),%rdi
call   1050 <mhs_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1201 <create_file_name+0xc1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11e3 <create_file_name+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1060 <mhs_strconcat@plt>
mov    %rax,-0x8(%rbp)
jmp    1201 <create_file_name+0xc1>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe0e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1060 <mhs_strconcat@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file_name>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1175 <create_file_name+0x35>
mov    %rsi,%r14
test   %rsi,%rsi
je     1175 <create_file_name+0x35>
mov    %rdi,%rbx
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     117f <create_file_name+0x3f>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <mhs_strdup@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    11a6 <create_file_name+0x66>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <mhs_strconcat@plt>
lea    0xe53(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <mhs_strconcat@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @create_file_name(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %22
6: ; preds = %2
%7 = tail call i64 @strchr(i8* %1, i8 signext 47)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i8* @mhs_strdup(i8* %1)
br label %22
11: ; preds = %6
%12 = tail call i32 @strlen(i8* %0)
%13 = add nsw i32 %12, -1
%14 = sext 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 %18, label %20
18: ; preds = %11
%19 = tail call i8* (i8*, i8*, i8*, ...) @mhs_strconcat(i8* %0, i8* %1, i8* null)
br label %22
20: ; preds = %11
%21 = tail call i8* (i8*, i8*, i8*, ...) @mhs_strconcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %1, i8* null)
br label %22
22: ; preds = %2, %20, %18, %9
%23 = phi i8* [ %10, %9 ], [ %19, %18 ], [ %21, %20 ], [ null, %2 ]
ret i8* %23
}