// File: corecodec[P]coremake/coremake.c
// Function: getrelpath
void getrelpath(char* path, int path_flags, const char* __curr, int curr_flags, int delend, int levelup)
{
    char *__path,_path[MAX_PATH];
    char *curr,_curr[MAX_PATH];

    if ((path_flags & FLAG_PATH_MASK) == FLAG_PATH_NOT_PATH)
        return;

    __path = path;
    strcpy(_path,path);
    pathunix(_path);
    path = _path;
    strcpy(_curr,__curr);
    pathunix(_curr);
    curr = _curr;

    if (!(path_flags & FLAG_PATH_SET_ABSOLUTE))
    {
        // ensure that we deal with absolute pathes to compare
        assert(ispathabs(curr));

        switch (path_flags & FLAG_PATH_MASK)
        {
        case FLAG_PATH_SOURCE:
            if (strnicmp(path,src_root,src_root_len)!=0 && !ispathabs(path))
                strins(path,src_root,NULL);
            break;
        case FLAG_PATH_GENERATED:
            if (strnicmp(path,proj_root,proj_root_len)!=0)
                strins(path,proj_root,NULL);
            break;
        case FLAG_PATH_COREMAKE:
            if (strnicmp(path,coremake_root,coremake_root_len)!=0)
                strins(path,coremake_root,NULL);
            break;
        }

        simplifypath(path,1);
        simplifypath(curr,1);

        for (;;)
	    {
		    char* i = nextlevel(path);
		    char* j = nextlevel(curr);

		    if (i && j && (i-path)==(j-curr) && strnicmp(path,curr,i-path)==0)
		    {
			    strdel(path,i);
			    curr = j;
		    }
		    else
			    break;
	    }

	    while ((curr = nextlevel(curr)) != NULL)
        {
            if (--levelup < 0)
		        strins(path,"../",NULL);
        }

	    if (!path[0])
		    strcpy(path,"./");
    }

	if (delend)
		delendpath(path);
    strcpy(__path,path);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x860, %rsp            # imm = 0x860
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl -0xc(%rbp), %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x51d1
jmp 0x5479
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x430(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x2090
leaq -0x430(%rbp), %rdi
callq 0x4e10
leaq -0x430(%rbp), %rax
movq %rax, -0x8(%rbp)
leaq -0x840(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2090
leaq -0x840(%rbp), %rdi
callq 0x4e10
leaq -0x840(%rbp), %rax
movq %rax, -0x438(%rbp)
movl -0xc(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0x545d
movq -0x438(%rbp), %rdi
callq 0x50d0
cmpl $0x0, %eax
je 0x524c
jmp 0x526b
leaq 0x10f6f(%rip), %rdi     # 0x161c2
leaq 0x10e7d(%rip), %rsi     # 0x160d7
movl $0x4ac, %edx            # imm = 0x4AC
leaq 0x10f6c(%rip), %rcx     # 0x161d2
callq 0x2140
movl -0xc(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x854(%rbp)
subl $0x1, %eax
je 0x529b
jmp 0x527e
movl -0x854(%rbp), %eax
subl $0x2, %eax
je 0x52db
jmp 0x528b
movl -0x854(%rbp), %eax
subl $0x3, %eax
je 0x530d
jmp 0x533f
movq -0x8(%rbp), %rdi
movq 0x15f4a(%rip), %rdx     # 0x1b1f0
leaq 0x15343(%rip), %rsi     # 0x1a5f0
callq 0x2260
cmpl $0x0, %eax
je 0x52d9
movq -0x8(%rbp), %rdi
callq 0x50d0
cmpl $0x0, %eax
jne 0x52d9
movq -0x8(%rbp), %rdi
leaq 0x15320(%rip), %rsi     # 0x1a5f0
xorl %eax, %eax
movl %eax, %edx
callq 0x3f50
jmp 0x533f
movq -0x8(%rbp), %rdi
movq 0x15f12(%rip), %rdx     # 0x1b1f8
leaq 0x15703(%rip), %rsi     # 0x1a9f0
callq 0x2260
cmpl $0x0, %eax
je 0x530b
movq -0x8(%rbp), %rdi
leaq 0x156ee(%rip), %rsi     # 0x1a9f0
xorl %eax, %eax
movl %eax, %edx
callq 0x3f50
jmp 0x533f
movq -0x8(%rbp), %rdi
movq 0x15ee8(%rip), %rdx     # 0x1b200
leaq 0x15ad1(%rip), %rsi     # 0x1adf0
callq 0x2260
cmpl $0x0, %eax
je 0x533d
movq -0x8(%rbp), %rdi
leaq 0x15abc(%rip), %rsi     # 0x1adf0
xorl %eax, %eax
movl %eax, %edx
callq 0x3f50
jmp 0x533f
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x5490
movq -0x438(%rbp), %rdi
movl $0x1, %esi
callq 0x5490
movq -0x8(%rbp), %rdi
callq 0x4c40
movq %rax, -0x848(%rbp)
movq -0x438(%rbp), %rdi
callq 0x4c40
movq %rax, -0x850(%rbp)
cmpq $0x0, -0x848(%rbp)
je 0x53fc
cmpq $0x0, -0x850(%rbp)
je 0x53fc
movq -0x848(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movq -0x850(%rbp), %rcx
movq -0x438(%rbp), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jne 0x53fc
movq -0x8(%rbp), %rdi
movq -0x438(%rbp), %rsi
movq -0x848(%rbp), %rdx
movq -0x8(%rbp), %rax
subq %rax, %rdx
callq 0x2260
cmpl $0x0, %eax
jne 0x53fc
movq -0x8(%rbp), %rdi
movq -0x848(%rbp), %rsi
callq 0x3fe0
movq -0x850(%rbp), %rax
movq %rax, -0x438(%rbp)
jmp 0x53fe
jmp 0x5403
jmp 0x535e
jmp 0x5405
movq -0x438(%rbp), %rdi
callq 0x4c40
movq %rax, -0x438(%rbp)
cmpq $0x0, %rax
je 0x5442
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
jge 0x5440
movq -0x8(%rbp), %rdi
leaq 0x11e81(%rip), %rsi     # 0x172b8
xorl %eax, %eax
movl %eax, %edx
callq 0x3f50
jmp 0x5405
movq -0x8(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x545b
movq -0x8(%rbp), %rdi
leaq 0x11e63(%rip), %rsi     # 0x172b9
callq 0x2090
jmp 0x545d
cmpl $0x0, -0x20(%rbp)
je 0x546c
movq -0x8(%rbp), %rdi
callq 0x4cf0
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x2090
addq $0x860, %rsp            # imm = 0x860
popq %rbp
retq
nopw %cs:(%rax,%rax)