// File: /workspace/github_c_makefile_star2_O0/yakushstanislav[P]EagleMQ/src/handlers.c
// Function: route_keys_command_handler
void route_keys_command_handler(EagleClient *client)
{
	ProtocolRequestRouteKeys *req = (ProtocolRequestRouteKeys*)client->request;
	ProtocolResponseHeader res;
	KeylistIterator keylist_iterator;
	KeylistNode *keylist_node;
	ListIterator list_iterator;
	ListNode *list_node;
	Route_t *route;
	Queue_t *queue_t;
	char *key;
	List *queues;
	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_ROUTE_PERM)
		&& !BIT_CHECK(client->perm, EG_USER_ROUTE_KEYS_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;
	}

	route = find_route_t(server->routes, req->body.name);
	if (!route) {
		add_status_response(client, req->header.cmd, EG_PROTOCOL_STATUS_ERROR_NOT_FOUND);
		return;
	}

	set_response_header(&res, req->header.cmd, EG_PROTOCOL_STATUS_SUCCESS,
		get_queue_number_route_t(route) * (32 + 64));

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

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

	i = sizeof(res);
	keylist_rewind(route->keys, &keylist_iterator);
	while ((keylist_node = keylist_next_node(&keylist_iterator)) != NULL)
	{
		key = EG_KEYLIST_NODE_KEY(keylist_node);
		queues = EG_KEYLIST_NODE_VALUE(keylist_node);

		list_rewind(queues, &list_iterator);
		while ((list_node = list_next_node(&list_iterator)) != NULL)
		{
			queue_t = EG_LIST_NODE_VALUE(list_node);

			memcpy(list + i, key, strlenz(key));
			i += 32;
			memcpy(list + i, queue_t->name, strlenz(queue_t->name));
			i += 64;
		}
	}

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x48, 0x20(%rax)
jae 0x930b
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x6980
jmp 0x953e
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x20, %rax
cmpq $0x0, %rax
jne 0x9362
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x2, %rax
cmpq $0x0, %rax
jne 0x9362
movq -0x8(%rbp), %rcx
movabsq $0x2000000000, %rax     # imm = 0x2000000000
andq 0x8(%rcx), %rax
cmpq $0x0, %rax
jne 0x9362
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0x5, %edx
callq 0x6980
jmp 0x953e
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movl $0x40, %esi
callq 0x63b0
cmpl $0x0, %eax
jne 0x9394
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0x7, %edx
callq 0x6980
jmp 0x953e
leaq 0xdf15(%rip), %rax      # 0x172b0
movq (%rax), %rax
movq 0x178(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0xdfe0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x93d8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0x9, %edx
callq 0x6980
jmp 0x953e
movq -0x10(%rbp), %rax
movb 0x2(%rax), %al
movb %al, -0x6d(%rbp)
movq -0x48(%rbp), %rdi
callq 0xe0a0
movl %eax, %ecx
movb -0x6d(%rbp), %al
imull $0x60, %ecx, %ecx
leaq -0x18(%rbp), %rdi
movl $0x1, %edx
movzbl %al, %esi
callq 0x6c70
movl -0x14(%rbp), %eax
movl %eax, %edi
addq $0x8, %rdi
callq 0x5160
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, (%rax)
movl $0x8, -0x6c(%rbp)
movq -0x48(%rbp), %rax
movq 0x50(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0xbde0
leaq -0x20(%rbp), %rdi
callq 0xbe00
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x9528
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xc520
leaq -0x38(%rbp), %rdi
callq 0xc450
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x9523
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x58(%rbp), %rdi
callq 0x2160
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x22c0
movl -0x6c(%rbp), %eax
addl $0x20, %eax
movl %eax, -0x6c(%rbp)
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rdi
callq 0x2160
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x22c0
movl -0x6c(%rbp), %eax
addl $0x40, %eax
movl %eax, -0x6c(%rbp)
jmp 0x9475
jmp 0x9439
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movl -0x14(%rbp), %eax
addq $0x8, %rax
movl %eax, %edx
callq 0x6cb0
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)