// File: /workspace/github_c_makefile_star2_O1/yakushstanislav[P]EagleMQ/src/handlers.c
// Function: queue_list_command_handler
void queue_list_command_handler(EagleClient *client)
{
	ProtocolRequestQueueList *req = (ProtocolRequestQueueList*)client->request;
	ProtocolResponseHeader res;
	ListIterator iterator;
	ListNode *node;
	Queue_t *queue_t;
	uint32_t queue_size, declared_clients, subscribed_clients;
	char *list;
	int i;

	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_LIST_PERM)) {
		add_status_response(client, req->cmd, EG_PROTOCOL_STATUS_ERROR_ACCESS);
		return;
	}

	set_response_header(&res, req->cmd, EG_PROTOCOL_STATUS_SUCCESS,
		EG_LIST_LENGTH(server->queues) * (64 + (sizeof(uint32_t) * 6)));

	list = (char*)xcalloc(sizeof(res) + res.bodylen);

	memcpy(list, &res, sizeof(res));

	i = sizeof(res);
	list_rewind(server->queues, &iterator);
	while ((node = list_next_node(&iterator)) != NULL)
	{
		queue_t = EG_LIST_NODE_VALUE(node);

		queue_size = get_size_queue_t(queue_t);
		declared_clients = get_declared_clients_queue_t(queue_t);
		subscribed_clients = get_subscribed_clients_queue_t(queue_t);

		memcpy(list + i, queue_t->name, strlenz(queue_t->name));
		i += 64;
		memcpy(list + i, &queue_t->max_msg, sizeof(uint32_t));
		i += sizeof(uint32_t);
		memcpy(list + i, &queue_t->max_msg_size, sizeof(uint32_t));
		i += sizeof(uint32_t);
		memcpy(list + i, &queue_t->flags, sizeof(uint32_t));
		i += sizeof(uint32_t);
		memcpy(list + i, &queue_size, sizeof(uint32_t));
		i += sizeof(uint32_t);
		memcpy(list + i, &declared_clients, sizeof(uint32_t));
		i += sizeof(uint32_t);
		memcpy(list + i, &subscribed_clients, sizeof(uint32_t));
		i += sizeof(uint32_t);
	}

	add_response(client, list, sizeof(res) + res.bodylen);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpq $0x7, 0x20(%rdi)
ja 0x5fb9
xorl %esi, %esi
movl $0x3, %edx
jmp 0x6109
movq 0x10(%rdi), %rax
testl $0x800021, 0x8(%rdi)    # imm = 0x800021
movzbl 0x2(%rax), %ebx
je 0x6102
movq %rdi, 0x10(%rsp)
leaq 0xc2b6(%rip), %r14      # 0x12290
movq (%r14), %rax
movq 0x170(%rax), %rax
imull $0x58, 0x20(%rax), %r12d
leaq 0x8(%r12), %rdi
callq 0x4376
movq %rax, %r15
movq %r12, 0x8(%rsp)
movq %r12, %rax
shlq $0x20, %rax
shll $0x10, %ebx
addq %rbx, %rax
addq $0x1000080, %rax        # imm = 0x1000080
movq %rax, (%r15)
movq (%r14), %rax
movq 0x170(%rax), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x8a40
movq %rbx, %rdi
callq 0x89ff
testq %rax, %rax
je 0x60de
movl $0x5c, %ebp
leal -0x54(%rbp), %r12d
movq 0x10(%rax), %r13
movq %r13, %rdi
callq 0x93a1
movl %eax, 0x4(%rsp)
movq %r13, %rdi
callq 0x9387
movl %eax, (%rsp)
movq %r13, %rdi
callq 0x938f
movl %eax, %ebx
movslq %r12d, %r14
leaq (%r15,%r14), %r12
movq %r13, %rdi
callq 0x2160
leaq 0x1(%rax), %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2290
movl 0x40(%r13), %eax
movl %eax, 0x40(%r15,%r14)
leal -0x10(%rbp), %eax
cltq
movl 0x44(%r13), %ecx
movl %ecx, (%r15,%rax)
leal -0xc(%rbp), %eax
cltq
movl 0x48(%r13), %ecx
movl %ecx, (%r15,%rax)
leal -0x8(%rbp), %eax
cltq
movl 0x4(%rsp), %ecx
movl %ecx, (%r15,%rax)
leal -0x4(%rbp), %eax
cltq
movl (%rsp), %ecx
movl %ecx, (%r15,%rax)
movslq %ebp, %rbp
movl %ebx, (%r15,%rbp)
leaq 0x18(%rsp), %rdi
callq 0x89ff
addl $0x58, %ebp
testq %rax, %rax
jne 0x603e
movq 0x8(%rsp), %rdx
addl $0x8, %edx
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x5396
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %esi
movl $0x5, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x51a2