// File: /workspace/github_cpp_makefile_star2_O3/mbourand[P]webserv/srcs/Response.cpp
// Function: Response::compressBody(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void	Response::compressBody(const std::string &str)
{
	for (std::map<std::string, std::string>::iterator it = _headers.begin(); it != _headers.end(); it++) {
		if (it->first == "Content-Type") {
			if (it->second == "image/jpg" || it->second == "video/mp4" || it->second == "audio/mpeg") //skip format that are already compressed
				return;
			else
				break;
		}
	}
	try
	{
		_body = str;
		if (_candeflate && g_webserv.compression_deflate)
		{
			_body = compress_deflate(_body, g_webserv.compression_level);
			this->addHeader("Content-Encoding", "deflate");
		}
		if (_cangzip && g_webserv.compression_gzip)
		{
			_body = compress_gzip(_body, g_webserv.compression_level);
			this->removeHeader("Content-Encoding");
			if (_candeflate  && g_webserv.compression_deflate)
				this->addHeader("Content-Encoding", "deflate, gzip");
			else
				this->addHeader("Content-Encoding", "gzip");
		}
	}
	catch(const std::runtime_error& e)
	{
		Logger::print(e.what(), NULL, WARNING, NORMAL);
		removeHeader("Content-Encoding");
		removeHeader("Transfer-Encoding");
		_body = str;
		this->addHeader("Content-Length", ft::toString(str.size()));
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x48(%rdi), %r15
leaq 0x38(%rdi), %r13
cmpq %r13, %r15
je 0x37601
leaq 0x2bbc(%rip), %r12      # 0x3a152
leaq 0x20(%r15), %rdi
movq %r12, %rsi
callq 0x7180
testl %eax, %eax
je 0x375b8
movq %r15, %rdi
callq 0x7350
movq %rax, %r15
cmpq %r13, %rax
jne 0x37596
jmp 0x37601
addq $0x40, %r15
leaq 0x6330(%rip), %rsi      # 0x3d8f3
movq %r15, %rdi
callq 0x7180
testl %eax, %eax
je 0x37888
leaq 0x6323(%rip), %rsi      # 0x3d8fd
movq %r15, %rdi
callq 0x7180
testl %eax, %eax
je 0x37888
leaq 0x6316(%rip), %rsi      # 0x3d907
movq %r15, %rdi
callq 0x7180
testl %eax, %eax
je 0x37888
leaq 0x30(%r14), %r15
leaq 0x60(%r14), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x72c0
cmpb $0x1, 0xc(%r14)
jne 0x376f5
leaq 0x16f42(%rip), %rax     # 0x4e568
cmpb $0x1, 0xc8(%rax)
jne 0x376f5
movl 0xcc(%rax), %edx
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x16f42
leaq 0x18(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x7590
movq (%r13), %rdi
leaq 0x28(%rsp), %r13
cmpq %r13, %rdi
je 0x37671
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x6292(%rip), %rsi      # 0x3d912
leaq 0x629b(%rip), %rdx      # 0x3d922
callq 0x80f4
leaq 0x48(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x422e(%rip), %rsi      # 0x3b8ca
leaq 0x422e(%rip), %rdx      # 0x3b8d1
leaq 0x38(%rsp), %rdi
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x388ac
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x72c0
movq 0x38(%rsp), %rdi
cmpq %rbp, %rdi
je 0x376de
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x376f5
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
cmpb $0x1, 0xd(%r14)
jne 0x37888
leaq 0x16e61(%rip), %rbp     # 0x4e568
cmpb $0x1, 0xc9(%rbp)
jne 0x37888
movl 0xcc(%rbp), %edx
leaq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x16dcc
leaq 0x18(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x7590
movq (%r13), %rdi
leaq 0x28(%rsp), %r13
cmpq %r13, %rdi
je 0x37752
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x61b1(%rip), %rsi      # 0x3d912
leaq 0x61ba(%rip), %rdx      # 0x3d922
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x38bb2
movq %r15, %rdi
movq %rax, %rsi
callq 0x38c66
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x3779c
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
cmpb $0x1, 0xc(%r14)
jne 0x37804
cmpb $0x1, 0xc8(%rbp)
jne 0x37804
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x6157(%rip), %rsi      # 0x3d912
leaq 0x6160(%rip), %rdx      # 0x3d922
callq 0x80f4
leaq 0x48(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x614c(%rip), %rsi      # 0x3d923
leaq 0x6152(%rip), %rdx      # 0x3d930
leaq 0x38(%rsp), %rdi
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x388ac
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x72c0
jmp 0x3785a
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x60ff(%rip), %rsi      # 0x3d912
leaq 0x6108(%rip), %rdx      # 0x3d922
callq 0x80f4
leaq 0x48(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x60fd(%rip), %rsi      # 0x3d92c
leaq 0x60fa(%rip), %rdx      # 0x3d930
leaq 0x38(%rsp), %rdi
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x388ac
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x72c0
movq 0x38(%rsp), %rdi
cmpq %rbp, %rdi
je 0x37871
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37888
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x378ad
jmp 0x378f3
jmp 0x378b9
jmp 0x378ad
jmp 0x378f3
jmp 0x378f3
jmp 0x378ad
jmp 0x378f3
jmp 0x378f3
jmp 0x378f3
jmp 0x378b9
movq %rdx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
jmp 0x378da
movq %rdx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
cmpq %rbp, %rdi
je 0x378da
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x378fd
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
jmp 0x378fd
movq %rdx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
cmpl $0x1, 0x10(%rsp)
jne 0x37adb
movq 0x8(%rsp), %rdi
callq 0x7210
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %rax, %rsi
callq 0xde66
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
movl $0x2, %edx
movl $0x1, %ecx
callq 0xdea4
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3795e
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x28(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x5fa4(%rip), %rsi      # 0x3d912
leaq 0x5fad(%rip), %rdx      # 0x3d922
leaq 0x18(%rsp), %rdi
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x3703a
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x379a3
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x28fb(%rip), %rsi      # 0x3a2ad
leaq 0x2905(%rip), %rdx      # 0x3a2be
callq 0x80f4
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x3703a
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x379e2
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x72c0
leaq 0x18(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x2708(%rip), %rsi      # 0x3a104
leaq 0x270f(%rip), %rdx      # 0x3a112
callq 0x80f4
movl 0x8(%rbx), %esi
leaq 0x38(%rsp), %rdi
callq 0x1bd7d
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
callq 0x388ac
leaq 0x38(%rsp), %rsi
movq %rax, %rdi
callq 0x72c0
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37a4a
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37a61
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
callq 0x7780
jmp 0x37888
jmp 0x37a75
jmp 0x37a98
jmp 0x37a98
jmp 0x37a75
jmp 0x37a98
movq %rax, 0x8(%rsp)
jmp 0x37abf
jmp 0x37a98
movq %rax, 0x8(%rsp)
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37ad6
movq 0x68(%rsp), %rsi
jmp 0x37ace
movq %rax, 0x8(%rsp)
jmp 0x37ad6
movq %rax, 0x8(%rsp)
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37abf
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x74b0
movq 0x18(%rsp), %rdi
cmpq %r13, %rdi
je 0x37ad6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x74b0
callq 0x7780
movq 0x8(%rsp), %rdi
callq 0x7810
movq %rax, %rdi
callq 0x96aa
nop