#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 *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
char *buildname(char *dirname, char *filename) {
  char *cp;
  static char buf[256];
  if ((dirname == NULL) || (*dirname == '\0'))
    return filename;
  cp = strrchr(filename, '/');
  if (cp)
    filename = cp + 1;
  strcpy(buf, dirname);
  strcat(buf, "/");
  strcat(buf, filename);
  return buf;
}


x86 assembly (clang, -O0):
<buildname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     115b <buildname+0x2b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1168 <buildname+0x38>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <buildname+0x9f>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1191 <buildname+0x61>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0x2eb4(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ea8(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rsi
lea    0x2e91(%rip),%rdi
call   1050 <strcat@plt>
lea    0x2e85(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildname>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1189 <buildname+0x59>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1189 <buildname+0x59>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%r15
test   %rax,%rax
cmove  %r14,%r15
lea    0x2eec(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xe8a(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@buildname.buf = internal global [256 x i8] zeroinitializer
@.str = [2 x i8] c"/\00"
define i8* @buildname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9, %2
%15 = load i8*, i8** %5
store i8* %15, i8** %3
br label %30
16: ; preds = %9
%17 = load i8*, i8** %5
%18 = call i8* @strrchr(i8* %17, i8 signext 47)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8* %23, i8** %5
br label %24
24: ; preds = %21, %16
%25 = load i8*, i8** %4
%26 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @buildname.buf, i64 0, i64 0), i8* %25)
%27 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @buildname.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = load i8*, i8** %5
%29 = call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @buildname.buf, i64 0, i64 0), i8* %28)
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @buildname.buf, i64 0, i64 0), i8** %3
br label %30
30: ; preds = %24, %14
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@buildname.buf = internal global [256 x i8] zeroinitializer
@.str = [2 x i8] c"/\00"
define i8* @buildname(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%9 = icmp eq i8* %8, null
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = select i1 %9, i8* %1, i8* %10
%12 = tail call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @buildname.buf, i64 0, i64 0), i8* %0)
%13 = tail call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @buildname.buf, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @strcat(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @buildname.buf, i64 0, i64 0), i8* %11)
br label %15
15: ; preds = %2, %4, %7
%16 = phi i8* [ getelementptr inbounds ([256 x i8], [256 x i8]* @buildname.buf, i64 0, i64 0), %7 ], [ %1, %4 ], [ %1, %2 ]
ret i8* %16
}