// File: 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
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movl $0x0, 0xf0(%rax)
addq $0xc0, %rax
movq %rax, -0x1a8(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x5960
movq -0x1a0(%rbp), %rdx
movb $0x0, -0x7a(%rbp)
movb $0x0, -0x7b(%rbp)
leaq 0x2095d(%rip), %rsi     # 0x43344
leaq -0x38(%rbp), %rdi
callq 0x6be0
jmp 0x229f2
movq -0x1a8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x23a80
movq %rax, -0x1b8(%rbp)
jmp 0x22a0b
movq -0x1b0(%rbp), %rdi
movq -0x1b8(%rbp), %rax
movq %rax, -0x18(%rbp)
addq $0xc0, %rdi
callq 0x13e10
movq %rax, -0x58(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x14920
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x1b9(%rbp)
jne 0x22ab9
movq -0x1b0(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x1d0(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x5960
movq -0x1c8(%rbp), %rdx
movb $0x1, -0x7a(%rbp)
leaq 0x208c5(%rip), %rsi     # 0x43344
leaq -0x78(%rbp), %rdi
callq 0x6be0
jmp 0x22a8a
movq -0x1d0(%rbp), %rdi
movb $0x1, -0x7b(%rbp)
leaq -0x78(%rbp), %rsi
callq 0x13940
movq %rax, -0x1d8(%rbp)
jmp 0x22aa7
movq -0x1d8(%rbp), %rdi
callq 0x5900
movb %al, -0x1b9(%rbp)
movb -0x1b9(%rbp), %al
movb %al, -0x1d9(%rbp)
testb $0x1, -0x7b(%rbp)
jne 0x22acd
jmp 0x22ad6
leaq -0x78(%rbp), %rdi
callq 0x5aa8
testb $0x1, -0x7a(%rbp)
jne 0x22ade
jmp 0x22ae7
leaq -0x79(%rbp), %rdi
callq 0x55e0
leaq -0x38(%rbp), %rdi
callq 0x5aa8
leaq -0x39(%rbp), %rdi
callq 0x55e0
movb -0x1d9(%rbp), %al
testb $0x1, %al
jne 0x22b05
jmp 0x22b84
movl $0x190, -0x4(%rbp)      # imm = 0x190
jmp 0x2329a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x22b76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x22b6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x22b5a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
testb $0x1, -0x7b(%rbp)
jne 0x22b4f
jmp 0x22b58
leaq -0x78(%rbp), %rdi
callq 0x5aa8
jmp 0x22b5a
testb $0x1, -0x7a(%rbp)
jne 0x22b62
jmp 0x22b6b
leaq -0x79(%rbp), %rdi
callq 0x55e0
jmp 0x22b6d
leaq -0x38(%rbp), %rdi
callq 0x5aa8
leaq -0x39(%rbp), %rdi
callq 0x55e0
jmp 0x232a6
movq -0x1b0(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x1f0(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x5960
movq -0x1e8(%rbp), %rdx
leaq 0x2078b(%rip), %rsi     # 0x43344
leaq -0xa0(%rbp), %rdi
callq 0x6be0
jmp 0x22bc7
movq -0x1f0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x13940
movq %rax, -0x1f8(%rbp)
jmp 0x22be3
movq -0x1f8(%rbp), %rdi
leaq 0x20b4e(%rip), %rsi     # 0x4373f
xorl %eax, %eax
movl %eax, %edx
callq 0x5a70
movq %rax, -0x200(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5aa8
leaq -0xa1(%rbp), %rdi
callq 0x55e0
movq -0x200(%rbp), %rax
cmpq $-0x1, %rax
je 0x22c69
movl $0x190, -0x4(%rbp)      # imm = 0x190
jmp 0x2329a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x22c58
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5aa8
leaq -0xa1(%rbp), %rdi
callq 0x55e0
jmp 0x232a6
movq -0x1b0(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x210(%rbp)
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x5960
movq -0x208(%rbp), %rdx
movb $0x0, -0x102(%rbp)
movb $0x0, -0x103(%rbp)
leaq 0x20a95(%rip), %rsi     # 0x43741
leaq -0xd0(%rbp), %rdi
callq 0x6be0
jmp 0x22cba
movq -0x210(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x23a80
movq %rax, -0x218(%rbp)
jmp 0x22cd6
movq -0x1b0(%rbp), %rdi
movq -0x218(%rbp), %rax
movq %rax, -0xb0(%rbp)
addq $0xc0, %rdi
callq 0x13e10
movq %rax, -0xe0(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x13de0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x219(%rbp)
jne 0x22d25
jmp 0x22dbb
movq -0x1b0(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x230(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x5960
movq -0x228(%rbp), %rdx
movb $0x1, -0x102(%rbp)
leaq 0x209e0(%rip), %rsi     # 0x43741
leaq -0x100(%rbp), %rdi
callq 0x6be0
jmp 0x22d6f
movq -0x230(%rbp), %rdi
movb $0x1, -0x103(%rbp)
leaq -0x100(%rbp), %rsi
callq 0x13940
movq %rax, -0x238(%rbp)
jmp 0x22d92
movq -0x238(%rbp), %rdi
leaq 0x209b3(%rip), %rsi     # 0x43753
callq 0x8ff0
movb %al, -0x239(%rbp)
jmp 0x22dad
movb -0x239(%rbp), %al
movb %al, -0x219(%rbp)
jmp 0x22dbb
movb -0x219(%rbp), %al
movb %al, -0x23a(%rbp)
testb $0x1, -0x103(%rbp)
jne 0x22dd2
jmp 0x22dde
leaq -0x100(%rbp), %rdi
callq 0x5aa8
testb $0x1, -0x102(%rbp)
jne 0x22de9
jmp 0x22df5
leaq -0x101(%rbp), %rdi
callq 0x55e0
leaq -0xd0(%rbp), %rdi
callq 0x5aa8
leaq -0xd1(%rbp), %rdi
callq 0x55e0
movb -0x23a(%rbp), %al
testb $0x1, %al
jne 0x22e1c
jmp 0x22ec1
movq -0x1b0(%rbp), %rax
movl $0x4, 0x120(%rax)
movl $0x1, 0x124(%rax)
jmp 0x23250
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x22eb0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x22ea4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x22e8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
testb $0x1, -0x103(%rbp)
jne 0x22e7d
jmp 0x22e89
leaq -0x100(%rbp), %rdi
callq 0x5aa8
jmp 0x22e8b
testb $0x1, -0x102(%rbp)
jne 0x22e96
jmp 0x22ea2
leaq -0x101(%rbp), %rdi
callq 0x55e0
jmp 0x22ea4
leaq -0xd0(%rbp), %rdi
callq 0x5aa8
leaq -0xd1(%rbp), %rdi
callq 0x55e0
jmp 0x232a6
movq -0x1b0(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x250(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x5960
movq -0x248(%rbp), %rdx
leaq 0x206ea(%rip), %rsi     # 0x435e0
leaq -0x130(%rbp), %rdi
callq 0x6be0
jmp 0x22f04
movq -0x250(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x23a80
movq %rax, -0x258(%rbp)
jmp 0x22f20
movq -0x1b0(%rbp), %rdi
movq -0x258(%rbp), %rax
movq %rax, -0x110(%rbp)
addq $0xc0, %rdi
callq 0x13e10
movq %rax, -0x140(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x13de0
movb %al, -0x259(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x5aa8
leaq -0x131(%rbp), %rdi
callq 0x55e0
movb -0x259(%rbp), %al
testb $0x1, %al
jne 0x22f88
jmp 0x23245
movq -0x1b0(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x270(%rbp)
leaq -0x161(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x5960
movq -0x268(%rbp), %rdx
leaq 0x20623(%rip), %rsi     # 0x435e0
leaq -0x160(%rbp), %rdi
callq 0x6be0
jmp 0x22fcb
movq -0x270(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x13940
movq %rax, -0x278(%rbp)
jmp 0x22fe7
movq -0x278(%rbp), %rdi
leaq 0x201e6(%rip), %rsi     # 0x431db
xorl %eax, %eax
movl %eax, %edx
callq 0x52f0
movq %rax, -0x280(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x5aa8
leaq -0x161(%rbp), %rdi
callq 0x55e0
movq -0x280(%rbp), %rax
cmpq $-0x1, %rax
je 0x230a4
movl $0x190, -0x4(%rbp)      # imm = 0x190
jmp 0x2329a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x2305c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x5aa8
leaq -0x131(%rbp), %rdi
callq 0x55e0
jmp 0x232a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x23093
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x5aa8
leaq -0x161(%rbp), %rdi
callq 0x55e0
jmp 0x232a6
movq -0x1b0(%rbp), %rax
addq $0xc0, %rax
movq %rax, -0x290(%rbp)
leaq -0x189(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x5960
movq -0x288(%rbp), %rdx
leaq 0x20507(%rip), %rsi     # 0x435e0
leaq -0x188(%rbp), %rdi
callq 0x6be0
jmp 0x230e7
movq -0x290(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x13940
movq %rax, -0x298(%rbp)
jmp 0x23103
movq -0x298(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x41890
movl %eax, -0x29c(%rbp)
jmp 0x23120
movq -0x1b0(%rbp), %rax
movl -0x29c(%rbp), %ecx
movslq %ecx, %rcx
movq %rcx, 0x118(%rax)
leaq -0x188(%rbp), %rdi
callq 0x5aa8
leaq -0x189(%rbp), %rdi
callq 0x55e0
movq -0x1b0(%rbp), %rax
cmpq $0x0, 0x118(%rax)
jae 0x23230
movl $0x10, %edi
callq 0x5250
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x2a8(%rbp)
leaq 0x205d9(%rip), %rsi     # 0x4375b
callq 0x5a10
jmp 0x23189
movq -0x2a8(%rbp), %rdi
movq 0x38e31(%rip), %rsi     # 0x5bfc8
movq 0x38e1a(%rip), %rdx     # 0x5bfb8
callq 0x5920
jmp 0x232af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x231ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x5aa8
leaq -0x189(%rbp), %rdi
callq 0x55e0
jmp 0x23202
movq -0x2a8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x53b0
jmp 0x23202
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x232a6
movq -0x48(%rbp), %rdi
callq 0x51e0
movq %rax, -0x198(%rbp)
movl $0x190, -0x4(%rbp)      # imm = 0x190
callq 0x58f0
jmp 0x2329a
jmp 0x23232
movq -0x1b0(%rbp), %rax
movl $0x3, 0x120(%rax)
jmp 0x2324e
movl $0x1, -0x4(%rbp)
jmp 0x2329a
jmp 0x23250
movq -0x1b0(%rbp), %rdi
addq $0x20, %rdi
leaq 0x2033c(%rip), %rsi     # 0x4359e
callq 0x9360
testb $0x1, %al
jne 0x2326d
jmp 0x23293
movq -0x1b0(%rbp), %rdi
addq $0x20, %rdi
leaq 0x204f4(%rip), %rsi     # 0x43773
callq 0x9360
testb $0x1, %al
jne 0x2328a
jmp 0x23293
movl $0x1, -0x4(%rbp)
jmp 0x2329a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x5950
nop