#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int strlen(char *);
char *get_full_path(char *prefix, char *path) {
  int prefix_len = (prefix == NULL) ? 0 : strlen(prefix);
  int path_len = strlen(path);
  char *fullpath;
  fullpath = malloc(prefix_len + path_len + 2);
  if (fullpath == NULL)
    return NULL;
  memcpy(fullpath, prefix, prefix_len);
  memcpy(fullpath + prefix_len, path, path_len + 1);
  fullpath[prefix_len + path_len] = '/';
  fullpath[prefix_len + path_len + 1] = '\0';
  return fullpath;
}


x86 assembly (clang, -O0):
<get_full_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1155 <get_full_path+0x25>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    1161 <get_full_path+0x31>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
add    -0x20(%rbp),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119d <get_full_path+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    11f4 <get_full_path+0xc4>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_full_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdi,%rdi
je     1153 <get_full_path+0x23>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
jmp    1156 <get_full_path+0x26>
xor    %r12d,%r12d
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
lea    (%r12,%r13,1),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a8 <get_full_path+0x78>
lea    (%r12,%r13,1),%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
movslq %r12d,%rax
mov    %rbx,%rdi
add    %rax,%rdi
add    $0x1,%r13d
mov    %r14,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
movslq %ebp,%rax
movw   $0x2f,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @get_full_path(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
br label %6
6: ; preds = %2, %4
%7 = phi i32 [ %5, %4 ], [ 0, %2 ]
%8 = tail call i32 @strlen(i8* %1)
%9 = add nsw i32 %8, %7
%10 = add nsw i32 %9, 2
%11 = tail call i8* @malloc(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %24, label %13
13: ; preds = %6
%14 = tail call i32 @memcpy(i8* %11, i8* %0, i32 %7)
%15 = sext i32 %7 to i64
%16 = getelementptr inbounds i8, i8* %11, i64 %15
%17 = add nsw i32 %8, 1
%18 = tail call i32 @memcpy(i8* %16, i8* %1, i32 %17)
%19 = sext i32 %9 to i64
%20 = getelementptr inbounds i8, i8* %11, i64 %19
store i8 47, i8* %20
%21 = add nsw i32 %9, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %11, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %6, %13
ret i8* %11
}