// File: /workspace/github_cpp_makefile_star2_O1/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 $0xa8, %rsp
movq %rcx, %r13
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, %r14
movups 0x1496(%rip), %xmm0     # 0x6618
leaq 0x60(%rsp), %r8
movaps %xmm0, (%r8)
leaq 0x38(%rdi), %r15
movq %r15, %rdi
movq %rcx, %rdx
movl $0x8, %ecx
callq 0x3830
cmpl $0x8, %eax
jne 0x51cf
movl (%r13), %eax
movl 0x4(%r13), %r12d
bswapl %eax
bswapl %r12d
addl %eax, %r12d
leaq 0x8(%r13), %rdx
leaq 0x60(%rsp), %r8
movq %r15, %rdi
movl %ebx, %esi
movl %r12d, %ecx
callq 0x3830
cmpl %r12d, %eax
je 0x51f8
addq $0x40, %r14
movq %r14, %rdi
movl %ebx, %esi
callq 0x25f8
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0xa8, %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, 0x8(%rsp)
bswapl %ecx
movq %rcx, 0x18(%rsp)
leaq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x21d0
leaq 0x70(%rsp), %rsi
movq %r12, %rdi
movq %rsi, %r12
callq 0x2100
leaq 0xdd2(%rip), %rdx       # 0x6004
leaq 0x30(%rsp), %rdi
movl $0x12, %esi
movq %r12, %rcx
callq 0x2180
movq 0x3d8d(%rip), %rax      # 0x8fd8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
callq 0x21b0
movq %rax, 0x50(%rsp)
movl 0x8(%r13), %r10d
bswapl %r10d
leaq 0x136b(%rip), %rsi      # 0x65d6
leaq 0xf09(%rip), %r8        # 0x617b
xorl %r12d, %r12d
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %rax, %rcx
movq 0x8(%rsp), %r9
xorl %eax, %eax
pushq %r10
pushq 0x20(%rsp)
callq 0x22e0
addq $0x10, %rsp
movl %ebp, 0x20(%rsp)
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0x22a0
movq %rax, 0x18(%rsp)
leaq 0xc(%r13), %rsi
leaq -0x4(%rbp), %rdx
movq %rdx, 0x58(%rsp)
movq %rax, %rdi
callq 0x2190
leaq 0x30(%rsp), %rbp
movl $0x0, (%rbp)
xorl %edi, %edi
callq 0x21d0
movl 0x8(%r13), %ecx
bswapl %ecx
cqto
idivq %rcx
movl %eax, (%rbp)
leaq 0x30(%rsp), %rsi
movq 0x18(%rsp), %rbp
movq %rbp, %rdi
movq 0x58(%rsp), %rdx
callq 0x2190
leaq 0x70(%rsp), %r13
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0x2340
movq (%r13), %rbp
movzbl (%r13), %r13d
movq %r13, 0x8(%rsp)
movq 0x18(%rsp), %rdi
callq 0x2250
movq 0xf8(%r14), %rcx
movl %r13d, %eax
xorl %edx, %edx
idivl 0xec(%r14)
movq (%rcx,%rdx,8), %rdi
movq %rbp, %rsi
callq 0x3dc2
leaq 0x14(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0x21d0
leaq 0x70(%rsp), %rsi
movq %r13, %rdi
callq 0x2100
leaq 0x30(%rsp), %r13
movl $0x12, %esi
movq %r13, %rdi
leaq 0xc88(%rip), %rdx       # 0x6004
leaq 0x70(%rsp), %rcx
callq 0x2180
movq 0x3c4b(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x14(%rsp), %rax
movl (%rax), %r10d
leaq 0x11de(%rip), %rsi      # 0x657d
movq %r13, %rdx
movq 0x50(%rsp), %r13
movq %r13, %rcx
leaq 0xdca(%rip), %r8        # 0x617b
movq %rbp, %r9
xorl %eax, %eax
pushq %r10
pushq 0x10(%rsp)
callq 0x22e0
addq $0x10, %rsp
leaq 0xf4(%r14), %rdx
movq %r15, %rdi
movl %ebx, %esi
movl $0x1, %ecx
movl $0xa, %r8d
callq 0x38d8
movl %eax, 0x8(%rsp)
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
callq 0x21d0
leaq 0x70(%rsp), %rsi
movq %rbp, %rdi
callq 0x2100
leaq 0x30(%rsp), %rbp
movl $0x12, %esi
movq %rbp, %rdi
leaq 0xbf1(%rip), %rdx       # 0x6004
leaq 0x70(%rsp), %rcx
callq 0x2180
movq 0x3bb4(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x1188(%rip), %rsi      # 0x65b6
movq %rbp, %rdx
movq %r13, %rcx
leaq 0xd40(%rip), %r8        # 0x617b
movl 0x8(%rsp), %r9d
xorl %eax, %eax
callq 0x22e0
movq %r15, %rdi
movl %ebx, %esi
leaq 0x14(%rsp), %rdx
movl $0x4, %ecx
movl $0xa, %r8d
callq 0x38d8
movl %eax, 0x8(%rsp)
leaq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0x21d0
leaq 0x70(%rsp), %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0x2100
leaq 0x30(%rsp), %r13
movl $0x12, %esi
movq %r13, %rdi
leaq 0xb6e(%rip), %rdx       # 0x6004
movq %r15, %rcx
callq 0x2180
movq 0x3b33(%rip), %rax      # 0x8fd8
movq (%rax), %rdi
leaq 0x1107(%rip), %rsi      # 0x65b6
movq %r13, %rdx
movq 0x50(%rsp), %rcx
leaq 0xcbd(%rip), %r8        # 0x617b
movl 0x8(%rsp), %r9d
xorl %eax, %eax
callq 0x22e0
addq $0x40, %r14
movq %r14, %rdi
movl %ebx, %esi
movl 0x20(%rsp), %edx
callq 0x33da
jmp 0x51e3
nop