// File: solaldunckel[P]webserv/srcs/HTTP/CGI.cpp
// Function: CGI::parseHeaders(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>&)
void CGI::parseHeaders(std::map<std::string, std::string> &headers) {
  size_t end, last;
  std::string header;

  while ((end = body_.find("\r\n")) != std::string::npos) {
    if (body_.find("\r\n") == 0) {
      body_.erase(0, end + 2);
      break;
    }
    if ((last = body_.find(':', 0)) != std::string::npos) {
      header = body_.substr(0, last);
      headers[header] = ft::trim_left(body_.substr(last + 1, end - last - 1), ' ');
    }
    body_.erase(0, end + 2);
  }
  if (headers.count("Content-Length")) {
    size_t size = ft::stoi(headers["Content-Length"]);

    body_.erase(size);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x57b0
movq -0x110(%rbp), %rdi
addq $0xb8, %rdi
leaq 0x22daf(%rip), %rsi     # 0x437bb
xorl %eax, %eax
movl %eax, %edx
callq 0x5a70
movq %rax, -0x18(%rbp)
cmpq $-0x1, %rax
je 0x20bd3
movq -0x110(%rbp), %rdi
addq $0xb8, %rdi
leaq 0x22d83(%rip), %rsi     # 0x437bb
xorl %eax, %eax
movl %eax, %edx
callq 0x5a70
cmpq $0x0, %rax
jne 0x20a7e
movq -0x110(%rbp), %rdi
addq $0xb8, %rdi
movq -0x18(%rbp), %rdx
addq $0x2, %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x50d0
jmp 0x20a68
jmp 0x20bd3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x20d99
movq -0x110(%rbp), %rdi
addq $0xb8, %rdi
movl $0x3a, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x5730
movq %rax, -0x20(%rbp)
cmpq $-0x1, %rax
je 0x20bad
movq -0x110(%rbp), %rsi
addq $0xb8, %rsi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x70(%rbp), %rdi
callq 0x55a0
jmp 0x20ac9
leaq -0x40(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movq %rsi, -0x118(%rbp)
callq 0x56d0
movq -0x118(%rbp), %rdi
callq 0x5aa8
movq -0x110(%rbp), %rsi
addq $0xb8, %rsi
movq -0x20(%rbp), %rcx
movq %rcx, %rdx
incq %rdx
movq -0x18(%rbp), %rax
notq %rcx
addq %rax, %rcx
leaq -0xb0(%rbp), %rdi
callq 0x55a0
jmp 0x20b19
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
movl $0x20, %edx
callq 0x414d0
jmp 0x20b33
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x19050
movq %rax, -0x120(%rbp)
jmp 0x20b49
movq -0x120(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x56d0
leaq -0x90(%rbp), %rdi
callq 0x5aa8
leaq -0xb0(%rbp), %rdi
callq 0x5aa8
jmp 0x20bad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x20b9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x5aa8
leaq -0xb0(%rbp), %rdi
callq 0x5aa8
jmp 0x20d99
movq -0x110(%rbp), %rdi
addq $0xb8, %rdi
movq -0x18(%rbp), %rdx
addq $0x2, %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x50d0
jmp 0x20bce
jmp 0x209f7
movq -0x10(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x5960
movq -0x128(%rbp), %rdx
leaq 0x229e1(%rip), %rsi     # 0x435e0
leaq -0xd0(%rbp), %rdi
callq 0x6be0
jmp 0x20c0d
movq -0x130(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x20dd0
movq %rax, -0x138(%rbp)
jmp 0x20c29
leaq -0xd0(%rbp), %rdi
callq 0x5aa8
leaq -0xd1(%rbp), %rdi
callq 0x55e0
movq -0x138(%rbp), %rax
cmpq $0x0, %rax
je 0x20d87
movq -0x10(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x5960
movq -0x140(%rbp), %rdx
leaq 0x22962(%rip), %rsi     # 0x435e0
leaq -0x100(%rbp), %rdi
callq 0x6be0
jmp 0x20c8c
movq -0x148(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x20e30
movq %rax, -0x150(%rbp)
jmp 0x20ca8
movq -0x150(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x41890
movl %eax, -0x154(%rbp)
jmp 0x20cc5
movl -0x154(%rbp), %eax
cltq
movq %rax, -0x160(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x5aa8
leaq -0x101(%rbp), %rdi
callq 0x55e0
movq -0x160(%rbp), %rax
movq -0x110(%rbp), %rdi
movq %rax, -0xe0(%rbp)
addq $0xb8, %rdi
movq -0xe0(%rbp), %rsi
movq $-0x1, %rdx
callq 0x50d0
jmp 0x20d1d
jmp 0x20d87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x20d45
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x5aa8
leaq -0xd1(%rbp), %rdi
callq 0x55e0
jmp 0x20d99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x20d79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x5aa8
leaq -0x101(%rbp), %rdi
callq 0x55e0
jmp 0x20d99
leaq -0x40(%rbp), %rdi
callq 0x5aa8
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x5aa8
movq -0x48(%rbp), %rdi
callq 0x5950
nopl (%rax,%rax)