// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rsi, 0x10(%rsp)
cmpb $0x0, 0x193(%rsi)
je 0x28cdd
movq %rbx, 0x8(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %r14d, %r14d
leaq 0x80(%rsp), %rbp
xorl %ebx, %ebx
movq %r12, %rdi
leaq 0x6c50(%rip), %rsi      # 0x2f880
movq %rbx, %rdx
callq 0x7980
cmpq $-0x1, %rax
je 0x28cf0
movq %rax, %r13
movq %rax, %rcx
subq %rbx, %rcx
movq %rbp, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x7540
movq %rbp, %rdi
callq 0x16e9c
movl %eax, %ebx
movq %rbp, %rdi
callq 0x79b8
testl %ebx, %ebx
je 0x28d1d
movslq %ebx, %r15
addq $0x2, %r13
leaq (%r15,%r13), %rbx
movq %r12, %rdi
leaq 0x6bf8(%rip), %rsi      # 0x2f880
movq %rbx, %rdx
callq 0x7980
cmpq %rbx, %rax
jne 0x28dad
addq %r15, %r14
movq 0x10(%rsp), %rax
cmpq 0x180(%rax), %r14
ja 0x28dda
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x7540
leaq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x7950
movq %rbp, %rdi
callq 0x79b8
addq $0x2, %rbx
jmp 0x28c26
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7690
movq %rbx, %rax
jmp 0x28f92
movq 0x10(%rsp), %rax
movl $0x190, 0x188(%rax)     # imm = 0x190
leaq 0x4049(%rip), %rsi      # 0x2cd4f
leaq 0x80(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x8032
jmp 0x28f83
movq 0x10(%rsp), %rax
leaq 0x140(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq 0x140(%rax), %rbx
leaq 0x38(%rsp), %r13
leaq 0x80(%rsp), %rbp
leaq 0x60(%rsp), %r12
movq 0x10(%rsp), %rax
cmpq 0x148(%rax), %rbx
je 0x28e07
movq (%rbx), %rsi
movq (%rsi), %rax
movq %r13, %rdi
callq *0x10(%rax)
movq %rbp, %rdi
callq 0x93a4
movq %r12, %rdi
movq %rbp, %rsi
callq 0x93fc
movq %r13, %rdi
movq %r12, %rsi
callq 0xc2ad
movl %eax, %r15d
movq %r12, %rdi
callq 0x79b8
movq %rbp, %rdi
callq 0x93dc
movq %r13, %rdi
callq 0x79b8
testb %r15b, %r15b
jne 0x28e37
addq $0x8, %rbx
jmp 0x28d47
movq 0x10(%rsp), %rax
movl $0x190, 0x188(%rax)     # imm = 0x190
leaq 0x3f8c(%rip), %rsi      # 0x2cd4f
leaq 0x80(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x8032
jmp 0x28f83
movq 0x10(%rsp), %rax
movl $0x19d, 0x188(%rax)     # imm = 0x19D
leaq 0x3f5f(%rip), %rsi      # 0x2cd4f
leaq 0x80(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x8032
jmp 0x28f83
movq 0x8(%rsp), %rdx
leaq 0x10(%rdx), %rax
movq %rax, (%rdx)
movq 0x18(%rsp), %rcx
leaq 0x28(%rsp), %rsi
cmpq %rsi, %rcx
je 0x28f2c
movq %rcx, (%rdx)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rdx)
jmp 0x28f32
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x28e45
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x58(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x295fa
leaq 0x80(%rsp), %rdi
callq 0x844c
leaq 0x38(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x84a4
movl $0x88, %edi
addq 0x1a138(%rip), %rdi     # 0x42fb8
leaq 0x38(%rsp), %rsi
callq 0x29634
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x79b8
leaq 0x80(%rsp), %rdi
callq 0x8484
movq %rbx, 0x60(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x73a0
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0x7370
leaq 0x80(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x7620
leaq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x895a
leaq 0x60(%rsp), %rsi
movq %r15, %rdi
callq 0x296d2
movq 0x8(%rsp), %rdx
leaq 0x10(%rdx), %rax
movq %rax, (%rdx)
movq 0x18(%rsp), %rcx
leaq 0x28(%rsp), %rsi
cmpq %rsi, %rcx
je 0x28f4d
movq %rcx, (%rdx)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rdx)
jmp 0x28f53
movups (%rsi), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rdx)
movq %rsi, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
jmp 0x28f83
movups (%rsi), %xmm0
movups %xmm0, (%rax)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rdx)
movq %rsi, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x79b8
leaq 0x80(%rsp), %rdi
callq 0x73f0
leaq 0x18(%rsp), %rdi
callq 0x79b8
movq 0x8(%rsp), %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x29021
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x79b8
jmp 0x28fb8
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x8484
jmp 0x29024
jmp 0x29021
jmp 0x29021
jmp 0x29021
jmp 0x29021
jmp 0x29021
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x79b8
leaq 0x80(%rsp), %rdi
callq 0x73f0
jmp 0x29024
jmp 0x29021
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x93dc
jmp 0x29004
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x2901a
jmp 0x2900f
jmp 0x29021
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x79b8
jmp 0x29024
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x79b8
movq %rbx, %rdi
callq 0x7860