#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(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ strcpy(char *, char const *);
size_t strlen(char const *);
char *abspath(const char *wd, const char *path) {
  size_t len_wd = strlen(wd);
  if (wd[len_wd - 1] == '/') {
    char *result = malloc(len_wd + strlen(path) + 1);
    memcpy(result, wd, len_wd);
    strcpy(result + len_wd, path);
    return result;
  } else {
    char *result = malloc(len_wd + 1 + strlen(path) + 1);
    memcpy(result, wd, len_wd);
    result[len_wd] = '/';
    strcpy(result + len_wd + 1, path);
    return result;
  }
}


x86 assembly (clang, -O0):
<abspath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11ca <abspath+0x8a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    122d <abspath+0xed>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
add    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abspath>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    -0x1(%rax,%r15,1),%bpl
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    $0x2f,%bpl
jne    118f <abspath+0x4f>
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
mov    %r12,%rdi
add    %rbx,%rdi
jmp    11ba <abspath+0x7a>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
movb   $0x2f,(%r12,%rbx,1)
lea    (%r12,%rbx,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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