// File: /workspace/github_c_makefile_star2_O1/GangZhuo[P]dohclient/http-parser/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;

  if (buflen == 0) {
    return 1;
  }

  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;

      /* fall through */
      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 = (uint16_t)(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)) &&
      (u->field_set & (1 << UF_HOST)) == 0) {
    return 1;
  }

  if (u->field_set & (1 << UF_HOST)) {
    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)) {
    uint16_t off;
    uint16_t len;
    const char* p;
    const char* end;
    unsigned long v;

    off = u->field_data[UF_PORT].off;
    len = u->field_data[UF_PORT].len;
    end = buf + off + len;

    /* NOTE: The characters are already validated and are in the [0-9] range */
    assert((size_t) (off + len) <= buflen && "Port number overflow");
    v = 0;
    for (p = buf + off; p < end; p++) {
      v *= 10;
      v += *p - '0';

      /* 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 $0x1, %eax
testq %rsi, %rsi
je 0x80eb
movq %rcx, %r14
movq %rdi, %r15
movl $0x0, (%rcx)
movq %rsi, 0x10(%rsp)
jle 0x7d47
leaq (%r15,%rsi), %r13
xorl %eax, %eax
movl %edx, 0x8(%rsp)
testl %edx, %edx
setne %al
leal 0x14(,%rax,4), %eax
movl $0x7, %r12d
xorl %ebp, %ebp
leaq 0x19735(%rip), %rbx     # 0x213cc
movl $0x0, (%rsp)
movsbl (%r15,%rbp), %esi
movl %eax, %edi
callq 0x7604
leal -0x15(%rax), %ecx
cmpl $0xa, %ecx
ja 0x80d6
movslq (%rbx,%rcx,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
xorl %ecx, %ecx
jmp 0x7ceb
movl $0x4, %ecx
jmp 0x7ceb
movl $0x1, %ecx
movl $0x1, (%rsp)
jmp 0x7ceb
movl $0x1, %ecx
jmp 0x7ceb
movl $0x5, %ecx
jmp 0x7ceb
movl $0x3, %ecx
cmpl %r12d, %ecx
jne 0x7cfa
movl %ecx, %ecx
incw 0x6(%r14,%rcx,4)
jmp 0x7d18
movl %ecx, %edx
movw %bp, 0x4(%r14,%rdx,4)
movw $0x1, 0x6(%r14,%rdx,4)
movl $0x1, %edx
shll %cl, %edx
orw %dx, (%r14)
movl %ecx, %r12d
leaq (%r15,%rbp), %rcx
incq %rcx
incq %rbp
cmpq %r13, %rcx
jb 0x7c9e
xorl %eax, %eax
cmpl $0x0, (%rsp)
sete %al
leal 0x2(,%rax,2), %r13d
movl $0x1, %eax
movl 0x8(%rsp), %edx
jmp 0x7d4d
movl $0x4, %r13d
movzwl (%r14), %esi
movl %esi, %ecx
andl $0x3, %ecx
cmpw $0x1, %cx
je 0x80eb
testb $0x2, %sil
je 0x805c
movzwl 0xa(%r14), %r12d
movzwl 0x8(%r14), %ecx
movw $0x0, 0xa(%r14)
testq %r12, %r12
je 0x8040
leaq 0xa(%r14), %rbp
leaq (%r15,%rcx), %rsi
addq %rsi, %r12
leaq 0x1e(%r14), %rsi
movq %rsi, (%rsp)
leaq 0xe(%r14), %rsi
movq %rsi, 0x8(%rsp)
leaq 0x1967d(%rip), %r8      # 0x21424
leaq 0x1964a(%rip), %r9      # 0x213f8
leal -0x2(%r13), %r10d
cmpl $0xa, %r10d
ja 0x7f96
movzbl (%r15,%rcx), %esi
movslq (%r9,%r10,4), %r10
addq %r9, %r10
jmpq *%r10
cmpl $0x40, %esi
jne 0x7e07
movl $0x4, %r10d
jmp 0x7f6d
addl $-0x30, %esi
cmpb $0xa, %sil
jae 0x7f96
movl $0xc, %r10d
jmp 0x7f6d
cmpl $0x5b, %esi
jne 0x7f39
movl $0x5, %r10d
jmp 0x7f6d
leal -0x30(%rsi), %ebx
xorl %r11d, %r11d
movl $0x3, %r10d
cmpb $0xa, %bl
jb 0x7f9f
movl %esi, %ebx
orb $0x20, %bl
addb $-0x61, %bl
cmpb $0x1a, %bl
jb 0x7f9f
xorl %r11d, %r11d
leal -0x21(%rsi), %ebx
cmpl $0x3e, %ebx
ja 0x7f32
movabsq $0x4000000016003ff9, %rdi # imm = 0x4000000016003FF9
btq %rbx, %rdi
leaq 0x195a7(%rip), %r9      # 0x213f8
jb 0x7f9f
jmp 0x7f32
movl %esi, %r11d
orb $0x20, %r11b
addb $-0x61, %r11b
movl $0x6, %r10d
cmpb $0x1a, %r11b
jb 0x7f6d
leal -0x30(%rsi), %r11d
cmpb $0xa, %r11b
setb %r11b
leal -0x2d(%rsi), %ebx
cmpb $0x2, %bl
setb %bl
orb %r11b, %bl
jne 0x7f6d
cmpl $0x3a, %esi
jne 0x7f96
movl $0xb, %r10d
jmp 0x7f6d
cmpl $0x5d, %esi
je 0x7ee7
leal -0x30(%rsi), %r11d
movl $0x7, %r10d
cmpb $0xa, %r11b
jb 0x7f6d
movl %esi, %r11d
orb $0x20, %r11b
cmpb $0x61, %r11b
jb 0x7f72
cmpb $0x67, %r11b
jb 0x7f6d
jmp 0x7f7f
cmpl $0x5d, %esi
jne 0x7eef
movl $0x8, %r10d
jmp 0x7f6d
leal -0x30(%rsi), %ebx
xorl %r11d, %r11d
movl $0xa, %r10d
cmpb $0xa, %bl
jb 0x7f9f
movl %esi, %ebx
orb $0x20, %bl
addb $-0x61, %bl
cmpb $0x1a, %bl
jb 0x7f9f
xorl %r11d, %r11d
movl %esi, %ebx
addl $-0x25, %ebx
cmpl $0x3a, %ebx
ja 0x7f32
movabsq $0x400000000000301, %rdi # imm = 0x400000000000301
btq %rbx, %rdi
jb 0x7f9f
cmpl $0x7e, %esi
jne 0x7f96
jmp 0x7f9f
movl %esi, %r11d
orb $0x20, %r11b
addb $-0x61, %r11b
movl $0x6, %r10d
cmpb $0x1a, %r11b
jb 0x7f6d
leal -0x30(%rsi), %r11d
cmpb $0xa, %r11b
setb %r11b
addb $-0x2d, %sil
cmpb $0x2, %sil
setb %sil
orb %r11b, %sil
je 0x7f96
xorl %r11d, %r11d
jmp 0x7f9f
xorl %r11d, %r11d
cmpl $0x2e, %esi
je 0x7f9f
cmpl $0x3a, %esi
je 0x7f9f
cmpl $0x7, %r13d
jne 0x7f96
cmpb $0x25, %sil
jne 0x7f96
xorl %r11d, %r11d
movl $0x9, %r10d
jmp 0x7f9f
movl $0x1, %r10d
movb $0x1, %r11b
testb %r11b, %r11b
je 0x7fa9
movl %r13d, %r10d
jmp 0x8014
leal -0x3(%r10), %esi
cmpl $0x9, %esi
ja 0x8014
movslq (%r8,%rsi,4), %rbx
addq %r8, %rbx
movq %rbp, %rsi
jmpq *%rbx
movq (%rsp), %rsi
cmpl $0x3, %r13d
je 0x8011
movw %cx, 0x1c(%r14)
movw $0x0, 0x1e(%r14)
orb $0x40, (%r14)
movq (%rsp), %rsi
jmp 0x8011
movq 0x8(%rsp), %rsi
cmpl $0xc, %r13d
je 0x8011
movw %cx, 0xc(%r14)
movw $0x0, 0xe(%r14)
orb $0x4, (%r14)
movq 0x8(%rsp), %rsi
jmp 0x8011
movq %rbp, %rsi
cmpl $0x6, %r13d
je 0x8011
movw %cx, 0x8(%r14)
movq %rbp, %rsi
incw (%rsi)
testb %r11b, %r11b
jne 0x80eb
leaq (%r15,%rcx), %rsi
incq %rsi
incq %rcx
movl %r10d, %r13d
cmpq %r12, %rsi
jb 0x7dae
jmp 0x8043
movq %rbp, %rsi
cmpl $0x7, %r13d
jne 0x8009
jmp 0x8011
movl %r13d, %r10d
addl $-0x2, %r10d
cmpl $0xa, %r10d
jae 0x805c
movl $0x3af, %ecx            # imm = 0x3AF
btl %r10d, %ecx
jb 0x80eb
testl %edx, %edx
je 0x806b
cmpw $0x6, (%r14)
jne 0x80eb
testb $0x4, (%r14)
je 0x80e9
movzwl 0xc(%r14), %esi
movzwl 0xe(%r14), %edi
leaq (%rdi,%rsi), %rcx
cmpq 0x10(%rsp), %rcx
ja 0x8119
testw %di, %di
setne %cl
je 0x80dd
leaq (%r15,%rsi), %rdx
movsbq (%rdx), %r8
addq $-0x30, %r8
cmpq $0xffff, %r8            # imm = 0xFFFF
ja 0x80e5
addq %rdi, %rdx
addq %r15, %rsi
incq %rsi
cmpq %rdx, %rsi
setb %cl
jae 0x80e0
leaq (%r8,%r8,4), %r8
movsbq (%rsi), %rdi
leaq (%rdi,%r8,2), %r8
addq $-0x30, %r8
incq %rsi
cmpq $0xffff, %r8            # imm = 0xFFFF
jbe 0x80b0
jmp 0x80e5
cmpl $0x1, %eax
jne 0x80fa
jmp 0x80eb
xorl %r8d, %r8d
movw %r8w, 0x2(%r14)
testb %cl, %cl
jne 0x80eb
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19bd9(%rip), %rdi     # 0x21cda
leaq 0x19578(%rip), %rsi     # 0x21680
leaq 0x19bdf(%rip), %rcx     # 0x21cee
movl $0x9b0, %edx            # imm = 0x9B0
callq 0x3230
leaq 0x19c1d(%rip), %rdi     # 0x21d3d
leaq 0x19559(%rip), %rsi     # 0x21680
leaq 0x19bc0(%rip), %rcx     # 0x21cee
movl $0x9df, %edx            # imm = 0x9DF
callq 0x3230