// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rcx, %rbx
movq %rdi, %r14
movl $0x0, (%rcx)
testq %rsi, %rsi
movl %edx, 0x4(%rsp)
jle 0x6189
movq %rsi, %r15
addq %r14, %r15
xorl %eax, %eax
testl %edx, %edx
setne %al
leal 0x14(,%rax,4), %eax
movl $0x7, %ebp
xorl %r12d, %r12d
leaq 0x2606(%rip), %r13      # 0x86ec
movl $0x0, (%rsp)
movsbl (%r14,%r12), %esi
movl %eax, %edi
callq 0x5d23
leal -0x15(%rax), %ecx
cmpl $0xa, %ecx
ja 0x6464
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
xorl %ecx, %ecx
jmp 0x613b
movl $0x4, %ecx
jmp 0x613b
movl $0x1, %ecx
movl $0x1, (%rsp)
jmp 0x613b
movl $0x1, %ecx
jmp 0x613b
movl $0x5, %ecx
jmp 0x613b
movl $0x3, %ecx
cmpl %ebp, %ecx
jne 0x6148
movl %ecx, %ecx
incw 0x6(%rbx,%rcx,4)
jmp 0x6163
movl %ecx, %edx
movw %r12w, 0x4(%rbx,%rdx,4)
movw $0x1, 0x6(%rbx,%rdx,4)
movl $0x1, %edx
shll %cl, %edx
orw %dx, (%rbx)
movl %ecx, %ebp
leaq (%r14,%r12), %rcx
incq %rcx
incq %r12
cmpq %r15, %rcx
jb 0x60ed
xorl %eax, %eax
cmpl $0x0, (%rsp)
sete %al
leal 0x2(,%rax,2), %r11d
jmp 0x618f
movl $0x4, %r11d
testb $0x3, (%rbx)
je 0x6415
movzwl 0x8(%rbx), %eax
movzwl 0xa(%rbx), %ecx
movw $0x0, 0xa(%rbx)
testq %rcx, %rcx
je 0x63fb
leaq 0xa(%rbx), %rdx
leaq (%r14,%rax), %rsi
addq %rsi, %rcx
leaq 0x1e(%rbx), %rsi
leaq 0xe(%rbx), %rdi
leaq 0x2573(%rip), %r8       # 0x873c
leaq 0x2548(%rip), %r9       # 0x8718
movabsq $0x4000000016003ff9, %r10 # imm = 0x4000000016003FF9
leal -0x2(%r11), %r15d
cmpl $0x8, %r15d
ja 0x6331
movzbl (%r14,%rax), %r12d
movslq (%r9,%r15,4), %r15
addq %r9, %r15
jmpq *%r15
movl $0x4, %r15d
cmpl $0x40, %r12d
je 0x6337
leal -0x30(%r12), %ebp
movl $0x3, %r15d
cmpb $0xa, %bpl
jb 0x6337
movl %r12d, %ebp
orb $0x20, %bpl
addb $-0x61, %bpl
cmpb $0x1a, %bpl
jb 0x6337
leal -0x21(%r12), %r13d
cmpl $0x3e, %r13d
ja 0x6246
btq %r13, %r10
jb 0x6337
cmpl $0x7e, %r12d
jne 0x6331
jmp 0x6337
addb $-0x30, %r12b
movl $0xa, %r15d
cmpb $0xa, %r12b
jae 0x6331
jmp 0x6337
movl $0x5, %r15d
cmpl $0x5b, %r12d
je 0x6337
movl %r12d, %ebp
orb $0x20, %bpl
addb $-0x61, %bpl
movl $0x6, %r15d
cmpb $0x1a, %bpl
jb 0x6337
leal -0x30(%r12), %ebp
cmpb $0xa, %bpl
setb %bpl
addb $-0x2d, %r12b
cmpb $0x2, %r12b
setb %r12b
orb %bpl, %r12b
je 0x6331
jmp 0x6337
movl %r12d, %ebp
orb $0x20, %bpl
addb $-0x61, %bpl
movl $0x6, %r15d
cmpb $0x1a, %bpl
jb 0x6337
leal -0x30(%r12), %ebp
cmpb $0xa, %bpl
setb %bpl
leal -0x2d(%r12), %r13d
cmpb $0x2, %r13b
setb %r13b
orb %bpl, %r13b
jne 0x6337
movl $0x9, %r15d
cmpl $0x3a, %r12d
jne 0x6331
jmp 0x6337
movl $0x8, %r15d
cmpl $0x5d, %r12d
je 0x6337
leal -0x30(%r12), %ebp
movl $0x7, %r15d
cmpb $0xa, %bpl
jb 0x6337
movl %r12d, %ebp
orb $0x20, %bpl
cmpb $0x61, %bpl
jb 0x63d7
cmpb $0x67, %bpl
jb 0x6337
movl $0x1, %r15d
cmpl $0x1, %r15d
jne 0x6342
movl %r11d, %ebp
jmp 0x63b5
leal -0x3(%r15), %r12d
movl %r15d, %ebp
cmpl $0x7, %r12d
ja 0x63b5
movslq (%r8,%r12,4), %r12
addq %r8, %r12
movl %r15d, %ebp
jmpq *%r12
movq %rsi, %r12
cmpl $0x3, %r11d
je 0x63ad
movw %ax, 0x1c(%rbx)
movw $0x0, 0x1e(%rbx)
orb $0x40, (%rbx)
movq %rsi, %r12
jmp 0x63ad
movq %rdx, %r12
cmpl $0x7, %r11d
jne 0x638b
jmp 0x63ad
movq %rdx, %r12
cmpl $0x6, %r11d
je 0x63ad
movw %ax, 0x8(%rbx)
movq %rdx, %r12
jmp 0x63ad
movq %rdi, %r12
cmpl $0xa, %r11d
je 0x63ad
movw %ax, 0xc(%rbx)
movw $0x0, 0xe(%rbx)
orb $0x4, (%rbx)
movq %rdi, %r12
incw (%r12)
movl %r15d, %ebp
cmpl $0x1, %r15d
je 0x645d
leaq (%r14,%rax), %r15
incq %r15
incq %rax
movl %ebp, %r11d
cmpq %rcx, %r15
jb 0x61da
jmp 0x63fe
movl $0x7, %ebp
movl $0x7, %r15d
cmpl $0x2e, %r12d
je 0x63ee
movl $0x1, %r15d
cmpl $0x3a, %r12d
cmovel %ebp, %r15d
jmp 0x6337
movl %r11d, %ebp
addl $-0x2, %ebp
cmpl $0x8, %ebp
jae 0x6415
movl $0x1, %eax
movl $0xaf, %ecx
btl %ebp, %ecx
jb 0x6469
cmpl $0x0, 0x4(%rsp)
je 0x6427
movl $0x1, %eax
cmpw $0x6, (%rbx)
jne 0x6469
xorl %eax, %eax
testb $0x4, (%rbx)
je 0x6469
movzwl 0xc(%rbx), %eax
addq %rax, %r14
movq %r14, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x2290
movq %rax, %rcx
movl $0x1, %eax
cmpq $0xffff, %rcx           # imm = 0xFFFF
ja 0x6469
movw %cx, 0x2(%rbx)
xorl %eax, %eax
jmp 0x6469
movl $0x1, %eax
jmp 0x6469
cmpl $0x1, %eax
jne 0x6478
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x27d9(%rip), %rdi      # 0x8c58
leaq 0x250a(%rip), %rsi      # 0x8990
leaq 0x27df(%rip), %rcx      # 0x8c6c
movl $0x925, %edx            # imm = 0x925
callq 0x2120