// File: solaldunckel[P]webserv/srcs/HTTP/Request.cpp
// Function: Request::chunk_trailer()
int Request::chunk_trailer() {
  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);
      break;
    }
    if ((last = buffer_.find(':', 0)) != std::string::npos) {
      header = buffer_.substr(0, last);
      value = buffer_.substr(last + 1, end - last - 1);
      headers_[header] = ft::trim_left(value, ' ');
    }
    else
      return 400;
    buffer_.erase(0, end + 2);
  }
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x57b0
leaq -0x60(%rbp), %rdi
callq 0x57b0
movq -0x100(%rbp), %rdi
leaq 0x200f1(%rip), %rsi     # 0x437bb
xorl %eax, %eax
movl %eax, %edx
callq 0x5a70
movq %rax, -0x18(%rbp)
cmpq $-0x1, %rax
je 0x238c6
movq -0x100(%rbp), %rdi
leaq 0x200cc(%rip), %rsi     # 0x437bb
xorl %eax, %eax
movl %eax, %edx
callq 0x5a70
cmpq $0x0, %rax
jne 0x2372e
movq -0x100(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x2, %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x50d0
jmp 0x23718
jmp 0x238c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x238f5
movq -0x100(%rbp), %rdi
movl $0x3a, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x5730
movq %rax, -0x20(%rbp)
cmpq $-0x1, %rax
je 0x23894
movq -0x100(%rbp), %rsi
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x90(%rbp), %rdi
callq 0x55a0
jmp 0x2376e
leaq -0x40(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movq %rsi, -0x108(%rbp)
callq 0x56d0
movq -0x108(%rbp), %rdi
callq 0x5aa8
movq -0x100(%rbp), %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 0x237ba
leaq -0x60(%rbp), %rdi
movq %rdi, -0x110(%rbp)
leaq -0xb0(%rbp), %rsi
movq %rsi, -0x118(%rbp)
callq 0x56d0
movq -0x118(%rbp), %rdi
callq 0x5aa8
movq -0x110(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x5200
jmp 0x237f9
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
movl $0x20, %edx
callq 0x414d0
jmp 0x23813
movq -0x100(%rbp), %rdi
addq $0xc0, %rdi
leaq -0x40(%rbp), %rsi
callq 0x13cd0
movq %rax, -0x120(%rbp)
jmp 0x23833
movq -0x120(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x56d0
leaq -0xd0(%rbp), %rdi
callq 0x5aa8
leaq -0xf0(%rbp), %rdi
callq 0x5aa8
jmp 0x238a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x23886
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x5aa8
leaq -0xf0(%rbp), %rdi
callq 0x5aa8
jmp 0x238f5
movl $0x190, -0x4(%rbp)      # imm = 0x190
movl $0x1, -0xf4(%rbp)
jmp 0x238d7
movq -0x100(%rbp), %rdi
movq -0x18(%rbp), %rdx
addq $0x2, %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x50d0
jmp 0x238c1
jmp 0x236bc
movl $0x1, -0x4(%rbp)
movl $0x1, -0xf4(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x5aa8
leaq -0x40(%rbp), %rdi
callq 0x5aa8
movl -0x4(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x5aa8
leaq -0x40(%rbp), %rdi
callq 0x5aa8
movq -0x68(%rbp), %rdi
callq 0x5950