// File: Fohlen[P]cubescript-standalone/stream.cpp
// Function: path(char*)
char *path(char *s)
{
    for(char *curpart = s;;)
    {
        char *endpart = strchr(curpart, '&');
        if(endpart) *endpart = '\0';
        if(curpart[0]=='<')
        {
            char *file = strrchr(curpart, '>');
            if(!file) return s;
            curpart = file+1;
        }
        for(char *t = curpart; (t = strpbrk(t, "/\\")); *t++ = PATHDIV);
        for(char *prevdir = NULL, *curdir = curpart;;)
        {
            prevdir = curdir[0]==PATHDIV ? curdir+1 : curdir;
            curdir = strchr(prevdir, PATHDIV);
            if(!curdir) break;
            if(prevdir+1==curdir && prevdir[0]=='.')
            {
                memmove(prevdir, curdir+1, strlen(curdir+1)+1);
                curdir = prevdir;
            }
            else if(curdir[1]=='.' && curdir[2]=='.' && curdir[3]==PATHDIV)
            {
                if(prevdir+2==curdir && prevdir[0]=='.' && prevdir[1]=='.') continue;
                memmove(prevdir, curdir+4, strlen(curdir+4)+1);
                curdir = prevdir;
            }
        }
        if(endpart)
        {
            *endpart = '&';
            curpart = endpart+1;
        }
        else break;
    }
    return s;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movl $0x26, %esi
callq 0x2080
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x183f4
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3c, %eax
jne 0x18432
movq -0x18(%rbp), %rdi
movl $0x3e, %esi
callq 0x2210
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x18426
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x185e4
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x69d9(%rip), %rsi      # 0x1ee1e
callq 0x23c0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x1846a
jmp 0x18456
movq -0x30(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x30(%rbp)
movb $0x2f, (%rax)
jmp 0x1843a
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x18494
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1849c
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movl $0x2f, %esi
callq 0x2080
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x184c2
jmp 0x185b9
movq -0x38(%rbp), %rax
addq $0x1, %rax
cmpq -0x40(%rbp), %rax
jne 0x1851e
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x1851e
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
addq $0x1, %rdi
callq 0x20b0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x2380
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x185b4
movq -0x40(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2e, %eax
jne 0x185b2
movq -0x40(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x2e, %eax
jne 0x185b2
movq -0x40(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x2f, %eax
jne 0x185b2
movq -0x38(%rbp), %rax
addq $0x2, %rax
cmpq -0x40(%rbp), %rax
jne 0x18575
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x18575
movq -0x38(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2e, %eax
jne 0x18575
jmp 0x1847a
movq -0x38(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rdi
addq $0x4, %rdi
callq 0x20b0
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x2380
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x185b4
jmp 0x1847a
cmpq $0x0, -0x20(%rbp)
je 0x185d5
movq -0x20(%rbp), %rax
movb $0x26, (%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x185d7
jmp 0x185dc
jmp 0x183d4
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nop