#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 *strchr(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char const *);
void build_fullname(char *fullname, const char *directory,
                    const char *filename) {
  char *dest = fullname;
  if (directory[0] == '/' && !directory[1]) {
    *dest = '/';
    ++dest;
  } else if (directory[0] != '.' || directory[1]) {
    strcpy(dest, directory);
    dest = strchr(dest, 0);
    *dest = '/';
    ++dest;
  }
  strcpy(dest, filename);
}


x86 assembly (clang, -O0):
<build_fullname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1172 <build_fullname+0x52>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    1172 <build_fullname+0x52>
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c7 <build_fullname+0xa7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1193 <build_fullname+0x73>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11c2 <build_fullname+0xa2>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11c7 <build_fullname+0xa7>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_fullname>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    (%rsi),%al
cmp    $0x2e,%al
je     113c <build_fullname+0x1c>
cmp    $0x2f,%al
jne    1142 <build_fullname+0x22>
cmpb   $0x0,0x1(%rsi)
jne    1142 <build_fullname+0x22>
jmp    1155 <build_fullname+0x35>
cmpb   $0x0,0x1(%rsi)
je     115c <build_fullname+0x3c>
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %rax,%rbx
movb   $0x2f,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>

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

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