#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 *);
int strlen(char *);
void path_resolve(char *parent_path, char *path, char *result) {
  int len = strlen(parent_path);
  if (path[0] == '/') {
    strcpy(result, path);
  } else {
    strcpy(result, parent_path);
    if (parent_path[len - 1] != '/') {
      result[len] = '/';
      strcpy(result + len + 1, path);
    } else {
      strcpy(result + len, path);
    }
  }
}


x86 assembly (clang, -O0):
<path_resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1162 <path_resolve+0x42>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11cb <path_resolve+0xab>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11b2 <path_resolve+0x92>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11c6 <path_resolve+0xa6>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11cb <path_resolve+0xab>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_resolve>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
cmpb   $0x2f,(%r14)
je     115d <path_resolve+0x3d>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
movslq %ebp,%rax
add    %rax,%rbx
cmpb   $0x2f,-0x1(%rax,%r15,1)
je     115d <path_resolve+0x3d>
movb   $0x2f,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strcpy@plt>

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

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