// File: /workspace/github_c_makefile_star2_O0/yakushstanislav[P]EagleMQ/src/handlers.c
// Function: stat_command_handler
void stat_command_handler(EagleClient *client)
{
	ProtocolRequestStat *req = (ProtocolRequestStat*)client->request;
	ProtocolResponseStat *stat;
	struct rusage self_ru, c_ru;

	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;
	}

	getrusage(RUSAGE_SELF, &self_ru);
	getrusage(RUSAGE_CHILDREN, &c_ru);

	stat = (ProtocolResponseStat*)xcalloc(sizeof(*stat));

	set_response_header(&stat->header, req->cmd, EG_PROTOCOL_STATUS_SUCCESS, sizeof(stat->body));

	stat->body.version.major = EAGLE_VERSION_MAJOR;
	stat->body.version.minor = EAGLE_VERSION_MINOR;
	stat->body.version.patch = EAGLE_VERSION_PATCH;

	stat->body.uptime = time(NULL) - server->start_time;
	stat->body.used_cpu_sys = (float)self_ru.ru_stime.tv_sec + (float)self_ru.ru_stime.tv_usec/1000000;
	stat->body.used_cpu_user = (float)self_ru.ru_utime.tv_sec + (float)self_ru.ru_utime.tv_usec/1000000;
	stat->body.used_memory = xmalloc_used_memory();
	stat->body.used_memory_rss = xmalloc_memory_rss();
	stat->body.fragmentation_ratio = xmalloc_fragmentation_ratio();
	stat->body.clients = EG_LIST_LENGTH(server->clients);
	stat->body.users = EG_LIST_LENGTH(server->users);
	stat->body.queues = EG_LIST_LENGTH(server->queues);
	stat->body.routes = EG_LIST_LENGTH(server->routes);
	stat->body.channels = EG_LIST_LENGTH(server->channels);
	stat->body.resv3 = 0;
	stat->body.resv4 = 0;

	add_response(client, stat, sizeof(*stat));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
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 0x6a7b
movq -0x8(%rbp), %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x6980
jmp 0x6c5a
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x20, %rax
cmpq $0x0, %rax
jne 0x6aa8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %esi
movl $0x5, %edx
callq 0x6980
jmp 0x6c5a
xorl %edi, %edi
leaq -0xa8(%rbp), %rsi
callq 0x2410
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leaq -0x138(%rbp), %rsi
callq 0x2410
movl $0x3f, %edi
callq 0x5160
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0x1, %edx
movl $0x37, %ecx
movzbl 0x2(%rax), %esi
callq 0x6c70
movq -0x18(%rbp), %rax
movb $0x1, 0x8(%rax)
movq -0x18(%rbp), %rax
movb $0x3, 0x9(%rax)
movq -0x18(%rbp), %rax
movb $0x0, 0xa(%rax)
xorl %eax, %eax
movl %eax, %edi
callq 0x22e0
leaq 0x10798(%rip), %rcx     # 0x172b0
movq (%rcx), %rcx
subq 0x198(%rcx), %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xb(%rax)
cvtsi2ssq -0x98(%rbp), %xmm0
cvtsi2ssq -0x90(%rbp), %xmm1
movss 0xbb8f(%rip), %xmm2     # 0x126d4
divss %xmm2, %xmm1
addss %xmm1, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0xf(%rax)
cvtsi2ssq -0xa8(%rbp), %xmm0
cvtsi2ssq -0xa0(%rbp), %xmm1
movss 0xbb64(%rip), %xmm2     # 0x126d4
divss %xmm2, %xmm1
addss %xmm1, %xmm0
movq -0x18(%rbp), %rax
movss %xmm0, 0x13(%rax)
callq 0x5530
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x17(%rax)
callq 0x5590
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1b(%rax)
callq 0x5750
movq -0x18(%rbp), %rax
movss %xmm0, 0x1f(%rax)
leaq 0x106fe(%rip), %rax     # 0x172b0
movq (%rax), %rax
movq 0x160(%rax), %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x23(%rax)
leaq 0x106e3(%rip), %rax     # 0x172b0
movq (%rax), %rax
movq 0x168(%rax), %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x27(%rax)
leaq 0x106c8(%rip), %rax     # 0x172b0
movq (%rax), %rax
movq 0x170(%rax), %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x2b(%rax)
leaq 0x106ad(%rip), %rax     # 0x172b0
movq (%rax), %rax
movq 0x178(%rax), %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x2f(%rax)
leaq 0x10692(%rip), %rax     # 0x172b0
movq (%rax), %rax
movq 0x180(%rax), %rax
movl 0x20(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x33(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x37(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x3b(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x3f, %edx
callq 0x6cb0
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)