#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 *TreeCCDupString(char *);
int /*<<< orphan*/ TreeCCOutOfMemory(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *TreeCCResolvePathname(char *absolute, char *relative) {
  int len;
  char *path;
  if (!absolute) {
    return TreeCCDupString(relative);
  }
  len = strlen(absolute);
  while (len > 0 && absolute[len - 1] != '/' && absolute[len - 1] != '\\') {
    --len;
  }
  if (len <= 0) {
    return TreeCCDupString(relative);
  }
  path = (char *)malloc(len + strlen(relative) + 1);
  if (!path) {
    TreeCCOutOfMemory(0);
  }
  strncpy(path, absolute, len);
  strcpy(path + len, relative);
  return path;
}


x86 assembly (clang, -O0):
<TreeCCResolvePathname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118d <TreeCCResolvePathname+0x2d>
mov    -0x18(%rbp),%rdi
call   1070 <TreeCCDupString@plt>
mov    %rax,-0x8(%rbp)
jmp    1279 <TreeCCResolvePathname+0x119>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x29(%rbp)
jle    11e1 <TreeCCResolvePathname+0x81>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x29(%rbp)
je     11e1 <TreeCCResolvePathname+0x81>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11f1 <TreeCCResolvePathname+0x91>
jmp    11ff <TreeCCResolvePathname+0x9f>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <TreeCCResolvePathname+0x39>
cmpl   $0x0,-0x1c(%rbp)
jg     121b <TreeCCResolvePathname+0xbb>
mov    -0x18(%rbp),%rdi
call   1070 <TreeCCDupString@plt>
mov    %rax,-0x8(%rbp)
jmp    1279 <TreeCCResolvePathname+0x119>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x30(%rbp),%edi
add    %eax,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    124d <TreeCCResolvePathname+0xed>
xor    %edi,%edi
call   1050 <TreeCCOutOfMemory@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TreeCCResolvePathname>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     11e7 <TreeCCResolvePathname+0x87>
mov    %rdi,%r15
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    %eax,%ebp
add    $0x1,%rbp
test   %ebx,%ebx
jle    11e7 <TreeCCResolvePathname+0x87>
movzbl -0x2(%r15,%rbp,1),%eax
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%rbp
cmp    $0x2f,%al
je     1199 <TreeCCResolvePathname+0x39>
cmp    $0x5c,%al
jne    1180 <TreeCCResolvePathname+0x20>
lea    0x1(%rbx),%r12d
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    (%rax,%rbx,1),%edi
add    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11bf <TreeCCResolvePathname+0x5f>
xor    %edi,%edi
call   1050 <TreeCCOutOfMemory@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
add    %rbp,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <TreeCCDupString@plt>

LLVM IR (-O0):
define i8* @TreeCCResolvePathname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = call i8* @TreeCCDupString(i8* %11)
store i8* %12, i8** %3
br label %72
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %6
br label %16
16: ; preds = %39, %13
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 47
br i1 %27, label %28, label %37
28: ; preds = %19
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 92
br label %37
37: ; preds = %28, %19, %16
%38 = phi i1 [ false, %19 ], [ false, %16 ], [ %36, %28 ]
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = load i32, i32* %6
%41 = add nsw i32 %40, -1
store i32 %41, i32* %6
br label %16
42: ; preds = %37
%43 = load i32, i32* %6
%44 = icmp sle i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i8*, i8** %5
%47 = call i8* @TreeCCDupString(i8* %46)
store i8* %47, i8** %3
br label %72
48: ; preds = %42
%49 = load i32, i32* %6
%50 = load i8*, i8** %5
%51 = call i32 @strlen(i8* %50)
%52 = add nsw i32 %49, %51
%53 = add nsw i32 %52, 1
%54 = call i64 @malloc(i32 %53)
%55 = inttoptr i64 %54 to i8*
store i8* %55, i8** %7
%56 = load i8*, i8** %7
%57 = icmp ne i8* %56, null
br i1 %57, label %60, label %58
58: ; preds = %48
%59 = call i32 @TreeCCOutOfMemory(i32 0)
br label %60
60: ; preds = %58, %48
%61 = load i8*, i8** %7
%62 = load i8*, i8** %4
%63 = load i32, i32* %6
%64 = call i32 @strncpy(i8* %61, i8* %62, i32 %63)
%65 = load i8*, i8** %7
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
%69 = load i8*, i8** %5
%70 = call i32 @strcpy(i8* %68, i8* %69)
%71 = load i8*, i8** %7
store i8* %71, i8** %3
br label %72
72: ; preds = %60, %45, %10
%73 = load i8*, i8** %3
ret i8* %73
}

LLVM IR (-O2):
define i8* @TreeCCResolvePathname(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i8* @TreeCCDupString(i8* %1)
br label %34
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = zext i32 %7 to i64
br label %9
9: ; preds = %13, %6
%10 = phi i64 [ %14, %13 ], [ %8, %6 ]
%11 = trunc i64 %10 to i32
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = add nsw i64 %10, -1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
switch i8 %16, label %9 [
i8 47, label %19
i8 92, label %19
]
17: ; preds = %9
%18 = tail call i8* @TreeCCDupString(i8* %1)
br label %34
19: ; preds = %13, %13
%20 = trunc i64 %10 to i32
%21 = tail call i32 @strlen(i8* %1)
%22 = add nuw i32 %20, 1
%23 = add i32 %22, %21
%24 = tail call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = icmp eq i64 %24, 0
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = tail call i32 @TreeCCOutOfMemory(i32 0)
br label %29
29: ; preds = %27, %19
%30 = tail call i32 @strncpy(i8* %25, i8* %0, i32 %20)
%31 = and i64 %10, 4294967295
%32 = getelementptr inbounds i8, i8* %25, i64 %31
%33 = tail call i32 @strcpy(i8* %32, i8* %1)
br label %34
34: ; preds = %29, %17, %4
%35 = phi i8* [ %18, %17 ], [ %25, %29 ], [ %5, %4 ]
ret i8* %35
}