// File: /workspace/github_c_makefile_star2_O3/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
testq %rsi, %rsi
je 0x7dbb
movl $0x0, (%rcx)
jle 0x7aac
movq %rdi, %r14
movq %rcx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
leaq (%rdi,%rsi), %r13
xorl %eax, %eax
movl %edx, (%rsp)
testl %edx, %edx
setne %al
leal 0x14(,%rax,4), %eax
movl $0x7, %r12d
xorl %ebp, %ebp
leaq 0x199ed(%rip), %r15     # 0x213cc
xorl %ebx, %ebx
movl $0x0, 0x4(%rsp)
movsbl (%r14,%rbp), %esi
movl %eax, %edi
callq 0x7358
leal -0x15(%rax), %ecx
cmpl $0xa, %ecx
ja 0x7d6d
movslq (%r15,%rcx,4), %rcx
addq %r15, %rcx
jmpq *%rcx
xorl %ecx, %ecx
jmp 0x7a37
movl $0x4, %ecx
jmp 0x7a37
movl $0x1, %ecx
movl $0x1, 0x4(%rsp)
jmp 0x7a37
movl $0x1, %ecx
jmp 0x7a37
movl $0x5, %ecx
jmp 0x7a37
movl $0x3, %ecx
cmpl %r12d, %ecx
jne 0x7a4b
movl %r12d, %ecx
movq 0x8(%rsp), %rdx
incw 0x6(%rdx,%rcx,4)
jmp 0x7a6b
movl %ecx, %edx
movq 0x8(%rsp), %rsi
movw %bp, 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,%rbp), %rcx
incq %rcx
incq %rbp
cmpq %r13, %rcx
jb 0x79e9
xorl %eax, %eax
cmpl $0x0, 0x4(%rsp)
sete %cl
movl %ebx, %edx
andl $0x3, %edx
cmpw $0x1, %dx
je 0x7dbb
movl %ebx, %ebp
testb $0x2, %bpl
jne 0x7ab8
movl (%rsp), %eax
movq 0x8(%rsp), %rbx
jmp 0x7db1
xorl %eax, %eax
testl %edx, %edx
setne %al
jmp 0x7dc0
movb %cl, %al
leal 0x2(,%rax,2), %r11d
movq 0x8(%rsp), %rbx
movzwl 0xa(%rbx), %eax
movzwl 0x8(%rbx), %ecx
movw $0x0, 0xa(%rbx)
testq %rax, %rax
je 0x7d91
leaq (%r14,%rcx), %rdx
addq %rdx, %rax
xorl %edx, %edx
leaq 0x1990a(%rip), %rsi     # 0x213f8
movabsq $0x4000000016003ff9, %rdi # imm = 0x4000000016003FF9
movabsq $0x400000000000301, %r8 # imm = 0x400000000000301
movzbl (%r14,%rcx), %r9d
leal -0x2(%r11), %r10d
movslq (%rsi,%r10,4), %r10
addq %rsi, %r10
jmpq *%r10
movl $0x4, %r10d
cmpl $0x40, %r9d
je 0x7d49
leal -0x30(%r9), %r10d
cmpb $0xa, %r10b
jb 0x7b58
movl %r9d, %r10d
orb $0x20, %r10b
addb $-0x61, %r10b
cmpb $0x1a, %r10b
jb 0x7b58
leal -0x21(%r9), %r10d
cmpl $0x3e, %r10d
ja 0x7d61
btq %r10, %rdi
jae 0x7d61
cmpl $0x3, %r11d
jne 0x7cfd
movzwl 0x1e(%rbx), %r9d
incl %r9d
jmp 0x7d0c
addl $-0x30, %r9d
cmpb $0xa, %r9b
jae 0x7dbb
cmpl $0xc, %r11d
jne 0x7cc8
movzwl 0xe(%rbx), %r9d
incl %r9d
jmp 0x7cd7
movl $0x5, %r10d
cmpl $0x5b, %r9d
je 0x7d49
movl %r9d, %r10d
orb $0x20, %r10b
addb $-0x61, %r10b
cmpb $0x1a, %r10b
jb 0x7bd6
leal -0x30(%r9), %r10d
cmpb $0xa, %r10b
setb %r10b
addb $-0x2d, %r9b
cmpb $0x2, %r9b
setb %r9b
orb %r10b, %r9b
je 0x7dbb
movw %cx, 0x8(%rbx)
jmp 0x7c0a
movl %r9d, %r10d
orb $0x20, %r10b
addb $-0x61, %r10b
cmpb $0x1a, %r10b
jb 0x7c0a
leal -0x30(%r9), %r10d
cmpb $0xa, %r10b
setb %r10b
leal -0x2d(%r9), %r11d
cmpb $0x2, %r11b
setb %r11b
orb %r10b, %r11b
je 0x7c1b
incl %edx
movw %dx, 0xa(%rbx)
movl $0x6, %r10d
jmp 0x7d49
movl $0xb, %r10d
cmpl $0x3a, %r9d
je 0x7d49
jmp 0x7dbb
movl $0x8, %r10d
cmpl $0x5d, %r9d
je 0x7d49
leal -0x30(%r9), %r10d
cmpb $0xa, %r10b
jae 0x7ce4
cmpl $0x7, %r11d
je 0x7c58
movw %cx, 0x8(%rbx)
incl %edx
movw %dx, 0xa(%rbx)
movl $0x7, %r10d
jmp 0x7d49
movl $0x8, %r10d
cmpl $0x5d, %r9d
je 0x7d49
leal -0x30(%r9), %r11d
movl $0xa, %r10d
cmpb $0xa, %r11b
jb 0x7d43
movl %r9d, %r11d
orb $0x20, %r11b
addb $-0x61, %r11b
cmpb $0x1a, %r11b
jb 0x7d43
movl %r9d, %r11d
addl $-0x25, %r11d
cmpl $0x3a, %r11d
ja 0x7cb9
btq %r11, %r8
jb 0x7d43
cmpl $0x7e, %r9d
je 0x7d43
jmp 0x7dbb
movw %cx, 0xc(%rbx)
orl $0x4, %ebp
movw %bp, (%rbx)
movw $0x1, %r9w
movw %r9w, 0xe(%rbx)
movl $0xc, %r10d
jmp 0x7d49
movl %r9d, %r10d
orb $0x20, %r10b
cmpb $0x61, %r10b
jb 0x7d19
cmpb $0x67, %r10b
jb 0x7c4e
jmp 0x7d2d
movw %cx, 0x1c(%rbx)
orl $0x40, %ebp
movw %bp, (%rbx)
movw $0x1, %r9w
movw %r9w, 0x1e(%rbx)
movl $0x3, %r10d
jmp 0x7d49
cmpl $0x2e, %r9d
je 0x7c4e
cmpl $0x3a, %r9d
je 0x7c4e
cmpl $0x7, %r11d
jne 0x7dbb
movl $0x9, %r10d
cmpb $0x25, %r9b
jne 0x7dbb
incl %edx
movw %dx, 0xa(%rbx)
leaq (%r14,%rcx), %r9
incq %r9
incq %rcx
movl %r10d, %r11d
cmpq %rax, %r9
jb 0x7b02
jmp 0x7d94
cmpl $0x7e, %r9d
je 0x7b58
jmp 0x7dbb
cmpl $0x1, %eax
je 0x7dc0
leaq 0x19f41(%rip), %rdi     # 0x21cba
leaq 0x198e0(%rip), %rsi     # 0x21660
leaq 0x19f47(%rip), %rcx     # 0x21cce
movl $0x9b0, %edx            # imm = 0x9B0
callq 0x3230
movl %r11d, %r10d
addl $-0x2, %r10d
cmpl $0xa, %r10d
jae 0x7dae
movl $0x3af, %eax            # imm = 0x3AF
btl %r10d, %eax
movl (%rsp), %eax
jae 0x7db1
jmp 0x7dbb
movl (%rsp), %eax
testl %eax, %eax
je 0x7dcf
cmpw $0x6, %bp
je 0x7dd7
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
testb $0x4, %bpl
je 0x7dc0
movzwl 0xc(%rbx), %edx
movzwl 0xe(%rbx), %ecx
leaq (%rcx,%rdx), %rax
cmpq 0x10(%rsp), %rax
ja 0x7e24
xorl %eax, %eax
testw %cx, %cx
je 0x7e1c
addq %rdx, %r14
addq %r14, %rcx
xorl %edx, %edx
leaq (%rdx,%rdx,4), %rdx
movsbq (%r14), %rsi
leaq (%rsi,%rdx,2), %rdx
addq $-0x30, %rdx
cmpq $0xffff, %rdx           # imm = 0xFFFF
ja 0x7dbb
incq %r14
cmpq %rcx, %r14
jb 0x7df9
jmp 0x7e1e
xorl %edx, %edx
movw %dx, 0x2(%rbx)
jmp 0x7dc0
leaq 0x19ef2(%rip), %rdi     # 0x21d1d
leaq 0x1982e(%rip), %rsi     # 0x21660
leaq 0x19e95(%rip), %rcx     # 0x21cce
movl $0x9df, %edx            # imm = 0x9DF
callq 0x3230