#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 *mem_alloc_c(int, char *);
int /*<<< orphan*/ strcat(char *, char const *);
int strlen(char const *);
char *alloc_fullpath(const char *path, const char *name) {
  char *fp = NULL;
  int len = strlen(name);
  int plen = path == NULL ? 0 : strlen(path);
  fp = mem_alloc_c(plen + 1 + len + 1, "fullpath");
  fp[0] = '\0';
  if (path != NULL) {
    strcat(fp, path);
    strcat(fp, "/");
  }
  strcat(fp, name);
  return fp;
}


x86 assembly (clang, -O0):
<alloc_fullpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1169 <alloc_fullpath+0x39>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    1175 <alloc_fullpath+0x45>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
add    $0x1,%edi
add    -0x1c(%rbp),%edi
add    $0x1,%edi
lea    0xe72(%rip),%rsi
call   1040 <mem_alloc_c@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x8(%rbp)
je     11c6 <alloc_fullpath+0x96>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_fullpath>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
test   %r15,%r15
je     1157 <alloc_fullpath+0x27>
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
jmp    115c <alloc_fullpath+0x2c>
mov    $0x1,%eax
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
lea    0xe97(%rip),%rsi
call   1040 <mem_alloc_c@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
test   %r15,%r15
je     1193 <alloc_fullpath+0x63>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
lea    0xe7e(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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