// File: /workspace/github_cpp_makefile_star2_O3/solaldunckel[P]webserv/srcs/HTTP/Request.cpp
// Function: Request::headers()
int Request::headers() {
  size_t end, last;
  std::string header;
  std::string value;

  while ((end = buffer_.find("\r\n")) != std::string::npos) {
    if (buffer_.find("\r\n") == 0) {
      buffer_.erase(0, end + 2);
      status_ = PREBODY;
      break;
    }
    if ((last = buffer_.find(':', 0)) != std::string::npos) {
      if (last == 0 || buffer_[last - 1] == ' ')
        return 400;
      header = buffer_.substr(0, last);
      value = buffer_.substr(last + 1, end - last - 1);
      if (header == "Host" && headers_.count(header))
        return 400;
      if (header.length() > 1000 || value.length() > 4000)
        return 400;
      headers_[header] = ft::trim_left(ft::trim_right(value, ' '), ' ');
      if (headers_[header].empty())
        headers_.erase(header);
    }
    else
      return 400;
    buffer_.erase(0, end + 2);
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
leaq 0x20(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xc0(%rdi), %r12
leaq 0xc8(%rdi), %rax
movq %rax, 0x90(%rsp)
leaq 0x14224(%rip), %r14     # 0x257df
leaq 0x30(%rsp), %r15
movl $0x2, %ecx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4780
movq %rax, 0x8(%rsp)
cmpq $-0x1, %rax
je 0x11823
movl $0x2, %ecx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4780
testq %rax, %rax
je 0x1182d
movq %r12, %r14
movq %rbx, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4590
movq %rax, %r13
movl $0x190, %eax            # imm = 0x190
movq %rax, (%rsp)
leaq 0x1(%r13), %r12
cmpq $0x2, %r12
jb 0x11852
movq (%rbx), %rax
cmpb $0x20, -0x1(%rax,%r13)
je 0x11852
movq %rbx, %rsi
movq %r15, %rbx
movq %r15, %rdi
movq %rsi, %rbp
xorl %edx, %edx
movq %r13, %rcx
callq 0x4490
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x4570
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x11676
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4470
notq %r13
addq 0x8(%rsp), %r13
movq %r15, %rbx
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x4490
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x4570
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
movq %r14, %r12
je 0x116be
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x10(%rsp), %r13
movq %r13, %rdi
leaq 0x13c7b(%rip), %rsi     # 0x25348
callq 0x40f0
testl %eax, %eax
leaq 0x14104(%rip), %r14     # 0x257df
movq %rbp, %rbx
jne 0x116f9
movq %r12, %rdi
movq %r13, %rsi
callq 0x12402
cmpq 0x90(%rsp), %rax
jne 0x11852
cmpq $0x3e8, 0x18(%rsp)      # imm = 0x3E8
ja 0x11852
movq 0x58(%rsp), %rdx
cmpq $0xfa0, %rdx            # imm = 0xFA0
ja 0x11852
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x50(%rsp), %rsi
addq %rsi, %rdx
leaq 0x70(%rsp), %r13
movq %r13, %rdi
callq 0x6c2a
leaq 0x98(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movl $0x20, %edx
callq 0x2425a
movq %r15, %rdi
movq %rbp, %rsi
movl $0x20, %edx
callq 0x241ea
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0xa8c4
movq %rax, %rdi
movq %r15, %rsi
callq 0x4570
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x11798
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x117bd
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x117df
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4470
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0xa8c4
cmpq $0x0, 0x8(%rax)
jne 0x1180b
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x1246c
movq %r12, %rdi
movq %rax, %rsi
callq 0x12540
movq 0x8(%rsp), %rdx
addq $0x2, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x40b0
jmp 0x115c0
movq $0x0, (%rsp)
jmp 0x11852
movq 0x8(%rsp), %rdx
addq $0x2, %rdx
movq $0x0, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x40b0
movl $0x2, 0x120(%rbx)
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x1186e
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1188a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4470
movq (%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1191a
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x118c6
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x118c6
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x118f0
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x118f0
movq %rax, %rbx
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x1191d
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x1191d
jmp 0x1191a
jmp 0x1191a
jmp 0x1191a
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x11939
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x11955
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4790
nop