// File: /workspace/github_c_makefile_star2_O2/marcomorain[P]garcon/http_parser.c
// Function: http_parser_parse_url
int
http_parser_parse_url(const char *buf, size_t buflen, int is_connect,
                      struct http_parser_url *u)
{
  enum state s;
  const char *p;
  enum http_parser_url_fields uf, old_uf;
  int found_at = 0;

  u->port = u->field_set = 0;
  s = is_connect ? s_req_server_start : s_req_spaces_before_url;
  old_uf = UF_MAX;

  for (p = buf; p < buf + buflen; p++) {
    s = parse_url_char(s, *p);

    /* Figure out the next field that we're operating on */
    switch (s) {
      case s_dead:
        return 1;

      /* Skip delimeters */
      case s_req_schema_slash:
      case s_req_schema_slash_slash:
      case s_req_server_start:
      case s_req_query_string_start:
      case s_req_fragment_start:
        continue;

      case s_req_schema:
        uf = UF_SCHEMA;
        break;

      case s_req_server_with_at:
        found_at = 1;

      /* FALLTROUGH */
      case s_req_server:
        uf = UF_HOST;
        break;

      case s_req_path:
        uf = UF_PATH;
        break;

      case s_req_query_string:
        uf = UF_QUERY;
        break;

      case s_req_fragment:
        uf = UF_FRAGMENT;
        break;

      default:
        assert(!"Unexpected state");
        return 1;
    }

    /* Nothing's changed; soldier on */
    if (uf == old_uf) {
      u->field_data[uf].len++;
      continue;
    }

    u->field_data[uf].off = p - buf;
    u->field_data[uf].len = 1;

    u->field_set |= (1 << uf);
    old_uf = uf;
  }

  /* host must be present if there is a schema */
  /* parsing http:///toto will fail */
  if ((u->field_set & ((1 << UF_SCHEMA) | (1 << UF_HOST))) != 0) {
    if (http_parse_host(buf, u, found_at) != 0) {
      return 1;
    }
  }

  /* CONNECT requests can only contain "hostname:port" */
  if (is_connect && u->field_set != ((1 << UF_HOST)|(1 << UF_PORT))) {
    return 1;
  }

  if (u->field_set & (1 << UF_PORT)) {
    /* Don't bother with endp; we've already validated the string */
    unsigned long v = strtoul(buf + u->field_data[UF_PORT].off, NULL, 10);

    /* Ports have a max value of 2^16 */
    if (v > 0xffff) {
      return 1;
    }

    u->port = (uint16_t) v;
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x10(%rsp)
andl $0x0, (%rcx)
movq %rsi, %r12
xorl %eax, %eax
movl %edx, 0x24(%rsp)
testl %edx, %edx
setne %al
leal 0x14(,%rax,4), %r15d
movq %rdi, 0x18(%rsp)
addq %rdi, %r12
xorl %ebp, %ebp
pushq $0x7
popq %r14
leaq 0x19c7(%rip), %r13      # 0x7710
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
movq 0x18(%rsp), %rax
addq %rbp, %rax
cmpq %r12, %rax
jae 0x5ddf
movsbl (%rax), %esi
movl %r15d, %edi
callq 0x59e8
movl %eax, %r15d
leal -0x15(%r15), %eax
cmpl $0xa, %eax
ja 0x6086
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
xorl %eax, %eax
jmp 0x5da3
pushq $0x4
jmp 0x5da2
pushq $0x1
popq %rcx
movl %ecx, %eax
movl %ecx, 0xc(%rsp)
jmp 0x5da3
pushq $0x1
jmp 0x5da2
pushq $0x5
jmp 0x5da2
pushq $0x3
popq %rax
cmpl %r14d, %eax
jne 0x5db7
movl %r14d, %eax
movq 0x10(%rsp), %rcx
incw 0x6(%rcx,%rax,4)
jmp 0x5dd7
movl %eax, %ecx
movq 0x10(%rsp), %rdx
movw %bp, 0x4(%rdx,%rcx,4)
movw $0x1, 0x6(%rdx,%rcx,4)
movl %ebx, %ecx
btsl %eax, %ecx
movl %ecx, %ebx
movw %cx, (%rdx)
movl %eax, %r14d
incq %rbp
jmp 0x5d53
movl %ebx, %r13d
testb $0x3, %r13b
je 0x602b
movq 0x10(%rsp), %rbx
movzwl 0x8(%rbx), %eax
movzwl 0xa(%rbx), %ecx
andw $0x0, 0xa(%rbx)
xorl %edx, %edx
cmpl $0x0, 0xc(%rsp)
sete %dl
leal 0x2(,%rdx,2), %edi
movq 0x18(%rsp), %rdx
addq %rax, %rdx
addq %rdx, %rcx
xorl %edx, %edx
leaq 0x18c9(%rip), %rsi      # 0x76ec
pushq $0x1
popq %r15
pushq $0x6
popq %r11
pushq $0x7
popq %r12
pushq $0x9
popq %r9
pushq $0xa
popq %r10
movq 0x18(%rsp), %r8
addq %rax, %r8
cmpq %rcx, %r8
jae 0x6017
movzbl (%r8), %r8d
leal -0x2(%rdi), %r14d
movslq (%rsi,%r14,4), %r14
addq %rsi, %r14
jmpq *%r14
cmpl $0x40, %r8d
jne 0x5e9a
pushq $0x4
jmp 0x5fde
addb $-0x30, %r8b
cmpb $0xa, %r8b
jae 0x6074
cmpl $0xa, %edi
jne 0x5f6e
movzwl 0xe(%rbx), %edi
incl %edi
jmp 0x5f7e
cmpl $0x5b, %r8d
jne 0x5f87
pushq $0x5
jmp 0x5fde
leal -0x30(%r8), %ebp
cmpb $0xa, %bpl
jb 0x5ed7
movl %r8d, %ebp
orb $0x20, %bpl
addb $-0x61, %bpl
cmpb $0x1a, %bpl
jb 0x5ed7
leal -0x21(%r8), %r14d
cmpl $0x3e, %r14d
ja 0x600b
movabsq $0x4000000016003ff9, %rbp # imm = 0x4000000016003FF9
btq %r14, %rbp
jae 0x600b
cmpl $0x3, %edi
jne 0x5fc8
movzwl 0x1e(%rbx), %edi
incl %edi
jmp 0x5fd8
movl %r8d, %edi
orb $0x20, %dil
addb $-0x61, %dil
cmpb $0x1a, %dil
jb 0x5fbd
leal -0x30(%r8), %edi
cmpb $0xa, %dil
setb %dil
leal -0x2d(%r8), %ebp
cmpb $0x2, %bpl
setb %bpl
orb %dil, %bpl
jne 0x5fbd
movl %r9d, %edi
cmpl $0x3a, %r8d
je 0x6003
jmp 0x6074
cmpl $0x5d, %r8d
jne 0x5f40
pushq $0x8
jmp 0x5fde
leal -0x30(%r8), %ebp
cmpb $0xa, %bpl
jb 0x5ff1
movl %r8d, %ebp
orb $0x20, %bpl
cmpb $0x61, %bpl
jb 0x5fe1
cmpb $0x67, %bpl
jb 0x5ff1
jmp 0x6074
movw %ax, 0xc(%rbx)
orl $0x4, %r13d
movw %r13w, (%rbx)
movw $0x1, %di
movw %di, 0xe(%rbx)
movl %r10d, %edi
jmp 0x6003
movl %r8d, %edi
orb $0x20, %dil
addb $-0x61, %dil
cmpb $0x1a, %dil
jb 0x5fb9
leal -0x30(%r8), %edi
cmpb $0xa, %dil
setb %dil
addb $-0x2d, %r8b
cmpb $0x2, %r8b
setb %r8b
orb %dil, %r8b
je 0x6074
movw %ax, 0x8(%rbx)
incl %edx
movw %dx, 0xa(%rbx)
movl %r11d, %edi
jmp 0x6003
movw %ax, 0x1c(%rbx)
orl $0x40, %r13d
movw %r13w, (%rbx)
movw $0x1, %di
movw %di, 0x1e(%rbx)
pushq $0x3
popq %rdi
jmp 0x6003
cmpl $0x2e, %r8d
je 0x5ff1
cmpl $0x3a, %r8d
jne 0x6074
cmpl $0x7, %edi
je 0x5ffa
movw %ax, 0x8(%rbx)
incl %edx
movw %dx, 0xa(%rbx)
movl %r12d, %edi
incq %rax
jmp 0x5e37
cmpl $0x7e, %r8d
je 0x5ed7
jmp 0x6074
addl $-0x2, %edi
cmpl $0x8, %edi
jae 0x6030
movl $0xaf, %eax
btl %edi, %eax
jae 0x6030
jmp 0x6074
movq 0x10(%rsp), %rbx
cmpl $0x0, 0x24(%rsp)
je 0x6040
cmpw $0x6, %r13w
je 0x6049
jmp 0x6070
xorl %r15d, %r15d
testb $0x4, %r13b
je 0x6074
movzwl 0xc(%rbx), %eax
movq 0x18(%rsp), %rdi
addq %rax, %rdi
xorl %r15d, %r15d
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x2290
cmpq $0xffff, %rax           # imm = 0xFFFF
ja 0x6070
movw %ax, 0x2(%rbx)
jmp 0x6074
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1, %r15d
je 0x6074
leaq 0x1ba5(%rip), %rdi      # 0x7c38
leaq 0x18d6(%rip), %rsi      # 0x7970
leaq 0x1bab(%rip), %rcx      # 0x7c4c
movl $0x925, %edx            # imm = 0x925
callq 0x2120