// File: /workspace/github_cpp_makefile_star2_O3/mbourand[P]webserv/srcs/Request.cpp
// Function: Request::dechunk(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
std::string		Request::dechunk(const std::string& str)
{
	if (!_chunked)
		return (str);
	size_t		start = 0;
	size_t		end = 0;
	size_t		len;
	size_t		total_len = 0;
	std::string	output;

	while ((end = str.find("\r\n", start)) != std::string::npos)
	{
		len = ft::hexToInt(str.substr(start, (end - start)));
		end += 2;
		if (!len)
		{
			for (Request::HeadersVector::iterator it = _headers.begin(); it != _headers.end(); it++)
				if ((*it)->getType() == TransferEncodingHeader().getType())
				{
					delete (*it);
					_headers.erase(it);
					Header* header = g_webserv.headers.createByType_ignore_case(ContentLengthHeader().getType());
					std::stringstream	ss;
					std::string			converted;
					ss << total_len;
					ss >> converted;
					header->setValue(converted);
					_headers.push_back(header);
					return (output);
				}
			return (output);
		}
		else if (str.find("\r\n", (end + len)) != (end + len))
		{
			_error_code = 400;
			return ("");
		}
		total_len += len;
		if (total_len > _max_body_size)
		{
			_error_code = 413;
			return ("");
		}
		output += str.substr(end, len);
		start = end + len + 2;
	}
	_error_code = 400;
	return ("");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdx, %r12
movq %rdi, %rbx
cmpb $0x0, 0x193(%rsi)
je 0x353e4
movq %rsi, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8667(%rip), %rsi      # 0x3d8f0
movl $0x2, %ecx
movq %r12, %rdi
xorl %edx, %edx
callq 0x77f0
cmpq $-0x1, %rax
je 0x353b5
movq %rax, %r14
xorl %ebx, %ebx
leaq 0x80(%rsp), %r13
xorl %r15d, %r15d
movq %r14, %rcx
subq %rbx, %rcx
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x74d0
movq %r13, %rdi
callq 0x1be90
movl %eax, %ebx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x352f5
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x74b0
testl %ebx, %ebx
je 0x35407
movslq %ebx, %rbp
addq $0x2, %r14
leaq (%r14,%rbp), %rbx
movl $0x2, %ecx
movq %r12, %rdi
leaq 0x85d9(%rip), %rsi      # 0x3d8f0
movq %rbx, %rdx
callq 0x77f0
cmpq %rbx, %rax
jne 0x35523
addq %rbp, %r15
movq 0x30(%rsp), %rax
cmpq 0x180(%rax), %r15
ja 0x35552
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbp, %rcx
callq 0x74d0
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
leaq 0x38(%rsp), %rdi
callq 0x7190
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x3538d
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x74b0
addq $0x2, %rbx
movl $0x2, %ecx
movq %r12, %rdi
leaq 0x8550(%rip), %rsi      # 0x3d8f0
movq %rbx, %rdx
callq 0x77f0
movq %rax, %r14
cmpq $-0x1, %rax
jne 0x352b2
movq 0x30(%rsp), %rax
movl $0x190, 0x188(%rax)     # imm = 0x190
movq 0x28(%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
leaq 0x59c4(%rip), %rdx      # 0x3ad9b
movq %rdx, %rsi
callq 0x80f4
jmp 0x35751
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x8a92
movq %rbx, %rax
jmp 0x35772
movq 0x30(%rsp), %rax
movq 0x140(%rax), %rbx
cmpq 0x148(%rax), %rbx
je 0x354f3
addq $0x140, %rax            # imm = 0x140
movq %rax, 0x58(%rsp)
leaq 0x8(%rbx), %r13
leaq 0x80(%rsp), %rbp
movq (%rbx), %rsi
movq (%rsi), %rax
leaq 0x8(%rsp), %rdi
callq *0x10(%rax)
movq %rbp, %rdi
callq 0x9b80
leaq 0x60(%rsp), %rdi
movq %rbp, %rsi
callq 0x9c26
movq 0x10(%rsp), %rdx
cmpq 0x68(%rsp), %rdx
jne 0x35485
movq 0x60(%rsp), %r14
testq %rdx, %rdx
je 0x3548f
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x74c0
testl %eax, %eax
sete %r12b
jmp 0x35492
movq 0x60(%rsp), %r14
xorl %r12d, %r12d
jmp 0x35492
movb $0x1, %r12b
leaq 0x70(%rsp), %rax
cmpq %rax, %r14
je 0x354ac
movq 0x70(%rsp), %rsi
incq %rsi
movq %r14, %rdi
callq 0x74b0
movq %rbp, %rdi
callq 0x9bc0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x354d0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
testb %r12b, %r12b
movq 0x30(%rsp), %r14
jne 0x35581
addq $0x8, %rbx
addq $0x8, %r13
cmpq 0x148(%r14), %rbx
jne 0x35437
movq 0x28(%rsp), %rsi
leaq 0x10(%rsi), %rax
movq %rax, (%rsi)
movq 0x38(%rsp), %rcx
leaq 0x48(%rsp), %rdx
cmpq %rdx, %rcx
je 0x35693
movq %rcx, (%rsi)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsi)
jmp 0x35699
movq 0x30(%rsp), %rax
movl $0x190, 0x188(%rax)     # imm = 0x190
movq 0x28(%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
leaq 0x5856(%rip), %rdx      # 0x3ad9b
movq %rdx, %rsi
callq 0x80f4
jmp 0x35751
movq 0x30(%rsp), %rax
movl $0x19d, 0x188(%rax)     # imm = 0x19D
movq 0x28(%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
leaq 0x5827(%rip), %rdx      # 0x3ad9b
movq %rdx, %rsi
callq 0x80f4
jmp 0x35751
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x3558f
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x148(%r14), %rdx
cmpq %rdx, %r13
je 0x355b1
leaq -0x8(%r13), %rdi
subq %r13, %rdx
movq %r13, %rsi
callq 0x7760
movq 0x148(%r14), %rdx
addq $-0x8, %rdx
movq %rdx, 0x148(%r14)
leaq 0x80(%rsp), %rdi
callq 0x85e4
leaq 0x8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x868a
movl $0x88, %edi
addq 0x189d1(%rip), %rdi     # 0x4dfb8
leaq 0x8(%rsp), %rsi
callq 0x36088
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x35610
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x80(%rsp), %rdi
callq 0x8624
movq %rbx, 0x60(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x7360
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0x7330
leaq 0x80(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x75a0
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x8e46
movq 0x148(%r14), %rsi
cmpq 0x150(%r14), %rsi
je 0x356ba
movq %rbx, (%rsi)
addq $0x8, 0x148(%r14)
jmp 0x356c9
movups (%rdx), %xmm0
movups %xmm0, (%rax)
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsi)
movq %rdx, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movb $0x0, 0x48(%rsp)
jmp 0x35751
leaq 0x60(%rsp), %rdx
movq 0x58(%rsp), %rdi
callq 0x365fa
movq 0x28(%rsp), %rsi
leaq 0x10(%rsi), %rax
movq %rax, (%rsi)
movq 0x38(%rsp), %rcx
leaq 0x48(%rsp), %rdx
cmpq %rdx, %rcx
je 0x356f2
movq %rcx, (%rsi)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsi)
jmp 0x356f8
movups (%rdx), %xmm0
movups %xmm0, (%rax)
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsi)
movq %rdx, 0x38(%rsp)
movq $0x0, 0x40(%rsp)
movb $0x0, 0x48(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x35730
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18839(%rip), %rsi     # 0x4df70
leaq 0x80(%rsp), %rdi
callq 0x73b0
leaq 0x100(%rsp), %rdi
callq 0x71c0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x3576d
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x28(%rsp), %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3586d
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x357ad
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x357ad
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x8624
jmp 0x35870
jmp 0x3586d
jmp 0x3586d
jmp 0x3586d
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x357ed
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x1877c(%rip), %rsi     # 0x4df70
leaq 0x80(%rsp), %rdi
callq 0x73b0
leaq 0x100(%rsp), %rdi
callq 0x71c0
jmp 0x35870
jmp 0x3586d
movq %rax, %rbx
jmp 0x35827
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x9bc0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x35870
movq 0x18(%rsp), %rsi
jmp 0x35863
jmp 0x3586d
jmp 0x3586d
jmp 0x35843
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x35870
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x35870
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x3588c
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %rbx, %rdi
callq 0x7810