// File: /workspace/github_cpp_makefile_star2_O3/alibakhtiar[P]ExampleHTTPServer/./HttpServer.hh
// Function: SimpleHttpServer::serverRequestHandler(SimpleHttpServer::Server*, int, sockaddr_in)
static void serverRequestHandler(Server *server, int sock, struct sockaddr_in clientAddr)
{
	bool rc;
	Request *req;
	Response *res;
	char *buffer;
	ssize_t recvLen;

	// New request
	req = new Request;
	req->sock = sock;
	req->addr = clientAddr;

	// New response
	res = new Response;
	res->sock = sock;
	res->req  = req;

	// Recv buffer
	buffer = new char[1+RECV_BUFFER_SIZE];

	while (1) {
		memset(buffer, '\0', 1+RECV_BUFFER_SIZE);

		recvLen = recv(sock, buffer, RECV_BUFFER_SIZE, 0);
		if (recvLen == 0) {
			break;
		}
		else if (recvLen < 0) {
			APPERROR(_STRERR, _FUNC, _LINE);
			break;
		}

		// Request parser
		rc = httpRequestParse(req, buffer, recvLen);
		if (rc == false)
			break;

		if (req->hasError == true) {
			res->statusCode = 400;
			res->errorPage();
			res->send();
			break;
		}

		if (server->onRequestCallback != NULL)
			server->onRequestCallback(req, res);

		break;
	}

	close(sock);

	delete[] buffer;
	buffer = NULL;

	delete req;
	req = NULL;

	delete res;
	res = NULL;

	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r15
movq %rdx, %r12
movl %esi, %ebp
movq %rdi, %r14
movl $0xb8, %edi
callq 0x21b0
movq %rax, %rbx
leaq 0x5090(%rip), %rax      # 0x7cd0
movq %rax, (%rbx)
xorl %r13d, %r13d
movb %r13b, 0x1c(%rbx)
leaq 0x30(%rbx), %rax
movq %rax, 0x20(%rbx)
movq %r13, 0x28(%rbx)
movb %r13b, 0x30(%rbx)
leaq 0x50(%rbx), %rax
movq %rax, 0x40(%rbx)
movq %r13, 0x48(%rbx)
movb %r13b, 0x50(%rbx)
leaq 0x70(%rbx), %rax
movq %rax, 0x60(%rbx)
movq %r13, 0x68(%rbx)
movb %r13b, 0x70(%rbx)
movq %r13, 0x80(%rbx)
leaq 0x90(%rbx), %rax
movl %r13d, 0x90(%rbx)
movq %r13, 0x98(%rbx)
movq %rax, 0xa0(%rbx)
movq %rax, 0xa8(%rbx)
movq %r13, 0xb0(%rbx)
movl %ebp, 0x8(%rbx)
movq %r12, 0xc(%rbx)
movq %r15, 0x14(%rbx)
movl $0x70, %edi
callq 0x21b0
movq %rax, %r15
leaq 0x5036(%rip), %rax      # 0x7d00
movq %rax, (%r15)
movl $0xc8, 0x18(%r15)
leaq 0x28(%r15), %rax
movl %r13d, 0x28(%r15)
movq %r13, 0x30(%r15)
movq %rax, 0x38(%r15)
movq %rax, 0x40(%r15)
movq %r13, 0x48(%r15)
leaq 0x60(%r15), %rax
movq %rax, 0x50(%r15)
movq %r13, 0x58(%r15)
movb %r13b, 0x60(%r15)
movl %ebp, 0x8(%r15)
movq %rbx, 0x10(%r15)
movl $0x801, %edi            # imm = 0x801
callq 0x2030
movq %rax, %r12
movl $0x801, %edx            # imm = 0x801
movq %rax, %rdi
xorl %esi, %esi
callq 0x2140
movl $0x800, %edx            # imm = 0x800
movl %ebp, %edi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x20d0
testq %rax, %rax
je 0x2d88
js 0x2db8
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x25ac
cmpb $0x1, 0x1c(%rbx)
jne 0x2d69
movl $0x190, 0x18(%r15)      # imm = 0x190
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
jmp 0x2d88
cmpq $0x0, 0x40(%r14)
je 0x2d88
leaq 0x30(%r14), %rdi
leaq 0x10(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0x8(%rsp), %rdx
movq %r15, (%rdx)
callq *0x48(%r14)
movl %ebp, %edi
callq 0x2300
movq %r12, %rdi
callq 0x2230
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq (%r15), %rax
movq %r15, %rdi
callq *0x28(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x240f
jmp 0x2d88