// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_parse_uri
int mg_parse_uri(const struct mg_str uri, struct mg_str *scheme,
                 struct mg_str *user_info, struct mg_str *host,
                 unsigned int *port, struct mg_str *path, struct mg_str *query,
                 struct mg_str *fragment) {
  struct mg_str rscheme = {0, 0}, ruser_info = {0, 0}, rhost = {0, 0},
                rpath = {0, 0}, rquery = {0, 0}, rfragment = {0, 0};
  unsigned int rport = 0;
  enum {
    P_START,
    P_SCHEME_OR_PORT,
    P_USER_INFO,
    P_HOST,
    P_PORT,
    P_REST
  } state = P_START;

  const char *p = uri.p, *end = p + uri.len;
  while (p < end) {
    switch (state) {
      case P_START:
        /*
         * expecting on of:
         * - `scheme://xxxx`
         * - `xxxx:port`
         * - `[a:b:c]:port`
         * - `xxxx/path`
         */
        if (*p == '[') {
          state = P_HOST;
          break;
        }
        for (; p < end; p++) {
          if (*p == ':') {
            state = P_SCHEME_OR_PORT;
            break;
          } else if (*p == '/') {
            state = P_REST;
            break;
          }
        }
        if (state == P_START || state == P_REST) {
          rhost.p = uri.p;
          rhost.len = p - uri.p;
        }
        break;
      case P_SCHEME_OR_PORT:
        if (end - p >= 3 && strncmp(p, "://", 3) == 0) {
          rscheme.p = uri.p;
          rscheme.len = p - uri.p;
          state = P_USER_INFO;
          p += 3;
        } else {
          rhost.p = uri.p;
          rhost.len = p - uri.p;
          state = P_PORT;
        }
        break;
      case P_USER_INFO:
        ruser_info.p = p;
        for (; p < end; p++) {
          if (*p == '@' || *p == '[') {
            break;
          }
        }
        if (p == end || *p == '/' || *p == '[') {
          /* backtrack and parse as host */
          p = ruser_info.p;
        }
        ruser_info.len = p - ruser_info.p;
        state = P_HOST;
        break;
      case P_HOST:
        if (*p == '@') p++;
        rhost.p = p;
        if (*p == '[') {
          int found = 0;
          for (; !found && p < end; p++) {
            found = (*p == ']');
          }
          if (!found) return -1;
        } else {
          for (; p < end; p++) {
            if (*p == ':' || *p == '/') break;
          }
        }
        rhost.len = p - rhost.p;
        if (p < end) {
          if (*p == ':') {
            state = P_PORT;
            break;
          } else if (*p == '/') {
            state = P_REST;
            break;
          }
        }
        break;
      case P_PORT:
        p++;
        for (; p < end; p++) {
          if (*p == '/') {
            state = P_REST;
            break;
          }
          rport *= 10;
          rport += *p - '0';
        }
        break;
      case P_REST:
        /* `p` points to separator. `path` includes the separator */
        parse_uri_component(&p, end, "?#", &rpath);
        if (p < end && *(p - 1) == '?') {
          parse_uri_component(&p, end, "#", &rquery);
        }
        parse_uri_component(&p, end, "", &rfragment);
        break;
    }
  }

  if (scheme != 0) *scheme = rscheme;
  if (user_info != 0) *user_info = ruser_info;
  if (host != 0) *host = rhost;
  if (port != 0) *port = rport;
  if (path != 0) *path = rpath;
  if (query != 0) *query = rquery;
  if (fragment != 0) *fragment = rfragment;

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3260
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3260
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3260
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3260
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3260
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3260
movl $0x0, -0x9c(%rbp)
movl $0x0, -0xa0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
addq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0xfb3c
movl -0xa0(%rbp), %eax
movq %rax, -0xc0(%rbp)
subq $0x5, %rax
ja 0xfb37
movq -0xc0(%rbp), %rax
leaq 0xfca5(%rip), %rcx      # 0x1f374
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0xf6f6
movl $0x3, -0xa0(%rbp)
jmp 0xfb37
jmp 0xf6f8
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0xf756
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0xf723
movl $0x1, -0xa0(%rbp)
jmp 0xf756
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0xf73e
movl $0x5, -0xa0(%rbp)
jmp 0xf756
jmp 0xf740
jmp 0xf742
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0xf6f8
cmpl $0x0, -0xa0(%rbp)
je 0xf768
cmpl $0x5, -0xa0(%rbp)
jne 0xf782
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0xa8(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x60(%rbp)
jmp 0xfb37
movq -0xb0(%rbp), %rax
movq -0xa8(%rbp), %rcx
subq %rcx, %rax
cmpq $0x3, %rax
jl 0xf7f3
movq -0xa8(%rbp), %rdi
leaq 0x10aab(%rip), %rsi     # 0x20257
movl $0x3, %edx
callq 0x30b0
cmpl $0x0, %eax
jne 0xf7f3
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0xa8(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x2, -0xa0(%rbp)
movq -0xa8(%rbp), %rax
addq $0x3, %rax
movq %rax, -0xa8(%rbp)
jmp 0xf817
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0xa8(%rbp), %rax
movq -0x18(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x60(%rbp)
movl $0x4, -0xa0(%rbp)
jmp 0xfb37
movq -0xa8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0xf86d
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x40, %eax
je 0xf855
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0xf857
jmp 0xf86d
jmp 0xf859
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0xf827
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
je 0xf89b
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0xf89b
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0xf8a6
movq -0x58(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq -0x58(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x3, -0xa0(%rbp)
jmp 0xfb37
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x40, %eax
jne 0xf8e8
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0xf98a
movl $0x0, -0xb4(%rbp)
xorl %eax, %eax
cmpl $0x0, -0xb4(%rbp)
movb %al, -0xc1(%rbp)
jne 0xf938
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
setb %al
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0xf944
jmp 0xf973
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5d, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xb4(%rbp)
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0xf910
cmpl $0x0, -0xb4(%rbp)
jne 0xf988
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfbfb
jmp 0xf9d4
jmp 0xf98c
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0xf9d2
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
je 0xf9ba
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0xf9bc
jmp 0xf9d2
jmp 0xf9be
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0xf98c
jmp 0xf9d4
movq -0xa8(%rbp), %rax
movq -0x68(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0xfa36
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0xfa14
movl $0x4, -0xa0(%rbp)
jmp 0xfb37
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0xfa32
movl $0x5, -0xa0(%rbp)
jmp 0xfb37
jmp 0xfa34
jmp 0xfa36
jmp 0xfb37
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0xfab2
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0xfa78
movl $0x5, -0xa0(%rbp)
jmp 0xfab2
imull $0xa, -0x9c(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0xa8(%rbp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
addl -0x9c(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0xfa4d
jmp 0xfb37
movq -0xb0(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
leaq 0xfebb(%rip), %rdx      # 0x1f987
leaq -0x78(%rbp), %rcx
callq 0xfc10
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0xfb16
movq -0xa8(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x3f, %eax
jne 0xfb16
movq -0xb0(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
leaq 0x11678(%rip), %rdx     # 0x21182
leaq -0x88(%rbp), %rcx
callq 0xfc10
movq -0xb0(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
leaq 0x10c80(%rip), %rdx     # 0x207ab
leaq -0x98(%rbp), %rcx
callq 0xfc10
jmp 0xf696
cmpq $0x0, -0x20(%rbp)
je 0xfb56
movq -0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq %rcx, 0x8(%rax)
cmpq $0x0, -0x28(%rbp)
je 0xfb70
movq -0x28(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x8(%rax)
cmpq $0x0, -0x30(%rbp)
je 0xfb8a
movq -0x30(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, (%rax)
movq -0x60(%rbp), %rcx
movq %rcx, 0x8(%rax)
cmpq $0x0, -0x38(%rbp)
je 0xfb9d
movl -0x9c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x10(%rbp)
je 0xfbb7
movq 0x10(%rbp), %rax
movq -0x78(%rbp), %rcx
movq %rcx, (%rax)
movq -0x70(%rbp), %rcx
movq %rcx, 0x8(%rax)
cmpq $0x0, 0x18(%rbp)
je 0xfbd4
movq 0x18(%rbp), %rax
movq -0x88(%rbp), %rcx
movq %rcx, (%rax)
movq -0x80(%rbp), %rcx
movq %rcx, 0x8(%rax)
cmpq $0x0, 0x20(%rbp)
je 0xfbf4
movq 0x20(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rcx, (%rax)
movq -0x90(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw (%rax,%rax)