// File: /workspace/github_c_makefile_star2_O3/yakushstanislav[P]EagleMQ/src/handlers.c
// Function: process_request
void process_request(EagleClient *client)
{
	ProtocolRequestHeader *req;

process:
	if (!client->bodylen)
	{
		if (client->nread < sizeof(*req)) {
			add_status_response(client, 0, EG_PROTOCOL_STATUS_ERROR_PACKET);
			return;
		}

		req = (ProtocolRequestHeader*)(client->buffer + client->offset);

		if (req->magic != EG_PROTOCOL_REQ)
		{
			client->offset = 0;
			client->bodylen = 0;
			add_status_response(client, 0, EG_PROTOCOL_STATUS_ERROR_PACKET);
			return;
		}

		if (req->bodylen > EG_MAX_BUF_SIZE)
		{
			client->offset = 0;
			client->bodylen = 0;
			add_status_response(client, 0, EG_PROTOCOL_STATUS_ERROR_PACKET);
			return;
		}

		if (client->length < req->bodylen) {
			client->request = xrealloc(client->request, EG_MAX_BUF_SIZE);
			client->length = EG_MAX_BUF_SIZE;
		}

		int delta = client->nread - sizeof(*req);

		if (delta == (int)req->bodylen)
		{
			memcpy(client->request, client->buffer + client->offset, client->nread);
			client->pos = client->nread;
			client->offset = 0;
			client->nread = 0;
		}
		else if (delta < (int)req->bodylen)
		{
			memcpy(client->request, client->buffer + client->offset, client->nread);
			client->bodylen = req->bodylen - delta;
			client->pos = client->nread;
			return;
		}
		else if (delta > (int)req->bodylen)
		{
			client->pos = req->bodylen + sizeof(*req);
			memcpy(client->request, client->buffer + client->offset, client->pos);
			client->offset += client->pos;
			client->nread -= client->pos;
		}
	} else {
		if (client->nread == client->bodylen)
		{
			memcpy(client->request + client->pos, client->buffer, client->nread);
			client->pos += client->nread;
			client->offset = 0;
			client->nread = 0;
			client->bodylen = 0;
		}
		else if (client->nread < client->bodylen)
		{
			memcpy(client->request + client->pos, client->buffer, client->nread);
			client->pos += client->nread;
			client->bodylen -= client->nread;
			client->offset = 0;
			return;
		}
		else if (client->nread > client->bodylen)
		{
			memcpy(client->request + client->pos, client->buffer, client->bodylen);
			client->pos += client->bodylen;
			client->nread -= client->bodylen;
			client->offset = client->bodylen;
			client->bodylen = 0;
		}
	}

	req = (ProtocolRequestHeader*)client->request;
	parse_command(client, req);

	if ((int)client->nread >= (int)sizeof(*req)) {
		goto process;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x38(%rdi), %r14
leaq 0x9dd2(%rip), %r15      # 0x122a0
movq 0x38(%rbx), %rax
movq 0x40(%rbx), %rdx
testq %rax, %rax
je 0x8513
cmpq %rax, %rdx
jne 0x8599
movq 0x10(%rbx), %rdi
movq 0x30(%rbx), %rsi
addq 0x20(%rbx), %rdi
movq %rax, %rdx
callq 0x2280
movq 0x40(%rbx), %rax
addq %rax, 0x20(%rbx)
movl $0x0, 0x2c(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
jmp 0x85fc
cmpq $0x7, %rdx
jbe 0x8643
movq 0x30(%rbx), %r12
movslq 0x2c(%rbx), %r13
cmpw $0x70, (%r12,%r13)
jne 0x8634
movslq 0x4(%r12,%r13), %rax
testq %rax, %rax
js 0x8634
cmpq %rax, 0x18(%rbx)
jae 0x8568
movq 0x10(%rbx), %rdi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
callq 0x4881
movq %rax, 0x10(%rbx)
movq $0x7fffffff, 0x18(%rbx) # imm = 0x7FFFFFFF
movq 0x40(%rbx), %rdx
movl 0x4(%r12,%r13), %eax
leal -0x8(%rdx), %ebp
cmpl %eax, %ebp
jne 0x85ce
movq 0x10(%rbx), %rdi
movslq 0x2c(%rbx), %rsi
addq 0x30(%rbx), %rsi
callq 0x2280
movq 0x40(%rbx), %rax
movq %rax, 0x20(%rbx)
movl $0x0, 0x2c(%rbx)
movq $0x0, 0x40(%rbx)
jmp 0x85fc
jb 0x8660
jbe 0x85fc
movq 0x10(%rbx), %rdi
movq 0x30(%rbx), %rsi
addq 0x20(%rbx), %rdi
movq %rax, %rdx
callq 0x2280
movq 0x38(%rbx), %rax
addq %rax, 0x20(%rbx)
subq %rax, 0x40(%rbx)
movl %eax, 0x2c(%rbx)
movq $0x0, 0x38(%rbx)
jmp 0x85fc
jl 0x8686
jle 0x85fc
movl %eax, %edx
addq $0x8, %rdx
movq %rdx, 0x20(%rbx)
movq 0x10(%rbx), %rdi
movslq 0x2c(%rbx), %rsi
addq 0x30(%rbx), %rsi
callq 0x2280
movq 0x20(%rbx), %rax
addl %eax, 0x2c(%rbx)
subq %rax, 0x40(%rbx)
movq 0x10(%rbx), %rcx
movzbl 0x2(%rcx), %esi
movq (%r15,%rsi,8), %rax
testq %rax, %rax
je 0x861b
movzbl 0x3(%rcx), %ecx
movl %ecx, 0x28(%rbx)
movq %rbx, %rdi
callq *%rax
jmp 0x8628
movq %rbx, %rdi
movl $0x4, %edx
callq 0x5642
cmpl $0x7, 0x40(%rbx)
jg 0x84ce
jmp 0x86aa
movl $0x0, 0x2c(%rbx)
movq $0x0, 0x38(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x3, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5642
movq 0x10(%rbx), %rdi
movq 0x30(%rbx), %rsi
addq 0x20(%rbx), %rdi
callq 0x2280
movq 0x40(%rbx), %rax
addq %rax, 0x20(%rbx)
subq %rax, 0x38(%rbx)
movl $0x0, 0x2c(%rbx)
jmp 0x86aa
movq 0x10(%rbx), %rdi
movslq 0x2c(%rbx), %rsi
addq 0x30(%rbx), %rsi
callq 0x2280
movl 0x4(%r12,%r13), %eax
subl %ebp, %eax
movq %rax, 0x38(%rbx)
movq 0x40(%rbx), %rax
movq %rax, 0x20(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq