// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
andl $0x0, 0xf0(%rdi)
leaq 0xd6a5(%rip), %rsi      # 0x1c332
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5328
leaq 0xc0(%rbx), %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0xf6d4
leaq 0xc8(%rbx), %r12
cmpq %r12, %rax
je 0xede2
leaq 0xd66b(%rip), %rsi      # 0x1c332
leaq 0x30(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x5328
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
callq 0x91fa
movq 0x8(%rax), %r15
leaq 0x30(%rsp), %rdi
callq 0x4898
leaq 0x10(%rsp), %rdi
callq 0x4898
testq %r15, %r15
je 0xedec
leaq 0xd627(%rip), %rsi      # 0x1c332
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x91fa
leaq 0xd9ec(%rip), %rsi      # 0x1c71a
movq %rax, %rdi
xorl %edx, %edx
callq 0x4870
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0x4898
cmpq $-0x1, %r15
jne 0xedec
leaq 0xd9c6(%rip), %rsi      # 0x1c71c
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0xf6d4
pushq $0x1
popq %rbp
cmpq %r12, %rax
je 0xee00
leaq 0xd997(%rip), %rsi      # 0x1c71c
leaq 0x30(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x5328
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
callq 0x91fa
leaq 0xd986(%rip), %rsi      # 0x1c72e
movq %rax, %rdi
callq 0x610b
movl %eax, %r15d
leaq 0x30(%rsp), %rdi
callq 0x4898
leaq 0x10(%rsp), %rdi
callq 0x4898
testb %r15b, %r15b
je 0xee0a
movabsq $0x100000004, %rax      # imm = 0x100000004
movq %rax, 0x120(%rbx)
jmp 0xeed7
leaq 0x10(%rsp), %rdi
callq 0x4898
movl $0x190, %ebp            # imm = 0x190
movl %ebp, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rdi
callq 0x4898
leaq 0xd7aa(%rip), %rsi      # 0x1c5bb
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0xf6d4
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0x4898
cmpq %r12, %r15
je 0xedf1
leaq 0xd775(%rip), %rsi      # 0x1c5bb
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x91fa
leaq 0xd372(%rip), %rsi      # 0x1c1db
movq %rax, %rdi
xorl %edx, %edx
callq 0x4270
movq %rax, %r15
leaq 0x10(%rsp), %rdi
callq 0x4898
cmpq $-0x1, %r15
jne 0xedec
leaq 0xd72a(%rip), %rsi      # 0x1c5bb
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x5328
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x91fa
pushq $0xa
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1b536
cltq
movq %rax, 0x118(%rbx)
leaq 0x10(%rsp), %rdi
callq 0x4898
movl $0x3, 0x120(%rbx)
addq $0x20, %rbx
leaq 0xd697(%rip), %rsi      # 0x1c579
movq %rbx, %rdi
callq 0x61cb
testb %al, %al
je 0xef05
leaq 0xd841(%rip), %rsi      # 0x1c736
movq %rbx, %rdi
callq 0x61cb
testb %al, %al
jne 0xedf1
xorl %ebp, %ebp
jmp 0xedf1
movq %rdx, %r14
movq %rax, %rbx
jmp 0xef24
movq %rdx, %r14
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4898
cmpl $0x1, %r14d
jne 0xef73
movq %rbx, %rdi
callq 0x4180
callq 0x4710
jmp 0xedec
jmp 0xef61
jmp 0xef70
jmp 0xef50
jmp 0xef61
jmp 0xef61
jmp 0xef70
jmp 0xef61
jmp 0xef70
jmp 0xef61
jmp 0xef70
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x4898
jmp 0xef64
jmp 0xef61
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4898
jmp 0xef73
movq %rax, %rbx
movq %rbx, %rdi
callq 0x4750
nop