// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
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 0x8d29
movl -0x2c(%rbp), %edi
movq -0x38(%rbp), %rax
movsbl (%rax), %esi
callq 0x8470
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
subl $0x1e, %eax
ja 0x8c96
movq -0x58(%rbp), %rax
leaq 0x2b10(%rip), %rcx      # 0xb758
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, -0x4(%rbp)
jmp 0x8dce
jmp 0x8d18
movl $0x0, -0x3c(%rbp)
jmp 0x8cb5
movl $0x1, -0x44(%rbp)
movl $0x1, -0x3c(%rbp)
jmp 0x8cb5
movl $0x3, -0x3c(%rbp)
jmp 0x8cb5
movl $0x4, -0x3c(%rbp)
jmp 0x8cb5
movl $0x5, -0x3c(%rbp)
jmp 0x8cb5
leaq 0x308f(%rip), %rdi      # 0xbd2c
leaq 0x2dc0(%rip), %rsi      # 0xba64
movl $0x925, %edx            # imm = 0x925
leaq 0x3090(%rip), %rcx      # 0xbd40
callq 0x2110
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jne 0x8cd4
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
movw 0x6(%rax,%rcx,4), %dx
addw $0x1, %dx
movw %dx, 0x6(%rax,%rcx,4)
jmp 0x8d18
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 0x8c06
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
andl $0x3, %eax
cmpl $0x0, %eax
je 0x8d58
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x44(%rbp), %edx
callq 0x8de0
cmpl $0x0, %eax
je 0x8d56
movl $0x1, -0x4(%rbp)
jmp 0x8dce
jmp 0x8d58
cmpl $0x0, -0x1c(%rbp)
je 0x8d73
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
cmpl $0x6, %eax
je 0x8d73
movl $0x1, -0x4(%rbp)
jmp 0x8dce
movq -0x28(%rbp), %rax
movzwl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x8dc7
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movzwl 0xc(%rax), %eax
cltq
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x2280
movq %rax, -0x50(%rbp)
cmpq $0xffff, -0x50(%rbp)    # imm = 0xFFFF
jbe 0x8db8
movl $0x1, -0x4(%rbp)
jmp 0x8dce
movq -0x50(%rbp), %rax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0x2(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)