#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*/ strcpy(char *, char *);
char *strrchr(char *, char);
void complete_path(char *result, char *toc_path, char *path) {
  strcpy(result, path);
  if (path[0] != '/') {
    char *ptr = strrchr(toc_path, '/');
    if (ptr) {
      strcpy(result, toc_path);
      strcpy(&result[ptr - toc_path + 1], path);
    }
  }
}


x86 assembly (clang, -O0):
<complete_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     119f <complete_path+0x7f>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     119a <complete_path+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    119f <complete_path+0x7f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<complete_path>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdx,%rsi
call   1030 <strcpy@plt>
cmpb   $0x2f,(%rbx)
je     117c <complete_path+0x5c>
mov    %r15,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     117c <complete_path+0x5c>
mov    %rax,%r12
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
sub    %r15,%r12
lea    (%r12,%r14,1),%rdi
add    $0x1,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @complete_path(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
%9 = load i8*, i8** %6
%10 = call i32 @strcpy(i8* %8, i8* %9)
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 47
br i1 %15, label %16, label %36
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i8* @strrchr(i8* %17, i8 signext 47)
store i8* %18, i8** %7
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %35
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i8*, i8** %5
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %4
%26 = load i8*, i8** %7
%27 = load i8*, i8** %5
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = add nsw i64 %30, 1
%32 = getelementptr inbounds i8, i8* %25, i64 %31
%33 = load i8*, i8** %6
%34 = call i32 @strcpy(i8* %32, i8* %33)
br label %35
35: ; preds = %21, %16
br label %36
36: ; preds = %35, %3
ret void
}

LLVM IR (-O2):
define void @complete_path(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strcpy(i8* %0, i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 47
br i1 %6, label %18, label %7
7: ; preds = %3
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %18, label %10
10: ; preds = %7
%11 = tail call i32 @strcpy(i8* %0, i8* %1)
%12 = ptrtoint i8* %8 to i64
%13 = ptrtoint i8* %1 to i64
%14 = sub i64 1, %13
%15 = add i64 %14, %12
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = tail call i32 @strcpy(i8* %16, i8* %2)
br label %18
18: ; preds = %7, %10, %3
ret void
}