// File: /workspace/github_cpp_makefile_star2_O2/dentiny[P]HTTP-Cache-Proxy/Proxy.cpp
// Function: Proxy::resendCheckStatus(int, int, int, std::vector<char, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void resendCheckStatus(int client_id, int client_fd, int server_fd, const std::vector<char> & content_to_send, const std::string & url)
	{
		// re-send the inserted message to the server
		int sent_length = 0;
		int N = content_to_send.size();
		while(sent_length < N)
		{
			int len = send(server_fd, &content_to_send.data()[0] + sent_length, N - sent_length, 0);
			if(len == -1)
			{
				throw ProxyException("Send with If-None-Match/If-Modified-Since error");
			}
			sent_length += len;
		}

		// receive header from server and decide by the status code
		std::vector<char> buffer(BUFFER_SIZE, '\0'); // buffer to store header temporarily
		int len = recv(server_fd, &buffer.data()[0], BUFFER_SIZE, 0);
		if(len == -1)
		{
			throw ProxyException("Receive with If-None-Match/If-Modified-Since error");
		}
		buffer[len] = '\0';

		// check header status
		const std::string header(buffer.begin(), buffer.begin() + len);
		bool status_304 = checkStatusCode(header);

		// if get true(status code 304), directly return cached content
		if(status_304)
		{
			// write first line of response to log
			std::string first_line = parser.extractFirstLine(header);
			std::string log_content = std::to_string(client_id) + ": Received " + first_line + " from " + url;
			logger.log(log_content);
			log_content = std::to_string(client_id) + ": Responding " + first_line;
			logger.log(log_content);

			// respond to the client with client
			respondCached(client_fd, url);
			return;
		}

		// if get false(status code 200), receive all the sent, and send to the client
		std::vector<std::vector<char>> segment;
		segment.push_back(std::vector<char>(buffer.begin(), buffer.begin() + len));

		// respond header to client, send every character in the buffer to client
		// true for send success, false for send error
		bool respondClient_suc = respondClient(client_fd, buffer, len);
		if(!respondClient_suc) 
		{
			throw ProxyException("Respond header to client error");
		}

		// receive content from server and send it to client segment by segment
		try
		{
			std::string httpAction = "GET"; // for resend, the http action has to be "GET"
			getResponse(client_id, client_fd, server_fd, url, header, segment, len, httpAction);	
		}
		catch(std::exception & e)
		{
			throw e;
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %r9, 0x30(%rsp)
movq %r8, %rbx
movl %ecx, %r12d
movl %edx, 0xc(%rsp)
movl %esi, %r15d
movq %rdi, %r14
movl 0x8(%r8), %ebp
subl (%r8), %ebp
xorl %r13d, %r13d
movl %ebp, %eax
subl %r13d, %eax
jle 0x6194
movslq %r13d, %rsi
addq (%rbx), %rsi
movslq %eax, %rdx
movl %r12d, %edi
xorl %ecx, %ecx
callq 0x31a0
addl %eax, %r13d
cmpl $-0x1, %eax
jne 0x611e
pushq $0x28
popq %rdi
callq 0x3190
movq %rax, %r14
leaq 0x4280(%rip), %rsi      # 0xa3d2
leaq 0x158(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x386c
movb $0x1, %bpl
leaq 0x158(%rsp), %rsi
movq %r14, %rdi
callq 0x55e8
xorl %ebp, %ebp
leaq 0x9b88(%rip), %rsi      # 0xfd08
leaq -0xb69(%rip), %rdx      # 0x561e
movq %r14, %rdi
callq 0x3490
jmp 0x65e1
leaq 0x78(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rcx
movl $0x10000, %esi          # imm = 0x10000
callq 0x563e
movq 0x38(%rsp), %rsi
movl $0x10000, %edx          # imm = 0x10000
movl %r12d, %edi
xorl %ecx, %ecx
callq 0x30e0
movq %rax, %r13
cmpl $-0x1, %r13d
je 0x647b
movslq %r13d, %rbx
movq 0x38(%rsp), %rax
movb $0x0, (%rax,%rbx)
movq 0x38(%rsp), %rsi
leaq (%rsi,%rbx), %rdx
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x78(%rsp), %rdi
callq 0x805e
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x75f2
testb %al, %al
je 0x6397
leaq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rdx
movq %r14, %rsi
callq 0x7636
leaq 0xf8(%rsp), %rdi
movl %r15d, %esi
callq 0x4a4e
movq 0x30(%rsp), %r13
leaq 0x41f6(%rip), %rdx      # 0xa435
leaq 0x98(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x4a2f
leaq 0xb8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x4a10
leaq 0x3e95(%rip), %rdx      # 0xa10a
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x4a2f
leaq 0x50(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
movq %r13, %rdx
callq 0x4a10
leaq 0xd8(%rsp), %rdi
callq 0x3150
leaq 0xb8(%rsp), %rdi
callq 0x3150
leaq 0x98(%rsp), %rdi
callq 0x3150
leaq 0xf8(%rsp), %rdi
callq 0x3150
leaq 0x8(%r14), %r12
leaq 0x50(%rsp), %rsi
movq %r12, %rdi
callq 0x4aa8
leaq 0x98(%rsp), %rdi
movl %r15d, %esi
callq 0x4a4e
leaq 0x4146(%rip), %rdx      # 0xa441
leaq 0xb8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x4a2f
leaq 0xd8(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x4a10
leaq 0x50(%rsp), %rbx
leaq 0xd8(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3370
movq %r15, %rdi
callq 0x3150
leaq 0xb8(%rsp), %rdi
callq 0x3150
leaq 0x98(%rsp), %rdi
callq 0x3150
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4aa8
movq %r14, %rdi
movl 0xc(%rsp), %esi
movq %r13, %rdx
callq 0x5eca
leaq 0x50(%rsp), %rdi
callq 0x3150
leaq 0x10(%rsp), %rdi
callq 0x3150
jmp 0x6455
andq $0x0, 0x60(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x38(%rsp), %rsi
addq %rsi, %rbx
leaq 0x10(%rsp), %rdi
leaq 0xd8(%rsp), %rcx
movq %rbx, %rdx
callq 0x598e
leaq 0x50(%rsp), %rbx
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x80cc
leaq 0x10(%rsp), %rdi
callq 0x3dda
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
movl 0xc(%rsp), %esi
movl %r13d, %ecx
callq 0x7668
testb %al, %al
je 0x64cf
leaq 0x3d3a(%rip), %rsi      # 0xa13b
leaq 0x10(%rsp), %rbp
leaq 0xd8(%rsp), %rdx
movq %rbp, %rdi
callq 0x386c
subq $0x8, %rsp
leaq 0x80(%rsp), %r9
movq %r14, %rdi
movl %r15d, %esi
movl 0x14(%rsp), %edx
movl %r12d, %ecx
movq 0x38(%rsp), %r8
pushq %rbp
pushq %r13
pushq %rbx
callq 0x76ae
addq $0x20, %rsp
leaq 0x10(%rsp), %rdi
callq 0x3150
leaq 0x50(%rsp), %rdi
callq 0x3c98
leaq 0x78(%rsp), %rdi
callq 0x3150
leaq 0x38(%rsp), %rdi
callq 0x3dda
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x3190
movq %rax, %r14
leaq 0x3f75(%rip), %rsi      # 0xa402
leaq 0x138(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x386c
movb $0x1, %bpl
leaq 0x138(%rsp), %rsi
movq %r14, %rdi
callq 0x55e8
xorl %ebp, %ebp
leaq 0x984d(%rip), %rsi      # 0xfd08
leaq -0xea4(%rip), %rdx      # 0x561e
movq %r14, %rdi
callq 0x3490
jmp 0x65e1
pushq $0x28
popq %rdi
callq 0x3190
movq %rax, %r14
leaq 0x3f6e(%rip), %rsi      # 0xa44f
leaq 0x118(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x386c
movb $0x1, %bpl
leaq 0x118(%rsp), %rsi
movq %r14, %rdi
callq 0x55e8
xorl %ebp, %ebp
leaq 0x97f9(%rip), %rsi      # 0xfd08
leaq -0xef8(%rip), %rdx      # 0x561e
movq %r14, %rdi
callq 0x3490
jmp 0x65e1
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x3150
testb %bpl, %bpl
jne 0x6540
jmp 0x663d
movq %rax, %rbx
movq %r14, %rdi
callq 0x3240
jmp 0x663d
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x3150
jmp 0x6562
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x3150
jmp 0x6681
jmp 0x667e
movq %rdx, %r14
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3150
jmp 0x65a3
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x3150
jmp 0x65f6
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x663d
movq %rbx, %rdi
callq 0x3100
pushq $0x8
popq %rdi
callq 0x3190
movq 0x99ec(%rip), %rcx      # 0xffb0
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x99fe(%rip), %rsi      # 0xffd0
movq 0x9a17(%rip), %rdx      # 0xfff0
movq %rax, %rdi
callq 0x3490
movq %rax, %rbx
callq 0x3470
jmp 0x663d
movq %rax, %rdi
callq 0x3b8d
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x3150
jmp 0x6608
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x3150
jmp 0x661c
jmp 0x663a
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x6686
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x3dda
jmp 0x663d
movq %rax, %rbx
jmp 0x668b
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x3c98
jmp 0x6695
movq %rax, %rbx
jmp 0x6695
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x3150
testb %bpl, %bpl
jne 0x6668
jmp 0x669f
movq %rax, %rbx
movq %r14, %rdi
callq 0x3240
jmp 0x669f
jmp 0x6674
movq %rax, %rbx
jmp 0x669f
movq %rax, %rbx
jmp 0x66cd
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x3150
leaq 0x10(%rsp), %rdi
callq 0x3150
leaq 0x78(%rsp), %rdi
callq 0x3150
leaq 0x38(%rsp), %rdi
callq 0x3dda
jmp 0x66cd
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
callq 0x3150
testb %bpl, %bpl
jne 0x66c5
jmp 0x66cd
movq %rax, %rbx
movq %r14, %rdi
callq 0x3240
movq %rbx, %rdi
callq 0x34b0
nop