#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 */
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *xmalloc(size_t);
char *get_filename(const char *directory, const char *name) {
  char *path;
  size_t dirlen;
  dirlen = strlen(directory);
  path = xmalloc((dirlen + strlen(name) + 2) * sizeof(char));
  strcpy(path, directory);
  if (dirlen == 0 || path[dirlen - 1] != '/') {
    path[dirlen++] = '/';
  }
  strcpy(path + dirlen, name);
  return path;
}


x86 assembly (clang, -O0):
<get_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
shl    $0x0,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x20(%rbp)
je     11a7 <get_filename+0x77>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11be <get_filename+0x8e>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
movb   $0x2f,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
test   %rbx,%rbx
je     1176 <get_filename+0x46>
cmpb   $0x2f,-0x1(%rbx,%r15,1)
je     117f <get_filename+0x4f>
movb   $0x2f,(%r15,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
add    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @get_filename(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = add i64 %3, 2
%6 = add i64 %5, %4
%7 = tail call i8* @xmalloc(i64 %6)
%8 = tail call i32 @strcpy(i8* %7, i8* %0)
%9 = icmp eq i64 %3, 0
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = add i64 %3, -1
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 47
br i1 %14, label %18, label %15
15: ; preds = %10, %2
%16 = add i64 %3, 1
%17 = getelementptr inbounds i8, i8* %7, i64 %3
store i8 47, i8* %17
br label %18
18: ; preds = %15, %10
%19 = phi i64 [ %16, %15 ], [ %3, %10 ]
%20 = getelementptr inbounds i8, i8* %7, i64 %19
%21 = tail call i32 @strcpy(i8* %20, i8* %1)
ret i8* %7
}