// File: /workspace/github_cpp_makefile_star2_O1/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 0x1431e(%rip), %r14     # 0x257df
leaq 0x30(%rsp), %r15
movl $0x2, %ecx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4770
movq %rax, 0x8(%rsp)
cmpq $-0x1, %rax
je 0x11729
movl $0x2, %ecx
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4770
testq %rax, %rax
je 0x11733
movq %r12, %r14
movq %rbx, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4580
movq %rax, %r13
movl $0x190, %eax            # imm = 0x190
movq %rax, (%rsp)
leaq 0x1(%r13), %r12
cmpq $0x2, %r12
jb 0x11758
movq (%rbx), %rax
cmpb $0x20, -0x1(%rax,%r13)
je 0x11758
movq %rbx, %rsi
movq %r15, %rbx
movq %r15, %rdi
movq %rsi, %rbp
xorl %edx, %edx
movq %r13, %rcx
callq 0x4480
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x4560
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x1157c
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4460
notq %r13
addq 0x8(%rsp), %r13
movq %r15, %rbx
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x4480
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x4560
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
movq %r14, %r12
je 0x115c4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0x10(%rsp), %r13
movq %r13, %rdi
leaq 0x13d75(%rip), %rsi     # 0x25348
callq 0x40f0
testl %eax, %eax
leaq 0x141fe(%rip), %r14     # 0x257df
movq %rbp, %rbx
jne 0x115ff
movq %r12, %rdi
movq %r13, %rsi
callq 0x1235c
cmpq 0x90(%rsp), %rax
jne 0x11758
cmpq $0x3e8, 0x18(%rsp)      # imm = 0x3E8
ja 0x11758
movq 0x58(%rsp), %rdx
cmpq $0xfa0, %rdx            # imm = 0xFA0
ja 0x11758
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x50(%rsp), %rsi
addq %rsi, %rdx
leaq 0x70(%rsp), %r13
movq %r13, %rdi
callq 0x6bac
leaq 0x98(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movl $0x20, %edx
callq 0x242d2
movq %r15, %rdi
movq %rbp, %rsi
movl $0x20, %edx
callq 0x24262
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0xa86c
movq %rax, %rdi
movq %r15, %rsi
callq 0x4560
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x1169e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x116c3
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x116e5
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4460
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0xa86c
cmpq $0x0, 0x8(%rax)
jne 0x11711
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x123c8
movq %r12, %rdi
movq %rax, %rsi
callq 0x12494
movq 0x8(%rsp), %rdx
addq $0x2, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x40b0
jmp 0x114c6
movq $0x0, (%rsp)
jmp 0x11758
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 0x11774
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x11790
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4460
movq (%rsp), %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11820
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x117cc
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x117cc
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x117f6
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x117f6
movq %rax, %rbx
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x11823
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x11823
jmp 0x11820
jmp 0x11820
jmp 0x11820
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x1183f
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1185b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rbx, %rdi
callq 0x4780
nop