#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*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *xmalloc(scalar_t__);
char *xstrdup(char const *);
char *compose_filename(const char *dir, const char *name) {
  char *res;
  if (dir) {
    res = xmalloc(strlen(dir) + 1 + strlen(name) + 1);
    strcpy(res, dir);
    strcat(res, "/");
    strcat(res, name);
  } else {
    res = xstrdup(name);
  }
  return res;
}


x86 assembly (clang, -O0):
<compose_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11c8 <compose_filename+0x78>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
jmp    11d5 <compose_filename+0x85>
mov    -0x10(%rbp),%rdi
call   1060 <xstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compose_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     11b7 <compose_filename+0x67>
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <xmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <xstrdup@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @compose_filename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %25
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 1
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %11, %13
%15 = add nsw i64 %14, 1
%16 = call i8* @xmalloc(i64 %15)
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = load i8*, i8** %3
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %5
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %5
%23 = load i8*, i8** %4
%24 = call i32 @strcat(i8* %22, i8* %23)
br label %28
25: ; preds = %2
%26 = load i8*, i8** %4
%27 = call i8* @xstrdup(i8* %26)
store i8* %27, i8** %5
br label %28
28: ; preds = %25, %8
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @compose_filename(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* %0)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = add i64 %5, 2
%8 = add i64 %7, %6
%9 = tail call i8* @xmalloc(i64 %8)
%10 = tail call i32 @strcpy(i8* %9, i8* %0)
%11 = tail call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @strcat(i8* %9, i8* %1)
br label %15
13: ; preds = %2
%14 = tail call i8* @xstrdup(i8* %1)
br label %15
15: ; preds = %13, %4
%16 = phi i8* [ %9, %4 ], [ %14, %13 ]
ret i8* %16
}