// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xaef1
movl $0x1, -0x4(%rbp)
jmp 0xb1c2
movq -0x28(%rbp), %rax
movw $0x0, (%rax)
movq -0x28(%rbp), %rax
movw $0x0, 0x2(%rax)
movl -0x1c(%rbp), %edx
movl $0x14, %eax
movl $0x18, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x2c(%rbp)
movl $0x7, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
addq -0x18(%rbp), %rcx
cmpq %rcx, %rax
jae 0xb04c
movl -0x2c(%rbp), %edi
movq -0x38(%rbp), %rax
movsbl (%rax), %esi
callq 0xa310
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x68(%rbp)
subl $0x1e, %eax
ja 0xafb9
movq -0x68(%rbp), %rax
leaq 0x29a09(%rip), %rcx     # 0x34974
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, -0x4(%rbp)
jmp 0xb1c2
jmp 0xb03b
movl $0x0, -0x3c(%rbp)
jmp 0xafd8
movl $0x1, -0x44(%rbp)
movl $0x1, -0x3c(%rbp)
jmp 0xafd8
movl $0x3, -0x3c(%rbp)
jmp 0xafd8
movl $0x4, -0x3c(%rbp)
jmp 0xafd8
movl $0x5, -0x3c(%rbp)
jmp 0xafd8
leaq 0x2a32e(%rip), %rdi     # 0x352ee
leaq 0x29ccd(%rip), %rsi     # 0x34c94
movl $0x9b0, %edx            # imm = 0x9B0
leaq 0x2a32f(%rip), %rcx     # 0x35302
callq 0x3250
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0xaff7
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movw 0x6(%rax,%rcx,4), %dx
addw $0x1, %dx
movw %dx, 0x6(%rax,%rcx,4)
jmp 0xb03b
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movw %ax, %dx
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movw %dx, 0x4(%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movw $0x1, 0x6(%rax,%rcx,4)
movl -0x3c(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movq -0x28(%rbp), %rax
movzwl (%rax), %ecx
orl %edx, %ecx
movw %cx, (%rax)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0xaf29
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xb076
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0xb076
movl $0x1, -0x4(%rbp)
jmp 0xb1c2
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xb0a8
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0xb1d0
cmpl $0x0, %eax
je 0xb0a6
movl $0x1, -0x4(%rbp)
jmp 0xb1c2
jmp 0xb0a8
cmpl $0x0, -0x1c(%rbp)
je 0xb0c6
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x6, %eax
je 0xb0c6
movl $0x1, -0x4(%rbp)
jmp 0xb1c2
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xb1bb
movq -0x28(%rbp), %rax
movw 0xc(%rax), %ax
movw %ax, -0x46(%rbp)
movq -0x28(%rbp), %rax
movw 0xe(%rax), %ax
movw %ax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movzwl -0x46(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movzwl -0x48(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movzwl -0x46(%rbp), %eax
movzwl -0x48(%rbp), %ecx
addl %ecx, %eax
cltq
cmpq -0x18(%rbp), %rax
ja 0xb129
movb $0x1, %al
testb $0x1, %al
jne 0xb127
jmp 0xb129
jmp 0xb148
leaq 0x2a236(%rip), %rdi     # 0x35366
leaq 0x29b5d(%rip), %rsi     # 0x34c94
movl $0x9df, %edx            # imm = 0x9DF
leaq 0x2a1bf(%rip), %rcx     # 0x35302
callq 0x3250
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rax
movzwl -0x46(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0xb1ac
imulq $0xa, -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
cltq
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0xffff, -0x60(%rbp)    # imm = 0xFFFF
jbe 0xb19c
movl $0x1, -0x4(%rbp)
jmp 0xb1c2
jmp 0xb19e
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0xb162
movq -0x60(%rbp), %rax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0x2(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)