// File: /workspace/github_cpp_makefile_star2_O3/SeTriones[P]Anubis/receiver.cpp
// Function: receiver::handle_request(int, int, char*)
int receiver::handle_request(int fd, int epoll_fd, char* buf) {
	int need_to_read = sizeof(request);
	timeval timeout = {0, 50*1000};
	int ret;
	ret = readn_timeout(fd, buf, need_to_read, &timeout);
	if (ret != need_to_read) {
		close_fd(fd);
		return -1;
	}
	request* req = (request*)buf;
	need_to_read = ntohl(req->key_len) + ntohl(req->body_len);
	ret = readn_timeout(fd, buf + sizeof(uint32_t) * 2, need_to_read, &timeout);
	if (ret != need_to_read) {
		close_fd(fd);
		return -1;
	}
	uint64_t key;
	uint8_t section_id;
	key = get_raw_key(buf, &section_id);
	KeyGroup* key_group = key_groups[section_id % key_group_cnt];
	int cnt = key_group->Inc(key);
	uint32_t ucnt = (uint32_t)cnt;
	_INFO("get key=%lu,seciond_id=%u,cnt=%u", key, section_id, ucnt);
	int wcnt = writen_timeout(fd, &endian, sizeof(uint8_t), 10);
	_INFO("wcnt=%d", wcnt);
	wcnt = writen_timeout(fd, &ucnt, sizeof(uint32_t), 10);
	_INFO("wcnt=%d", wcnt);
	add_input_fd(fd, epoll_fd);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %r13
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r14
movups 0x15ac(%rip), %xmm0     # 0x6630
leaq 0x50(%rsp), %r8
movaps %xmm0, (%r8)
leaq 0x38(%rdi), %r15
movq %r15, %rdi
movq %rcx, %rdx
movl $0x8, %ecx
callq 0x391a
cmpl $0x8, %eax
jne 0x50d1
movl (%r13), %eax
movl 0x4(%r13), %r12d
bswapl %eax
bswapl %r12d
addl %eax, %r12d
leaq 0x8(%r13), %rdx
leaq 0x50(%rsp), %r8
movq %r15, %rdi
movl %ebx, %esi
movl %r12d, %ecx
callq 0x391a
cmpl %r12d, %eax
je 0x50fa
addq $0x40, %r14
movq %r14, %rdi
movl %ebx, %esi
callq 0x25f6
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl (%r13), %eax
movl 0x4(%r13), %ecx
bswapl %eax
movq %rax, (%rsp)
bswapl %ecx
movq %rcx, 0x18(%rsp)
leaq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x21e0
leaq 0x60(%rsp), %rsi
movq %r12, %rdi
movq %rsi, %r12
callq 0x2100
leaq 0xed1(%rip), %rdx       # 0x6004
leaq 0x30(%rsp), %rdi
movl $0x12, %esi
movq %r12, %rcx
callq 0x2190
movq 0x3e8c(%rip), %rax      # 0x8fd8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x21c0
movq %rax, 0x20(%rsp)
movl 0x8(%r13), %r10d
bswapl %r10d
leaq 0x1482(%rip), %rsi      # 0x65ee
leaq 0x1008(%rip), %r8       # 0x617b
xorl %r12d, %r12d
movq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %rax, %rcx
movq (%rsp), %r9
xorl %eax, %eax
pushq %r10
pushq 0x20(%rsp)
callq 0x22f0
addq $0x10, %rsp
movl %ebp, 0x18(%rsp)
movq (%rsp), %rbp
movq %rbp, %rdi
callq 0x22b0
movq %rax, 0x48(%rsp)
leaq -0x4(%rbp), %rax
movq %rax, 0x10(%rsp)
xorl %edi, %edi
callq 0x21e0
movl 0x8(%r13), %ecx
bswapl %ecx
cqto
idivq %rcx
leaq 0x30(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x30(%rsp), %rsi
movq 0x48(%rsp), %rbp
movq %rbp, %rdi
movq 0x10(%rsp), %rdx
callq 0x21a0
leaq 0x60(%rsp), %r13
movq %rbp, %rdi
movq (%rsp), %rsi
movq %r13, %rdx
callq 0x2350
movq (%r13), %r13
movq %rbp, %rdi
callq 0x2260
movq 0xf8(%r14), %rcx
movzbl %r13b, %eax
movq %rax, (%rsp)
xorl %edx, %edx
idivl 0xec(%r14)
movq (%rcx,%rdx,8), %rdi
movq %r13, %rsi
callq 0x3ea6
movl %eax, %ebp
leaq 0x2c(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x8(%rsp), %rdi
callq 0x21e0
leaq 0x60(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x2100
leaq 0x30(%rsp), %rdi
movl $0x12, %esi
leaq 0xda7(%rip), %rdx       # 0x6004
leaq 0x60(%rsp), %rcx
callq 0x2190
movq 0x3d6a(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x131d(%rip), %rsi      # 0x6595
leaq 0x30(%rsp), %rdx
movq 0x20(%rsp), %rcx
leaq 0xef2(%rip), %r8        # 0x617b
movq %r13, %r9
xorl %eax, %eax
pushq %rbp
pushq 0x8(%rsp)
callq 0x22f0
addq $0x10, %rsp
leaq 0xf4(%r14), %rdx
movq %r15, %rdi
movl %ebx, %esi
movl $0x1, %ecx
movl $0xa, %r8d
callq 0x39c2
movl %eax, (%rsp)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x21e0
leaq 0x60(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2100
leaq 0x30(%rsp), %r13
movl $0x12, %esi
movq %r13, %rdi
leaq 0xd18(%rip), %rdx       # 0x6004
movq %rbp, %rcx
callq 0x2190
movq 0x3cdd(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x12c9(%rip), %rbp      # 0x65ce
movq %rbp, %rsi
movq %r13, %rdx
movq 0x20(%rsp), %rcx
leaq 0xe64(%rip), %r8        # 0x617b
movl (%rsp), %r9d
xorl %eax, %eax
callq 0x22f0
movq %r15, %rdi
movl %ebx, %esi
leaq 0x2c(%rsp), %rdx
movl $0x4, %ecx
movl $0xa, %r8d
callq 0x39c2
movl %eax, (%rsp)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x21e0
leaq 0x60(%rsp), %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0x2100
leaq 0x30(%rsp), %r13
movl $0x12, %esi
movq %r13, %rdi
leaq 0xc94(%rip), %rdx       # 0x6004
movq %r15, %rcx
callq 0x2190
movq 0x3c59(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq 0x20(%rsp), %rcx
leaq 0xde7(%rip), %r8        # 0x617b
movl (%rsp), %r9d
xorl %eax, %eax
callq 0x22f0
addq $0x40, %r14
movq %r14, %rdi
movl %ebx, %esi
movl 0x18(%rsp), %edx
callq 0x34e6
jmp 0x50e5