// File: /workspace/github_c_makefile_star2_O0/yakushstanislav[P]EagleMQ/src/handlers.c
// Function: queue_pop_command_handler
void queue_pop_command_handler(EagleClient *client)
{
	ProtocolRequestQueuePop *req = (ProtocolRequestQueuePop*)client->request;
	ProtocolResponseHeader res;
	Queue_t *queue_t;
	Message *msg;
	char *buffer;

	if (client->pos < sizeof(*req)) {
		add_status_response(client, 0, EG_PROTOCOL_STATUS_ERROR_PACKET);
		return;
	}

	if (!BIT_CHECK(client->perm, EG_USER_ADMIN_PERM) && !BIT_CHECK(client->perm, EG_USER_QUEUE_PERM)
		&& !BIT_CHECK(client->perm, EG_USER_QUEUE_POP_PERM)) {
		add_status_response(client, req->header.cmd, EG_PROTOCOL_STATUS_ERROR_ACCESS);
		return;
	}

	if (!check_input_buffer2(req->body.name, 64)) {
		add_status_response(client, req->header.cmd, EG_PROTOCOL_STATUS_ERROR_VALUE);
		return;
	}

	queue_t = find_queue_t(client->declared_queues, req->body.name);
	if (!queue_t) {
		add_status_response(client, req->header.cmd, EG_PROTOCOL_STATUS_ERROR_NOT_DECLARED);
		return;
	}

	msg = get_message_queue_t(queue_t);
	if (!msg) {
		add_status_response(client, req->header.cmd, EG_PROTOCOL_STATUS_ERROR_NO_DATA);
		return;
	}

	set_response_header(&res, req->header.cmd, EG_PROTOCOL_STATUS_SUCCESS, EG_MESSAGE_SIZE(msg) + sizeof(uint64_t));

	buffer = (char*)xmalloc(sizeof(res) + sizeof(uint64_t));

	memcpy(buffer, &res, sizeof(res));
	memcpy(buffer + sizeof(res), &msg->tag, sizeof(uint64_t));

	add_response(client, buffer, sizeof(res) + sizeof(uint64_t));
	add_object_response(client, EG_MESSAGE_OBJECT(msg));

	pop_message_queue_t(queue_t, req->body.timeout);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x4c, 0x20(%rax)
jae 0x8678
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x6980
jmp 0x87e9
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x20, %rax
cmpq $0x0, %rax
jne 0x86cb
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0x86cb
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x10000000, %rax       # imm = 0x10000000
cmpq $0x0, %rax
jne 0x86cb
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0x5, %edx
callq 0x6980
jmp 0x87e9
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movl $0x40, %esi
callq 0x63b0
cmpl $0x0, %eax
jne 0x86fd
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0x7, %edx
callq 0x6980
jmp 0x87e9
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0xd500
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x8738
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0x8, %edx
callq 0x6980
jmp 0x87e9
movq -0x20(%rbp), %rdi
callq 0xd450
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x8767
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0xa, %edx
callq 0x6980
jmp 0x87e9
movq -0x10(%rbp), %rax
movb 0x2(%rax), %al
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
addq $0x8, %rcx
leaq -0x18(%rbp), %rdi
movl $0x1, %edx
movzbl %al, %esi
callq 0x6c70
movl $0x10, %edi
callq 0x5090
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, (%rax)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl $0x10, %edx
callq 0x6cb0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rsi
callq 0x85f0
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x48(%rax), %esi
callq 0xd3c0
addq $0x30, %rsp
popq %rbp
retq
nop