// File: /workspace/github_cpp_makefile_star2_O1/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 0x357e0
movq %rsi, 0x8(%rsp)
movq %rbx, 0x30(%rsp)
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x826b(%rip), %rsi      # 0x3d8f0
movl $0x2, %ecx
movq %r12, %rdi
xorl %edx, %edx
callq 0x77f0
cmpq $-0x1, %rax
je 0x357b1
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 0x1c192
movl %eax, %ebx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x356f1
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x74b0
testl %ebx, %ebx
je 0x35803
movslq %ebx, %rbp
addq $0x2, %r14
leaq (%r14,%rbp), %rbx
movl $0x2, %ecx
movq %r12, %rdi
leaq 0x81dd(%rip), %rsi      # 0x3d8f0
movq %rbx, %rdx
callq 0x77f0
cmpq %rbx, %rax
jne 0x3591d
addq %rbp, %r15
movq 0x8(%rsp), %rax
cmpq 0x180(%rax), %r15
ja 0x3594c
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 0x35789
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x74b0
addq $0x2, %rbx
movl $0x2, %ecx
movq %r12, %rdi
leaq 0x8154(%rip), %rsi      # 0x3d8f0
movq %rbx, %rdx
callq 0x77f0
movq %rax, %r14
cmpq $-0x1, %rax
jne 0x356ae
movq 0x8(%rsp), %rax
movl $0x190, 0x188(%rax)     # imm = 0x190
movq 0x30(%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
leaq 0x55c8(%rip), %rdx      # 0x3ad9b
movq %rdx, %rsi
callq 0x80f4
jmp 0x35b52
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x8a8a
movq %rbx, %rax
jmp 0x35b73
movq 0x8(%rsp), %rax
movq 0x140(%rax), %r14
cmpq 0x148(%rax), %r14
je 0x358ed
movq 0x8(%rsp), %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, 0x78(%rsp)
leaq 0x8(%r14), %r13
leaq 0x80(%rsp), %rbp
leaq 0x58(%rsp), %r12
movq (%r14), %rsi
movq (%rsi), %rax
leaq 0x10(%rsp), %rdi
callq *0x10(%rax)
movq %rbp, %rdi
callq 0x9ba0
movq %r12, %rdi
movq %rbp, %rsi
callq 0x9c46
movq 0x18(%rsp), %rdx
cmpq 0x60(%rsp), %rdx
jne 0x35885
testq %rdx, %rdx
je 0x35889
movq 0x58(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x74c0
testl %eax, %eax
sete %bl
jmp 0x3588b
xorl %ebx, %ebx
jmp 0x3588b
movb $0x1, %bl
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x358a7
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %rbp, %rdi
callq 0x9be0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x358cb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
testb %bl, %bl
jne 0x3597b
addq $0x8, %r14
addq $0x8, %r13
movq 0x8(%rsp), %rax
cmpq 0x148(%rax), %r14
jne 0x3583d
movq 0x30(%rsp), %rsi
leaq 0x10(%rsi), %rax
movq %rax, (%rsi)
movq 0x38(%rsp), %rcx
leaq 0x48(%rsp), %rdx
cmpq %rdx, %rcx
je 0x35a94
movq %rcx, (%rsi)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsi)
jmp 0x35a9a
movq 0x8(%rsp), %rax
movl $0x190, 0x188(%rax)     # imm = 0x190
movq 0x30(%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
leaq 0x545c(%rip), %rdx      # 0x3ad9b
movq %rdx, %rsi
callq 0x80f4
jmp 0x35b52
movq 0x8(%rsp), %rax
movl $0x19d, 0x188(%rax)     # imm = 0x19D
movq 0x30(%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
leaq 0x542d(%rip), %rdx      # 0x3ad9b
movq %rdx, %rsi
callq 0x80f4
jmp 0x35b52
movq (%r14), %rdi
testq %rdi, %rdi
je 0x35989
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x8(%rsp), %rax
movq 0x148(%rax), %rdx
cmpq %rdx, %r13
je 0x359a9
leaq -0x8(%r13), %rdi
subq %r13, %rdx
movq %r13, %rsi
callq 0x7760
movq 0x8(%rsp), %r14
addq $-0x8, 0x148(%r14)
leaq 0x80(%rsp), %rdi
callq 0x85dc
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x8682
movl $0x88, %edi
addq 0x185d7(%rip), %rdi     # 0x4dfb8
leaq 0x10(%rsp), %rsi
callq 0x364a4
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35a0a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x80(%rsp), %rdi
callq 0x861c
movq %rbx, 0x58(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x7360
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
callq 0x7330
leaq 0x80(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x75a0
movq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x8e3a
movq 0x148(%r14), %rsi
cmpq 0x150(%r14), %rsi
je 0x35abb
movq 0x58(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x148(%r14)
jmp 0x35aca
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 0x35b52
leaq 0x58(%rsp), %rdx
movq 0x78(%rsp), %rdi
callq 0x36a2c
movq 0x30(%rsp), %rsi
leaq 0x10(%rsi), %rax
movq %rax, (%rsi)
movq 0x38(%rsp), %rcx
leaq 0x48(%rsp), %rdx
cmpq %rdx, %rcx
je 0x35af3
movq %rcx, (%rsi)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsi)
jmp 0x35af9
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 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35b31
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18438(%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 0x35b6e
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x30(%rsp), %rax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x35c6e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35bae
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x35bae
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x861c
jmp 0x35c71
jmp 0x35c6e
jmp 0x35c6e
jmp 0x35c6e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35bee
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x1837b(%rip), %rsi     # 0x4df70
leaq 0x80(%rsp), %rdi
callq 0x73b0
leaq 0x100(%rsp), %rdi
callq 0x71c0
jmp 0x35c71
jmp 0x35c6e
movq %rax, %rbx
jmp 0x35c28
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x9be0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x35c71
movq 0x20(%rsp), %rsi
jmp 0x35c64
jmp 0x35c6e
jmp 0x35c6e
jmp 0x35c44
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x35c71
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x35c71
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x35c8d
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %rbx, %rdi
callq 0x7810
nop