// File: ctSkennerton[P]fxtract/util/uri.c
// Function: uri_parts
void
uri_parts(char const *request, URIREF *uri)
{
    char const  *ap, *cp = find(request, 1);   // brk ":/?#\0"
    memset(uri, 0, sizeof(URIREF));

    if (cp > request && cp[0] == ':' && cp[1] == '/' && cp[2] == '/') {
        uri->scheme = (MEMREF){request, cp - request};
        cp += 3;
    } else {
        cp = request;
    }

    if (cp[0] == '/' && cp[1] == '/') {
        // Do not use find(): auth may contain ':'
        // and password may contain anything except '@'
        //  and query or fragment may contain "@"??
        if ((ap = strchr(cp += 2, '@'))) { // BasicAuth
            uri->auth = (MEMREF){cp, ap - cp};
            cp = ap + 1;
        }
    }

    uri->host.ptr = cp;
    cp = find(cp, 1);   // brk ":/?#\0"
    if (!(uri->host.len = cp - uri->host.ptr))
        uri->host.ptr = NULL;

    if (*cp == ':') {
        uri->port.ptr = ++cp;
        cp = find(cp, 2);    // brk "/?#\0"
        uri->port.len = cp - uri->port.ptr;
    }

    if (*cp == '/') {
        uri->path.ptr = ++cp;
        cp = find(cp, 3);    // brk "#?\0"
        uri->path.len = cp - uri->path.ptr;
    }

    if (*cp == '?') {
        uri->query.ptr = ++cp;
        cp = find(cp, 4);    // brk "#\0"
        uri->query.len = cp - uri->query.ptr;
    }

    if (*cp == '#') {
        uri->fragment.len = strlen(uri->fragment.ptr = cp + 1);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x6750
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x70, %edx
callq 0x30e0
movq -0x20(%rbp), %rax
cmpq -0x8(%rbp), %rax
jbe 0x657a
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0x657a
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2f, %eax
jne 0x657a
movq -0x20(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x2f, %eax
jne 0x657a
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq %rcx, -0x30(%rbp)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rdx
subq %rdx, %rcx
movq %rcx, -0x28(%rbp)
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x20(%rbp)
jmp 0x6582
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x65f4
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2f, %eax
jne 0x65f4
movq -0x20(%rbp), %rdi
addq $0x2, %rdi
movq %rdi, -0x20(%rbp)
movl $0x40, %esi
callq 0x3090
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x65f2
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movq %rcx, -0x40(%rbp)
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq %rdx, %rcx
movq %rcx, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x65f4
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x6750
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x20(%rcx), %rcx
subq %rcx, %rax
movq -0x10(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
jne 0x663b
movq -0x10(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0x6684
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x20(%rbp), %rdi
movl $0x2, %esi
callq 0x6750
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
subq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x66cd
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x20(%rbp), %rdi
movl $0x3, %esi
callq 0x6750
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
subq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3f, %eax
jne 0x6716
movq -0x20(%rbp), %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x20(%rbp), %rdi
movl $0x4, %esi
callq 0x6750
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
subq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x6742
movq -0x20(%rbp), %rdi
addq $0x1, %rdi
movq -0x10(%rbp), %rax
movq %rdi, 0x60(%rax)
callq 0x30a0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)