// File: tokuhirom[P]nanouri/nanouri.c
// Function: nanouri_parse_uri(char const*, unsigned long, char const**, unsigned long*, char const**, unsigned long*, int*, char const**, int*)
int nanouri_parse_uri(const char* _buf, size_t len, const char** scheme, size_t *scheme_len, const char **host, size_t *host_len, int *port, const char **path_query, int*path_query_len) {
  const char * buf = _buf, * buf_end = buf + len;

  *scheme = buf;
  for (;;++buf) {
    CHECK_EOF();
    if (':' == *buf) {
      break;
    }
  }
  *scheme_len = buf - *scheme;

  EXPECT(':'); EXPECT('/'); EXPECT('/');

  *host = buf;
  *port = 0;
  *host_len = 0;
  *path_query_len = 0;
  for (;;++buf) {
    if (buf == buf_end) {
      *host_len = buf - *host;
      return 0;
    }
    if (':' == *buf) { /* with port */
      *host_len = buf - *host;
      buf++;

      *port = 0;
      for (;'0' <= *buf && *buf <= '9';buf++) {
        if (buf == buf_end) {
          return 0;
        }
        *port = *port * 10 + (*buf - '0');
      }
      if (buf == buf_end) {
        return 0;
      }
      break;
    }
    if ('/' == *buf) { /* no port */
      *host_len = buf - *host;
      break;
    }
  }

  *path_query = buf;
  *path_query_len = buf_end - buf;
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x3bfd
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3e52
movq -0x40(%rbp), %rax
movsbl (%rax), %ecx
movl $0x3a, %eax
cmpl %ecx, %eax
jne 0x3c0f
jmp 0x3c1f
jmp 0x3c11
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3be7
movq -0x40(%rbp), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %rax
subq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x3c4a
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3e52
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movsbl (%rax), %eax
cmpl $0x3a, %eax
je 0x3c6d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e52
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x3c83
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3e52
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x3ca6
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e52
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x3cbc
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x3e52
movq -0x40(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x40(%rbp)
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x3cdf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3e52
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movq 0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x3d34
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %rax
subq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3e52
movq -0x40(%rbp), %rax
movsbl (%rax), %ecx
movl $0x3a, %eax
cmpl %ecx, %eax
jne 0x3df3
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %rax
subq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq 0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x40(%rbp), %rax
movsbl (%rax), %edx
xorl %eax, %eax
movl $0x30, %ecx
cmpl %edx, %ecx
movb %al, -0x49(%rbp)
jg 0x3d98
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
setle %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x3da1
jmp 0x3dde
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x3db7
movl $0x0, -0x4(%rbp)
jmp 0x3e52
movq 0x10(%rbp), %rax
imull $0xa, (%rax), %ecx
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
addl %eax, %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3d73
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x3df1
movl $0x0, -0x4(%rbp)
jmp 0x3e52
jmp 0x3e2d
movq -0x40(%rbp), %rax
movsbl (%rax), %ecx
movl $0x2f, %eax
cmpl %ecx, %eax
jne 0x3e1a
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq (%rax), %rax
subq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
jmp 0x3e2d
jmp 0x3e1c
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x3d09
movq -0x40(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq