// File: /workspace/github_c_makefile_star2_O0/yakushstanislav[P]EagleMQ/src/handlers.c
// Function: user_list_command_handler
void user_list_command_handler(EagleClient *client)
{
	ProtocolRequestUserList *req = (ProtocolRequestUserList*)client->request;
	ProtocolResponseHeader res;
	EagleUser *user;
	ListIterator iterator;
	ListNode *node;
	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)) {
		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->users) * (64 + sizeof(uint64_t)));

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

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

	i = sizeof(res);
	list_rewind(server->users, &iterator);
	while ((node = list_next_node(&iterator)) != NULL)
	{
		user = EG_LIST_NODE_VALUE(node);
		memcpy(list + i, user->name, strlenz(user->name));
		memcpy(list + i + 32, user->password, strlenz(user->password));
		memcpy(list + i + 64, &user->perm, sizeof(uint64_t));
		i += 64 + sizeof(uint64_t);
	}

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x8, 0x20(%rax)
jae 0x7358
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x6980
jmp 0x74c5
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x20, %rax
cmpq $0x0, %rax
jne 0x7385
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0x5, %edx
callq 0x6980
jmp 0x74c5
movq -0x10(%rbp), %rax
movb 0x2(%rax), %al
leaq 0xff1d(%rip), %rcx      # 0x172b0
movq (%rcx), %rcx
movq 0x168(%rcx), %rcx
movl 0x20(%rcx), %ecx
imulq $0x48, %rcx, %rcx
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, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movq %rcx, (%rax)
movl $0x8, -0x44(%rbp)
leaq 0xfed0(%rip), %rax      # 0x172b0
movq (%rax), %rax
movq 0x168(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0xc520
leaq -0x30(%rbp), %rdi
callq 0xc450
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x74af
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2160
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x22c0
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
addq %rcx, %rax
addq $0x20, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x2160
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x22c0
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq -0x20(%rbp), %rdx
movq 0x40(%rdx), %rdx
movq %rdx, 0x40(%rax,%rcx)
movslq -0x44(%rbp), %rax
addq $0x48, %rax
movl %eax, -0x44(%rbp)
jmp 0x73f3
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x14(%rbp), %eax
addq $0x8, %rax
movl %eax, %edx
callq 0x6cb0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)