#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*/ memcpy(char *, char const *, int);
int strlen(char const *);
scalar_t__ xmalloc(int);
char *fullname(const char *path, const char *name) {
  int l1, l2;
  char *full;
  l1 = strlen(path);
  l2 = strlen(name);
  if (path[l1 - 1] == '/')
    l1--;
  full = (char *)xmalloc(sizeof(char) * (l1 + 1 + l2 + 1));
  memcpy(full, path, l1);
  full[l1] = '/';
  memcpy(full + l1 + 1, name, l2 + 1);
  return full;
}


x86 assembly (clang, -O0):
<fullname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    117b <fullname+0x4b>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
add    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
add    $0x1,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fullname>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
movslq %r15d,%rbx
cmpb   $0x2f,-0x1(%r12,%rbx,1)
lea    -0x1(%rbx),%rax
cmove  %eax,%ebx
lea    (%rbx,%r13,1),%edi
add    $0x2,%edi
call   1040 <xmalloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
movslq %ebx,%rax
movb   $0x2f,0x0(%rbp,%rax,1)
lea    (%rax,%rbp,1),%rdi
add    $0x1,%rdi
add    $0x1,%r13d
mov    %r14,%rsi
mov    %r13d,%edx
call   1050 <memcpy@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @fullname(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %3, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
%10 = select i1 %9, i32 %5, i32 %3
%11 = add i32 %4, 2
%12 = add i32 %11, %10
%13 = tail call i64 @xmalloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @memcpy(i8* %14, i8* %0, i32 %10)
%16 = sext i32 %10 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 47, i8* %17
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = add nsw i32 %4, 1
%20 = tail call i32 @memcpy(i8* %18, i8* %1, i32 %19)
ret i8* %14
}