// File: /workspace/github_cpp_makefile_star2_O2/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 0x16fc(%rip), %xmm0     # 0x6628
leaq 0x50(%rsp), %r8
movaps %xmm0, (%r8)
leaq 0x38(%rdi), %r15
pushq $0x8
popq %rcx
movq %r15, %rdi
movq %r13, %rdx
callq 0x3170
cmpl $0x8, %eax
jne 0x4f77
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 0x3170
cmpl %r12d, %eax
je 0x4f9e
addq $0x40, %r14
movq %r14, %rdi
movl %ebx, %esi
callq 0x2a7e
pushq $-0x1
popq %r12
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 0x21d0
leaq 0x60(%rsp), %rsi
movq %r12, %rdi
movq %rsi, %r12
callq 0x2100
leaq 0x102d(%rip), %rdx      # 0x6004
leaq 0x30(%rsp), %rdi
pushq $0x12
popq %rsi
movq %r12, %rcx
callq 0x2180
movq 0x4fea(%rip), %rax      # 0x9fd8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x21b0
movq %rax, 0x20(%rsp)
movl 0x8(%r13), %r10d
bswapl %r10d
leaq 0x15dc(%rip), %rsi      # 0x65ea
leaq 0x1166(%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 0x22e0
popq %rcx
popq %rdx
movl %ebp, 0x18(%rsp)
movq (%rsp), %rbp
movq %rbp, %rdi
callq 0x22a0
movq %rax, 0x48(%rsp)
leaq -0x4(%rbp), %rax
movq %rax, 0x10(%rsp)
xorl %edi, %edi
callq 0x21d0
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 0x2190
leaq 0x60(%rsp), %r13
movq %rbp, %rdi
movq (%rsp), %rsi
movq %r13, %rdx
callq 0x2340
movq (%r13), %r13
movq %rbp, %rdi
callq 0x2250
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 0x391a
movl %eax, %ebp
leaq 0x2c(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x8(%rsp), %rdi
callq 0x21d0
leaq 0x60(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x2100
leaq 0x30(%rsp), %rdi
pushq $0x12
popq %rsi
leaq 0xf09(%rip), %rdx       # 0x6004
leaq 0x60(%rsp), %rcx
callq 0x2180
movq 0x4ecc(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
leaq 0x147b(%rip), %rsi      # 0x6591
leaq 0x30(%rsp), %rdx
movq 0x20(%rsp), %rcx
leaq 0x1054(%rip), %r8       # 0x617b
movq %r13, %r9
xorl %eax, %eax
pushq %rbp
pushq 0x8(%rsp)
callq 0x22e0
popq %rcx
popq %rdx
leaq 0xf4(%r14), %rdx
pushq $0x1
popq %rcx
pushq $0xa
popq %r8
movq %r15, %rdi
movl %ebx, %esi
callq 0x3214
movl %eax, (%rsp)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x21d0
leaq 0x60(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2100
leaq 0x30(%rsp), %r13
movq %r13, %rdi
pushq $0x12
popq %rsi
leaq 0xe82(%rip), %rdx       # 0x6004
movq %rbp, %rcx
callq 0x2180
movq 0x4e47(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
leaq 0x142f(%rip), %rsi      # 0x65ca
movq %r13, %rdx
movq 0x20(%rsp), %rcx
leaq 0xfd1(%rip), %r8        # 0x617b
movl (%rsp), %r9d
xorl %eax, %eax
callq 0x22e0
pushq $0x4
popq %rcx
movq %r15, %rdi
movl %ebx, %esi
leaq 0x2c(%rsp), %rdx
pushq $0xa
popq %r8
callq 0x3214
movl %eax, %ebp
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x21d0
leaq 0x60(%rsp), %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0x2100
leaq 0x30(%rsp), %r13
movq %r13, %rdi
pushq $0x12
popq %rsi
leaq 0xe08(%rip), %rdx       # 0x6004
movq %r15, %rcx
callq 0x2180
movq 0x4dcd(%rip), %rax      # 0x9fd8
movq (%rax), %rdi
leaq 0x13b5(%rip), %rsi      # 0x65ca
movq %r13, %rdx
movq 0x20(%rsp), %rcx
leaq 0xf57(%rip), %r8        # 0x617b
movl %ebp, %r9d
xorl %eax, %eax
callq 0x22e0
addq $0x40, %r14
movq %r14, %rdi
movl %ebx, %esi
movl 0x18(%rsp), %edx
callq 0x29c8
jmp 0x4f89
nop