// File: dentiny[P]HTTP-Cache-Proxy/Proxy.cpp
// Function: Proxy::getResponse(int, int, int, Request const&)
void getResponse(int client_id, int client_fd, int server_fd, const Request & request)
	{
	    // get header first, decide whether content-based or chunk-based
	    std::vector<char> buffer(BUFFER_SIZE, '\0');
	    int len = 0; // len is the length of received header length
	    try
	    {
	    	len = getResponseHeader(server_fd, buffer);
	    }
	    catch(std::exception & e)
	    {
	    	throw e;
	    }

	    // send header to the client
	    if(!respondClient(client_fd, buffer, len))
	    {
	    	throw ProxyException("Proxy send to client error");
	    }

	    // get url of the request, and pass it as the argument of getResponse() body part
	    const std::string url = request.url;
	    const std::string header(buffer.begin(), buffer.begin() + len + 1);
	    std::vector<std::vector<char>> segment; // store every segment of the response from the server
	    segment.push_back(std::vector<char>(buffer.begin(), buffer.begin() + len)); // push header into the segment vector
	    try
	    {
	    	getResponse(client_id, client_fd, server_fd, url, header, segment, len, request.httpAction);
	    }
	    catch(std::exception & e)
	    {
	    	throw e;
	    }
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
movb $0x0, -0x39(%rbp)
leaq -0x3a(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x4650
movq -0x148(%rbp), %rcx
leaq -0x38(%rbp), %rdi
movl $0x10000, %esi          # imm = 0x10000
leaq -0x39(%rbp), %rdx
callq 0x9390
jmp 0x16e46
leaq -0x3a(%rbp), %rdi
callq 0x4420
movq -0x150(%rbp), %rdi
movl $0x0, -0x50(%rbp)
movl -0x14(%rbp), %esi
leaq -0x38(%rbp), %rdx
callq 0x17310
movl %eax, -0x154(%rbp)
jmp 0x16e71
movl -0x154(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x16f16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x3a(%rbp), %rdi
callq 0x4420
jmp 0x172f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x172e7
movq -0x48(%rbp), %rdi
callq 0x4120
movq %rax, -0x58(%rbp)
movl $0x8, %edi
callq 0x41b0
movq %rax, %rdi
movq %rdi, -0x160(%rbp)
movq -0x58(%rbp), %rsi
callq 0x7db0
movq -0x160(%rbp), %rdi
movq 0xd0e3(%rip), %rsi      # 0x23fd0
movq 0xd0fc(%rip), %rdx      # 0x23ff0
callq 0x4610
jmp 0x17301
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x45d0
jmp 0x16f11
jmp 0x172e7
movq -0x150(%rbp), %rdi
movl -0x10(%rbp), %esi
movl -0x50(%rbp), %ecx
leaq -0x38(%rbp), %rdx
callq 0x10e70
movb %al, -0x161(%rbp)
jmp 0x16f34
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x1700d
jmp 0x16f44
movb $0x1, -0x7a(%rbp)
movl $0x28, %edi
callq 0x41b0
movq %rax, -0x178(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x4650
movq -0x170(%rbp), %rdx
leaq 0x2603(%rip), %rsi      # 0x1957a
leaq -0x78(%rbp), %rdi
callq 0x4bf0
jmp 0x16f82
movq -0x178(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x9240
jmp 0x16f94
movq -0x178(%rbp), %rdi
movb $0x0, -0x7a(%rbp)
leaq 0xcd52(%rip), %rsi      # 0x23cf8
leaq -0xdcfd(%rip), %rdx     # 0x92b0
callq 0x4610
jmp 0x17301
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x172e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x16feb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x4250
leaq -0x79(%rbp), %rdi
callq 0x4420
testb $0x1, -0x7a(%rbp)
jne 0x16ffc
jmp 0x17008
movq -0x178(%rbp), %rdi
callq 0x42d0
jmp 0x172e7
movq -0x20(%rbp), %rsi
addq $0x60, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x4150
jmp 0x17023
leaq -0x38(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0xa150
movq -0x188(%rbp), %rdi
movq %rax, -0xc8(%rbp)
callq 0xa150
movq %rax, -0xe0(%rbp)
movslq -0x50(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0xa180
movq %rax, -0xd8(%rbp)
leaq -0xd8(%rbp), %rdi
movl $0x1, %esi
callq 0xa180
movq %rax, -0xd0(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x4650
movq -0x180(%rbp), %rcx
movq -0xc8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x10cb0
jmp 0x170b2
leaq -0xe1(%rbp), %rdi
callq 0x4420
leaq -0x100(%rbp), %rdi
callq 0xd730
leaq -0x38(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0xa150
movq -0x198(%rbp), %rdi
movq %rax, -0x120(%rbp)
callq 0xa150
movq %rax, -0x130(%rbp)
movslq -0x50(%rbp), %rsi
leaq -0x130(%rbp), %rdi
callq 0xa180
movq %rax, -0x128(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x4650
movq -0x190(%rbp), %rcx
movq -0x120(%rbp), %rsi
movq -0x128(%rbp), %rdx
leaq -0x118(%rbp), %rdi
callq 0xa1c0
jmp 0x17141
leaq -0x100(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x10e40
jmp 0x17156
leaq -0x118(%rbp), %rdi
callq 0x6130
leaq -0x131(%rbp), %rdi
callq 0x4420
movq -0x150(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
movl -0x50(%rbp), %r8d
movq -0x20(%rbp), %r9
addq $0x40, %r9
movq %rsp, %rax
movq %r9, 0x10(%rax)
movl %r8d, 0x8(%rax)
leaq -0x100(%rbp), %r8
movq %r8, (%rax)
leaq -0xa0(%rbp), %r8
leaq -0xc0(%rbp), %r9
callq 0x10ef0
jmp 0x171b4
jmp 0x1728d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xe1(%rbp), %rdi
callq 0x4420
jmp 0x172db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x171fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x6130
leaq -0x131(%rbp), %rdi
callq 0x4420
jmp 0x172c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x172c3
movq -0x48(%rbp), %rdi
callq 0x4120
movq %rax, -0x140(%rbp)
movl $0x8, %edi
callq 0x41b0
movq %rax, %rdi
movq %rdi, -0x1a0(%rbp)
movq -0x140(%rbp), %rsi
callq 0x7db0
movq -0x1a0(%rbp), %rdi
movq 0xcd69(%rip), %rsi      # 0x23fd0
movq 0xcd82(%rip), %rdx      # 0x23ff0
callq 0x4610
jmp 0x17301
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x45d0
jmp 0x1728b
jmp 0x172c3
leaq -0x100(%rbp), %rdi
callq 0x5a00
leaq -0xc0(%rbp), %rdi
callq 0x4250
leaq -0xa0(%rbp), %rdi
callq 0x4250
leaq -0x38(%rbp), %rdi
callq 0x6130
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
leaq -0x100(%rbp), %rdi
callq 0x5a00
leaq -0xc0(%rbp), %rdi
callq 0x4250
leaq -0xa0(%rbp), %rdi
callq 0x4250
leaq -0x38(%rbp), %rdi
callq 0x6130
movq -0x48(%rbp), %rdi
callq 0x4640
movq %rax, %rdi
callq 0x52e0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)