// File: /workspace/github_cpp_makefile_star2_O1/solaldunckel[P]webserv/srcs/HTTP/Request.cpp
// Function: Request::prebody()
int Request::prebody() {
  body_offset_ = 0;

  if (headers_.find("Host") == headers_.end() || headers_["Host"].empty())
    return 400;

  if (headers_["Host"].find("@") != std::string::npos)
    return 400;

  if (headers_.find("Transfer-Encoding") != headers_.end() && headers_["Transfer-Encoding"] == "chunked") {
    status_ = CHUNK;
    chunk_status_ = CHUNK_SIZE;
  } else if (headers_.find("Content-Length") != headers_.end()) {
    if (headers_["Content-Length"].find_first_not_of("0123456789") != std::string::npos)
      return 400;
    try {
      length_ = ft::stoi(headers_["Content-Length"]);
      if (length_ < 0)
        throw std::invalid_argument("negative content-length");
    }
    catch (std::exception &e) {
      return 400;
    }
    status_ = BODY;
  }
  else {
    return 1;
  }
  if (method_ != "POST" && method_ != "PUT")
    return 1;
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl $0x0, 0xf0(%rdi)
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x13ab9(%rip), %rsi     # 0x25348
leaq 0x13ab6(%rip), %rdx     # 0x2534c
leaq 0x8(%rsp), %rdi
callq 0x578e
leaq 0xc0(%rbx), %r14
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x12566
movq %rax, %r15
leaq 0xc8(%rbx), %r13
cmpq %r13, %rax
je 0x118fd
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x13a74(%rip), %rsi     # 0x25348
leaq 0x13a71(%rip), %rdx     # 0x2534c
leaq 0x48(%rsp), %rdi
callq 0x578e
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0xa7d2
cmpq $0x0, 0x8(%rax)
sete %r12b
jmp 0x11900
movb $0x1, %r12b
cmpq %r13, %r15
je 0x11920
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11920
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1193c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
movl $0x190, %ebp            # imm = 0x190
testb %r12b, %r12b
jne 0x119ae
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x139ee(%rip), %rsi     # 0x25348
leaq 0x139eb(%rip), %rdx     # 0x2534c
callq 0x578e
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0xa7d2
leaq 0x13e01(%rip), %rsi     # 0x2577b
movl $0x1, %ecx
movq %rax, %rdi
xorl %edx, %edx
callq 0x4770
movq %rax, %r15
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119a8
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
cmpq $-0x1, %r15
je 0x119bf
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x13daa(%rip), %rsi     # 0x2577d
leaq 0x13db4(%rip), %rdx     # 0x2578e
callq 0x578e
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x12566
movq %rax, %r15
cmpq %r13, %rax
je 0x11a3a
leaq 0x38(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x13d78(%rip), %rsi     # 0x2577d
leaq 0x13d82(%rip), %rdx     # 0x2578e
leaq 0x28(%rsp), %rdi
callq 0x578e
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0xa7d2
leaq 0x13d65(%rip), %rsi     # 0x2578f
movq %rax, %rdi
callq 0x40f0
testl %eax, %eax
sete %r12b
jmp 0x11a3d
xorl %r12d, %r12d
cmpq %r13, %r15
je 0x11a5d
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11a5d
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11a79
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
testb %r12b, %r12b
je 0x11ac9
movabsq $0x100000004, %rax      # imm = 0x100000004
movq %rax, 0x120(%rbx)
addq $0x20, %rbx
leaq 0x13af5(%rip), %rsi     # 0x2558f
movq %rbx, %rdi
callq 0x40f0
testl %eax, %eax
je 0x11ac2
leaq 0x13cea(%rip), %rsi     # 0x25797
movq %rbx, %rdi
callq 0x40f0
movl $0x1, %ebp
testl %eax, %eax
jne 0x119ae
xorl %ebp, %ebp
jmp 0x119ae
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x13af4(%rip), %rsi     # 0x255d1
leaq 0x13afb(%rip), %rdx     # 0x255df
callq 0x578e
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x12566
movq %rax, %r15
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11b15
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
cmpq %r13, %r15
je 0x11bfa
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x13a9f(%rip), %rsi     # 0x255d1
leaq 0x13aa6(%rip), %rdx     # 0x255df
callq 0x578e
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0xa7d2
leaq 0x1369f(%rip), %rsi     # 0x251f1
movl $0xa, %ecx
movq %rax, %rdi
xorl %edx, %edx
callq 0x4720
movq %rax, %r15
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11b80
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
cmpq $-0x1, %r15
jne 0x119ae
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x13a33(%rip), %rsi     # 0x255d1
leaq 0x13a3a(%rip), %rdx     # 0x255df
callq 0x578e
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0xa7d2
movq %rax, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x244f4
cltq
movq %rax, 0x118(%rbx)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11beb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
movl $0x3, 0x120(%rbx)
jmp 0x11a8f
movl $0x1, %ebp
jmp 0x119ae
movq %rdx, %r14
movq %rax, %rbx
jmp 0x11c2e
movq %rdx, %r14
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11c2e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
cmpl $0x1, %r14d
jne 0x11cae
movq %rbx, %rdi
callq 0x4180
callq 0x4710
jmp 0x119ae
jmp 0x11c8a
jmp 0x11cab
jmp 0x11c8a
jmp 0x11cab
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x11c8d
movq 0x38(%rsp), %rsi
jmp 0x11c7e
jmp 0x11c8a
jmp 0x11c8a
jmp 0x11cab
jmp 0x11c8a
jmp 0x11cab
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x11c8d
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x11c8d
jmp 0x11c8a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11cae
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x11cae
movq %rax, %rbx
movq %rbx, %rdi
callq 0x4780