// File: /workspace/github_cpp_makefile_star2_O1/dentiny[P]HTTP-Cache-Proxy/Proxy.cpp
// Function: Proxy::handleConnect(int, int, int, Request const&)
void handleConnect(int client_id, int client_fd, int server_fd, const Request & request)
	{
		// send a 200 OK to client
		const char * okMsg = "200 OK";
		int len = send(client_fd, okMsg, strlen(okMsg) + 1, 0);
		if(len == -1)
		{
			throw ProxyException("Send 200 OK to client error");
		}

		// select and keep listening
		bool connectionEnd = false;
		fd_set rfds;
		int fds[] = { client_fd, server_fd };
		int max_fd = std::max(fds[0], fds[1]) + 1; // argument of select() is the maximum fd + 1
		std::vector<char> buffer(BUFFER_SIZE, '\0'); // buffer to store request or response
		while(true)
		{
			// check if break loop
			if(connectionEnd)
			{
				break;
			}

			// initialize the fd set
			FD_ZERO(&rfds);
			FD_SET(fds[0], &rfds);
			FD_SET(fds[1], &rfds);

			// listen to fds in a blocking way
			status = select(max_fd, &rfds, NULL, NULL, NULL); 
			if(status == -1)
			{
				throw ProxyException("Server or client select error");
			}

			// receive request or respond from the set fd
			// send to the other fd
			for(int i = 0; i < 2; ++i)
			{
				if(FD_ISSET(fds[i], &rfds))
				{
					// receive
					len = recv(fds[i], &buffer.data()[0], BUFFER_SIZE - 1, 0);
					if(len == -1)
					{
						throw ProxyException("Receive request or respond error");
					}

					// decide the end of CONNECT
					else if(len == 0)
					{
						connectionEnd = true;
						break;
					}
					buffer[len] = '\0';

					// send
					len = send(fds[1 - i], &buffer.data()[0], len, 0);
					if(len == -1)
					{
						throw ProxyException("Send to client or server error");
					}
				}
			}
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %ecx, %r15d
movl %edx, %r12d
movq %rdi, 0x10(%rsp)
leaq 0x784a(%rip), %rsi      # 0xd251
movl $0x7, %edx
movl %r12d, %edi
xorl %ecx, %ecx
callq 0x31b0
cmpl $-0x1, %eax
je 0x5cea
movl %r12d, 0x8(%rsp)
movl %r15d, 0xc(%rsp)
cmpl %r15d, %r12d
movl %r15d, %r14d
cmovgl %r12d, %r14d
movl $0x10000, %edi          # imm = 0x10000
callq 0x3330
movq %rax, %rbx
incl %r14d
xorl %r13d, %r13d
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
xorl %esi, %esi
callq 0x31f0
leal 0x3f(%r12), %eax
testl %r12d, %r12d
cmovnsl %r12d, %eax
movl %eax, %ecx
andl $-0x40, %ecx
subl %ecx, %r12d
movl $0x1, %edx
movl %r12d, %ecx
shlq %cl, %rdx
movq %rdx, 0x28(%rsp)
movl $0x1, %edx
sarl $0x6, %eax
cltq
movq %rax, 0x18(%rsp)
leal 0x3f(%r15), %eax
testl %r15d, %r15d
cmovnsl %r15d, %eax
movl %eax, %ecx
andl $-0x40, %ecx
subl %ecx, %r15d
movl %r15d, %ecx
shlq %cl, %rdx
movq %rdx, 0x20(%rsp)
sarl $0x6, %eax
movslq %eax, %rbp
xorps %xmm0, %xmm0
movaps %xmm0, 0x120(%rsp)
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movq 0x28(%rsp), %rax
movq 0x18(%rsp), %rcx
orq %rax, 0xb0(%rsp,%rcx,8)
movq 0x20(%rsp), %rax
orq %rax, 0xb0(%rsp,%rbp,8)
movl %r14d, %edi
leaq 0xb0(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x3300
movq 0x10(%rsp), %rcx
movl %eax, 0x2b0(%rcx)
cmpl $-0x1, %eax
je 0x5c8e
movl %r14d, %r12d
movl $0x1, %r14d
leaq 0x8(%rsp), %r15
movl (%r15), %edi
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
sarl $0x6, %eax
cltq
movq 0xb0(%rsp,%rax,8), %rax
btq %rdi, %rax
jae 0x5b9c
movl $0xffff, %edx           # imm = 0xFFFF
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x3100
testl %eax, %eax
je 0x5ba7
cmpl $-0x1, %eax
je 0x5c32
movslq %eax, %rdx
movb $0x0, (%rbx,%rdx)
movl 0x8(%rsp,%r14,4), %edi
movq %rbx, %rsi
xorl %ecx, %ecx
callq 0x31b0
cmpl $-0x1, %eax
je 0x5bd6
addq $0x4, %r15
decq %r14
je 0x5b47
jmp 0x5baa
movb $0x1, %r13b
testb $0x1, %r13b
movl %r12d, %r14d
je 0x5aac
movl $0x10000, %esi          # imm = 0x10000
movq %rbx, %rdi
callq 0x3340
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x31a0
movq %rax, %r15
leaq 0x40(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x76bf(%rip), %rsi      # 0xd2b3
leaq 0x76d6(%rip), %rdx      # 0xd2d1
leaq 0x30(%rsp), %rdi
callq 0x3c86
movb $0x1, %bpl
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x6aa8
xorl %ebp, %ebp
leaq 0xc0ea(%rip), %rsi      # 0x11d08
leaq 0xecd(%rip), %rdx       # 0x6af2
movq %r15, %rdi
callq 0x34e0
jmp 0x5d49
movl $0x28, %edi
callq 0x31a0
movq %rax, %r15
leaq 0x60(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x7642(%rip), %rsi      # 0xd292
leaq 0x765b(%rip), %rdx      # 0xd2b2
leaq 0x50(%rsp), %rdi
callq 0x3c86
movb $0x1, %bpl
leaq 0x50(%rsp), %rsi
movq %r15, %rdi
callq 0x6aa8
xorl %ebp, %ebp
leaq 0xc08e(%rip), %rsi      # 0x11d08
leaq 0xe71(%rip), %rdx       # 0x6af2
movq %r15, %rdi
callq 0x34e0
jmp 0x5d49
movl $0x28, %edi
callq 0x31a0
movq %rax, %r15
leaq 0x80(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x75c5(%rip), %rsi      # 0xd274
leaq 0x75db(%rip), %rdx      # 0xd291
leaq 0x70(%rsp), %rdi
callq 0x3c86
movb $0x1, %bpl
leaq 0x70(%rsp), %rsi
movq %r15, %rdi
callq 0x6aa8
xorl %ebp, %ebp
leaq 0xc02f(%rip), %rsi      # 0x11d08
leaq 0xe12(%rip), %rdx       # 0x6af2
movq %r15, %rdi
callq 0x34e0
jmp 0x5d49
movl $0x28, %edi
callq 0x31a0
movq %rax, %rbx
leaq 0xa0(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x754e(%rip), %rsi      # 0xd258
leaq 0x7562(%rip), %rdx      # 0xd273
leaq 0x90(%rsp), %rdi
callq 0x3c86
movb $0x1, %bpl
leaq 0x90(%rsp), %rsi
movq %rbx, %rdi
callq 0x6aa8
xorl %ebp, %ebp
leaq 0xbfce(%rip), %rsi      # 0x11d08
leaq 0xdb1(%rip), %rdx       # 0x6af2
movq %rbx, %rdi
callq 0x34e0
movq %rax, %r14
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x5d71
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x3340
jmp 0x5d71
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x5dfb
movq %rbx, %rdi
callq 0x3250
jmp 0x5dfb
movq %rax, %r14
jmp 0x5dfb
movq %rax, %r14
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x5ddc
movq 0x80(%rsp), %rsi
jmp 0x5dcc
jmp 0x5dd6
jmp 0x5deb
movq %rax, %r14
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x5ddc
movq 0x60(%rsp), %rsi
jmp 0x5dcc
jmp 0x5dd6
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x5ddc
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3340
jmp 0x5ddc
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x5dee
movq %r15, %rdi
callq 0x3250
jmp 0x5dee
movq %rax, %r14
movl $0x10000, %esi          # imm = 0x10000
movq %rbx, %rdi
callq 0x3340
movq %r14, %rdi
callq 0x3510
nop