// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
testq %rsi, %rsi
je 0x777f
movq %rcx, 0x10(%rsp)
andl $0x0, (%rcx)
xorl %eax, %eax
movl %edx, 0x1c(%rsp)
testl %edx, %edx
setne %al
leal 0x14(,%rax,4), %eax
movq %rsi, 0x20(%rsp)
movq %rdi, %r14
leaq (%rdi,%rsi), %rbp
xorl %r15d, %r15d
pushq $0x7
popq %r12
leaq 0x17d19(%rip), %r13     # 0x1f3f8
xorl %ebx, %ebx
movl $0x0, 0xc(%rsp)
leaq (%r14,%r15), %rcx
cmpq %rbp, %rcx
jae 0x776d
movsbl (%rcx), %esi
movl %eax, %edi
callq 0x70cc
leal -0x15(%rax), %ecx
cmpl $0xa, %ecx
ja 0x7ada
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
xorl %ecx, %ecx
jmp 0x7730
pushq $0x4
jmp 0x772f
pushq $0x1
popq %rdx
movl %edx, %ecx
movl %edx, 0xc(%rsp)
jmp 0x7730
pushq $0x1
jmp 0x772f
pushq $0x5
jmp 0x772f
pushq $0x3
popq %rcx
cmpl %r12d, %ecx
jne 0x7744
movl %r12d, %ecx
movq 0x10(%rsp), %rdx
incw 0x6(%rdx,%rcx,4)
jmp 0x7765
movl %ecx, %edx
movq 0x10(%rsp), %rsi
movw %r15w, 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
incq %r15
jmp 0x76e9
movl %ebx, %eax
andl $0x3, %eax
pushq $0x1
popq %rcx
cmpw $0x1, %ax
jne 0x7791
movl %ecx, %eax
jmp 0x7782
pushq $0x1
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %r12d
testb $0x2, %r12b
jne 0x77a4
movq 0x10(%rsp), %rbx
jmp 0x7a6f
movq 0x10(%rsp), %rbx
movzwl 0xa(%rbx), %eax
movzwl 0x8(%rbx), %edx
andw $0x0, 0xa(%rbx)
xorl %esi, %esi
cmpl $0x0, 0xc(%rsp)
sete %sil
leal 0x2(,%rsi,2), %r10d
leaq (%r14,%rdx), %rsi
addq %rsi, %rax
xorl %esi, %esi
leaq 0x17bf3(%rip), %rdi     # 0x1f3cc
pushq $0xb
popq %r11
pushq $0xa
popq %r9
pushq $0xc
popq %r8
leaq (%r14,%rdx), %r15
cmpq %rax, %r15
jae 0x7a56
movzbl (%r15), %r13d
leal -0x2(%r10), %r15d
movslq (%rdi,%r15,4), %r15
addq %rdi, %r15
jmpq *%r15
cmpl $0x40, %r13d
jne 0x7847
pushq $0x4
jmp 0x7a09
leal -0x30(%r13), %ebp
cmpb $0xa, %bpl
jae 0x777b
cmpl $0xc, %r10d
jne 0x797a
movzwl 0xe(%rbx), %r10d
incl %r10d
jmp 0x798b
cmpl $0x5b, %r13d
jne 0x79b1
pushq $0x5
jmp 0x7a09
leal -0x30(%r13), %ebp
cmpb $0xa, %bpl
jb 0x7884
movl %r13d, %ebp
orb $0x20, %bpl
addb $-0x61, %bpl
cmpb $0x1a, %bpl
jb 0x7884
leal -0x21(%r13), %r15d
cmpl $0x3e, %r15d
ja 0x7a47
movabsq $0x4000000016003ff9, %rbp # imm = 0x4000000016003FF9
btq %r15, %rbp
jae 0x7a47
cmpl $0x3, %r10d
jne 0x79f1
movzwl 0x1e(%rbx), %r10d
incl %r10d
jmp 0x7a02
movl %r13d, %r10d
orb $0x20, %r10b
addb $-0x61, %r10b
cmpb $0x1a, %r10b
jb 0x79e7
leal -0x30(%r13), %r10d
cmpb $0xa, %r10b
setb %r10b
leal -0x2d(%r13), %ebp
cmpb $0x2, %bpl
setb %bpl
orb %r10b, %bpl
jne 0x79e7
movl %r11d, %r10d
cmpl $0x3a, %r13d
je 0x7a3f
jmp 0x777b
cmpl $0x5d, %r13d
je 0x7914
leal -0x30(%r13), %ebp
cmpb $0xa, %bpl
jae 0x7998
cmpl $0x7, %r10d
je 0x7901
movw %dx, 0x8(%rbx)
incl %esi
movw %si, 0xa(%rbx)
pushq $0x7
jmp 0x7a09
cmpl $0x5d, %r13d
jne 0x791b
pushq $0x8
jmp 0x7a09
leal -0x30(%r13), %ebp
movl %r9d, %r10d
cmpb $0xa, %bpl
jb 0x7a39
movl %r13d, %ebp
orb $0x20, %bpl
addb $-0x61, %bpl
movl %r9d, %r10d
cmpb $0x1a, %bpl
jb 0x7a39
movl %r13d, %r10d
addl $-0x25, %r10d
cmpl $0x3a, %r10d
ja 0x7968
movabsq $0x400000000000301, %r15 # imm = 0x400000000000301
btq %r10, %r15
movl %r9d, %r10d
jb 0x7a39
movl %r9d, %r10d
cmpl $0x7e, %r13d
je 0x7a39
jmp 0x777b
movw %dx, 0xc(%rbx)
orl $0x4, %r12d
movw %r12w, (%rbx)
movw $0x1, %r10w
movw %r10w, 0xe(%rbx)
movl %r8d, %r10d
jmp 0x7a3f
movl %r13d, %ebp
orb $0x20, %bpl
cmpb $0x61, %bpl
jb 0x7a0d
cmpb $0x67, %bpl
jb 0x78f7
jmp 0x7a21
movl %r13d, %r10d
orb $0x20, %r10b
addb $-0x61, %r10b
cmpb $0x1a, %r10b
jb 0x79e3
leal -0x30(%r13), %r10d
cmpb $0xa, %r10b
setb %r10b
addb $-0x2d, %r13b
cmpb $0x2, %r13b
setb %bpl
orb %r10b, %bpl
je 0x777b
movw %dx, 0x8(%rbx)
incl %esi
movw %si, 0xa(%rbx)
pushq $0x6
jmp 0x7a09
movw %dx, 0x1c(%rbx)
orl $0x40, %r12d
movw %r12w, (%rbx)
movw $0x1, %r10w
movw %r10w, 0x1e(%rbx)
pushq $0x3
popq %r10
jmp 0x7a3f
cmpl $0x2e, %r13d
je 0x78f7
cmpl $0x3a, %r13d
je 0x78f7
cmpl $0x7, %r10d
jne 0x777b
pushq $0x9
popq %r10
cmpb $0x25, %r13b
jne 0x777b
incl %esi
movw %si, 0xa(%rbx)
incq %rdx
jmp 0x77e5
cmpl $0x7e, %r13d
je 0x7884
jmp 0x777b
addl $-0x2, %r10d
cmpl $0xa, %r10d
jae 0x7a6f
movl $0x3af, %eax            # imm = 0x3AF
btl %r10d, %eax
jb 0x777b
cmpl $0x0, 0x1c(%rsp)
je 0x7a83
cmpw $0x6, %r12w
jne 0x777b
jmp 0x7a8f
xorl %eax, %eax
testb $0x4, %r12b
je 0x7782
movzwl 0xc(%rbx), %edx
movzwl 0xe(%rbx), %eax
leaq (%rax,%rdx), %rsi
cmpq 0x20(%rsp), %rsi
ja 0x7b02
addq %rdx, %r14
addq %r14, %rax
xorl %edx, %edx
cmpq %rax, %r14
jae 0x7acf
imulq $0xa, %rdx, %rdx
movsbq (%r14), %rsi
addq %rsi, %rdx
addq $-0x30, %rdx
incq %r14
cmpq $0xffff, %rdx           # imm = 0xFFFF
jbe 0x7aaa
jmp 0x777b
movw %dx, 0x2(%rbx)
xorl %eax, %eax
jmp 0x7782
cmpl $0x1, %eax
je 0x7782
leaq 0x181d0(%rip), %rdi     # 0x1fcba
leaq 0x17b6f(%rip), %rsi     # 0x1f660
leaq 0x181d6(%rip), %rcx     # 0x1fcce
movl $0x9b0, %edx            # imm = 0x9B0
callq 0x3240
leaq 0x18214(%rip), %rdi     # 0x1fd1d
leaq 0x17b50(%rip), %rsi     # 0x1f660
leaq 0x181b7(%rip), %rcx     # 0x1fcce
movl $0x9df, %edx            # imm = 0x9DF
callq 0x3240