// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movl $0x0, (%rcx)
testq %rsi, %rsi
jle 0x6292
movq %rsi, %r15
movq %rdi, %r14
movq %rcx, 0x10(%rsp)
addq %rdi, %r15
xorl %eax, %eax
movl %edx, 0x8(%rsp)
testl %edx, %edx
setne %al
leal 0x14(,%rax,4), %eax
movl $0x7, %r12d
xorl %r13d, %r13d
leaq 0x273c(%rip), %rbp      # 0x86ec
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
movsbl (%r14,%r13), %esi
movl %eax, %edi
callq 0x5bef
leal -0x15(%rax), %ecx
cmpl $0xa, %ecx
ja 0x6319
movslq (%rbp,%rcx,4), %rcx
addq %rbp, %rcx
jmpq *%rcx
xorl %ecx, %ecx
jmp 0x6009
movl $0x4, %ecx
jmp 0x6009
movl $0x1, %ecx
movl $0x1, 0xc(%rsp)
jmp 0x6009
movl $0x1, %ecx
jmp 0x6009
movl $0x5, %ecx
jmp 0x6009
movl $0x3, %ecx
cmpl %r12d, %ecx
jne 0x601d
movl %r12d, %ecx
movq 0x10(%rsp), %rdx
incw 0x6(%rdx,%rcx,4)
jmp 0x603e
movl %ecx, %edx
movq 0x10(%rsp), %rsi
movw %r13w, 0x4(%rsi,%rdx,4)
movw $0x1, 0x6(%rsi,%rdx,4)
movl %ebx, %edx
btsl %ecx, %edx
movl %edx, %ebx
movw %dx, (%rsi)
movl %ecx, %r12d
leaq (%r14,%r13), %rcx
incq %rcx
incq %r13
cmpq %r15, %rcx
jb 0x5fba
xorl %eax, %eax
cmpl $0x0, 0xc(%rsp)
sete %cl
movl %ebx, %r11d
testb $0x3, %r11b
je 0x629e
movb %cl, %al
leal 0x2(,%rax,2), %r9d
movq 0x10(%rsp), %rbx
movzwl 0x8(%rbx), %eax
movzwl 0xa(%rbx), %ecx
movw $0x0, 0xa(%rbx)
testq %rcx, %rcx
je 0x62a9
leaq (%r14,%rax), %rdx
addq %rdx, %rcx
xorl %edx, %edx
leaq 0x267a(%rip), %rsi      # 0x8718
movabsq $0x4000000016003ff9, %rdi # imm = 0x4000000016003FF9
movzbl (%r14,%rax), %r8d
leal -0x2(%r9), %r10d
movslq (%rsi,%r10,4), %r10
addq %rsi, %r10
jmpq *%r10
movl $0x4, %r10d
cmpl $0x40, %r8d
je 0x6266
leal -0x30(%r8), %r10d
cmpb $0xa, %r10b
jb 0x60fe
movl %r8d, %r10d
orb $0x20, %r10b
addb $-0x61, %r10b
cmpb $0x1a, %r10b
jb 0x60fe
leal -0x21(%r8), %r10d
cmpl $0x3e, %r10d
ja 0x627e
btq %r10, %rdi
jae 0x627e
cmpl $0x3, %r9d
jne 0x6226
movzwl 0x1e(%rbx), %r8d
incl %r8d
jmp 0x6237
addb $-0x30, %r8b
cmpb $0xa, %r8b
jae 0x6288
cmpl $0xa, %r9d
jne 0x6208
movzwl 0xe(%rbx), %r8d
incl %r8d
jmp 0x6219
movl $0x5, %r10d
cmpl $0x5b, %r8d
je 0x6266
movl %r8d, %r9d
orb $0x20, %r9b
addb $-0x61, %r9b
cmpb $0x1a, %r9b
jb 0x617c
leal -0x30(%r8), %r9d
cmpb $0xa, %r9b
setb %r9b
addb $-0x2d, %r8b
cmpb $0x2, %r8b
setb %r8b
orb %r9b, %r8b
je 0x6288
movw %ax, 0x8(%rbx)
jmp 0x61b0
movl %r8d, %r9d
orb $0x20, %r9b
addb $-0x61, %r9b
cmpb $0x1a, %r9b
jb 0x61b0
leal -0x30(%r8), %r9d
cmpb $0xa, %r9b
setb %r9b
leal -0x2d(%r8), %r10d
cmpb $0x2, %r10b
setb %r10b
orb %r9b, %r10b
je 0x61c1
incl %edx
movw %dx, 0xa(%rbx)
movl $0x6, %r10d
jmp 0x6266
movl $0x9, %r10d
cmpl $0x3a, %r8d
je 0x6266
jmp 0x6288
movl $0x8, %r10d
cmpl $0x5d, %r8d
je 0x6266
leal -0x30(%r8), %r10d
cmpb $0xa, %r10b
jb 0x6250
movl %r8d, %r10d
orb $0x20, %r10b
cmpb $0x61, %r10b
jb 0x6244
cmpb $0x67, %r10b
jb 0x6250
jmp 0x6288
movw %ax, 0xc(%rbx)
orl $0x4, %r11d
movw %r11w, (%rbx)
movw $0x1, %r8w
movw %r8w, 0xe(%rbx)
movl $0xa, %r10d
jmp 0x6266
movw %ax, 0x1c(%rbx)
orl $0x40, %r11d
movw %r11w, (%rbx)
movw $0x1, %r8w
movw %r8w, 0x1e(%rbx)
movl $0x3, %r10d
jmp 0x6266
cmpl $0x2e, %r8d
je 0x6250
cmpl $0x3a, %r8d
jne 0x6288
cmpl $0x7, %r9d
je 0x625a
movw %ax, 0x8(%rbx)
incl %edx
movw %dx, 0xa(%rbx)
movl $0x7, %r10d
leaq (%r14,%rax), %r8
incq %r8
incq %rax
movl %r10d, %r9d
cmpq %rcx, %r8
jb 0x60a8
jmp 0x62ac
cmpl $0x7e, %r8d
je 0x60fe
movl $0x1, %eax
jmp 0x631e
xorl %eax, %eax
testl %edx, %edx
setne %al
jmp 0x631e
movl 0x8(%rsp), %ecx
movq 0x10(%rsp), %rbx
jmp 0x62d0
movl %r9d, %r10d
addl $-0x2, %r10d
cmpl $0x8, %r10d
jae 0x62cc
movl $0x1, %eax
movl $0xaf, %ecx
btl %r10d, %ecx
movl 0x8(%rsp), %ecx
jae 0x62d0
jmp 0x631e
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
je 0x62e2
movl $0x1, %eax
cmpw $0x6, %r11w
je 0x62ea
jmp 0x631e
xorl %eax, %eax
testb $0x4, %r11b
je 0x631e
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 0x631e
movw %cx, 0x2(%rbx)
xorl %eax, %eax
jmp 0x631e
cmpl $0x1, %eax
jne 0x632d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2904(%rip), %rdi      # 0x8c38
leaq 0x2635(%rip), %rsi      # 0x8970
leaq 0x290a(%rip), %rcx      # 0x8c4c
movl $0x925, %edx            # imm = 0x925
callq 0x2120