// File: /workspace/github_cpp_makefile_star2_O3/SeTriones[P]Anubis/receiver.cpp
// Function: receiver::svc()
int receiver::svc() {
	int local_epoll_idx = 0;
	pthread_mutex_lock(&epoll_idx_mutex);
	local_epoll_idx = epoll_thread_cnt;
	epoll_thread_cnt++;
	pthread_mutex_unlock(&epoll_idx_mutex);
	local_epoll_idx = local_epoll_idx % epoll_cnt;

	int epoll_fd = epoll_fds[local_epoll_idx];
	epoll_event* es = epoll_ready_events[local_epoll_idx];
	pthread_mutex_t* epoll_mutex = &epoll_mutexes[local_epoll_idx];
	int* event_num = &epoll_ready_event_num[local_epoll_idx];

	char* recv_buf = (char*)malloc(max_recv_buf_len);
	int fd, new_fd;
	int tmp_conn;
	sockaddr_in sa;
	socklen_t len;

	while (!stop_task) {
		pthread_mutex_lock(epoll_mutex);
		if (stop_task) {
			pthread_mutex_unlock(epoll_mutex);
			break;
		}

		if ((*event_num) <= 0) {
			*event_num = epoll_wait(epoll_fd, es, max_conn, -1);
		}
		if ((*event_num)-- < 0) {
			pthread_mutex_unlock(epoll_mutex);
			if (errno == EINTR) {
				continue;
			}
			else {
				break;
			}
		}

		fd = es[(*event_num)].data.fd;

		if (fd == listen_fd) {
			del_input_fd(fd, epoll_fd);
			pthread_mutex_unlock(epoll_mutex);
			while ((new_fd = accept(fd, NULL, NULL)) >= 0) {
				pthread_mutex_lock(&conn_mutex);
				conn_num++;
				tmp_conn = conn_num;
				pthread_mutex_unlock(&conn_mutex);
				len = sizeof(sa);
				getpeername(new_fd, (struct sockaddr *)&sa, &len);
				set_socket(new_fd, O_NONBLOCK);
				add_input_fd(new_fd, epoll_fds[incoming_fd_cnt % epoll_cnt]);
				_INFO("new conn on %s:%d,fd=%d,conn_num=%d,epollno=%d", inet_ntoa(sa.sin_addr), ntohs(sa.sin_port), new_fd, tmp_conn, incoming_fd_cnt % epoll_cnt);
				incoming_fd_cnt++;
			}
			add_input_fd(fd, epoll_fd);
		} else if (fd == pipe_read_fds[local_epoll_idx]) {
			_INFO("get a stop signal");
			pthread_mutex_unlock(epoll_mutex);
			continue;
		} else {
			del_input_fd(fd, epoll_fd);
			pthread_mutex_unlock(epoll_mutex);
			handle_request(fd, epoll_fd, recv_buf);
		}
	}

	free(recv_buf);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
leaq 0x98(%rdi), %r14
movq %r14, %rdi
callq 0x2320
movl 0xe0(%rbx), %r15d
leal 0x1(%r15), %eax
movl %eax, 0xe0(%rbx)
movq %r14, %rdi
callq 0x2170
movl %r15d, %eax
cltd
idivl 0x44(%rbx)
movslq %edx, %r14
movq 0x50(%rbx), %rax
movq 0xc0(%rbx), %rcx
movl (%rax,%r14,4), %ebp
movq (%rcx,%r14,8), %r13
leaq (%r14,%r14,4), %r12
shlq $0x3, %r12
addq 0x68(%rbx), %r12
movq 0xc8(%rbx), %r15
movl $0x100000, %edi         # imm = 0x100000
callq 0x22b0
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x58(%rbx)
jne 0x4dcd
movq %r12, %rdi
callq 0x2320
cmpl $0x0, 0x58(%rbx)
je 0x4deb
movq %r12, %rdi
callq 0x2170
movq 0x18(%rsp), %rdi
callq 0x2260
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x70(%rbx), %rax
movq %rax, 0x38(%rsp)
movq %r14, 0x30(%rsp)
movq %r12, 0x28(%rsp)
movl %ebp, 0x10(%rsp)
movq %r13, 0x20(%rsp)
movq %r15, 0x40(%rsp)
movl (%r15,%r14,4), %ecx
testl %ecx, %ecx
jle 0x4e25
decl %ecx
movl %ecx, (%r15,%r14,4)
jmp 0x4e4a
movq 0x8(%rsp), %rax
movl (%rax), %edx
movl %ebp, %edi
movq %r13, %rsi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x20f0
leal -0x1(%rax), %ecx
movl %ecx, (%r15,%r14,4)
testl %eax, %eax
js 0x5037
movslq %ecx, %rax
leaq (%rax,%rax,2), %rax
movl 0x4(%r13,%rax,4), %r15d
cmpl 0x4c(%rbx), %r15d
jne 0x4fdb
movq 0x8(%rsp), %r13
movq %r13, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x3676
movq %r12, %rdi
callq 0x2170
movl %r15d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20a0
testl %eax, %eax
js 0x4fb9
movl %eax, %r12d
movq 0x38(%rsp), %rbp
movq %rbp, %rdi
callq 0x2320
movl 0x5c(%rbx), %r14d
incl %r14d
movl %r14d, 0x5c(%rbx)
movq %rbp, %rdi
callq 0x2170
movl $0x10, 0x14(%rsp)
movl %r12d, %edi
leaq 0x48(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0x2160
movq %r13, %rdi
movl %r12d, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x35ae
movq 0x50(%rbx), %rcx
movl 0xe4(%rbx), %eax
cltd
idivl 0x44(%rbx)
movslq %edx, %rax
movl (%rcx,%rax,4), %edx
movq %r13, %rdi
movl %r12d, %esi
callq 0x34e6
leaq 0x58(%rsp), %r13
movq %r13, %rdi
callq 0x21e0
movq %r13, %rdi
leaq 0x80(%rsp), %r13
movq %r13, %rsi
callq 0x2100
movl $0x12, %esi
leaq 0x60(%rsp), %rdi
leaq 0x10d9(%rip), %rdx      # 0x6004
movq %r13, %rcx
callq 0x2190
movq 0x409e(%rip), %rax      # 0x8fd8
movq (%rax), %rbp
callq 0x21c0
movq %rax, %r13
movl 0x4c(%rsp), %edi
callq 0x20e0
movzwl 0x4a(%rsp), %ecx
rolw $0x8, %cx
movq %rax, %r9
movzwl %cx, %r11d
movl 0xe4(%rbx), %eax
cltd
idivl 0x44(%rbx)
movl %edx, %r10d
movq %rbp, %rdi
leaq 0x1579(%rip), %rsi      # 0x64ee
leaq 0x60(%rsp), %rdx
movq %r13, %rcx
movq 0x8(%rsp), %r13
leaq 0x11f2(%rip), %r8       # 0x617b
xorl %eax, %eax
pushq %r10
pushq %r14
pushq %r12
pushq %r11
callq 0x22f0
addq $0x20, %rsp
incl 0xe4(%rbx)
movl %r15d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20a0
movl %eax, %r12d
testl %eax, %eax
jns 0x4e91
movq %r13, %rdi
movl %r15d, %esi
movl 0x10(%rsp), %ebp
movl %ebp, %edx
callq 0x34e6
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r12
movq 0x20(%rsp), %r13
jmp 0x5011
movq 0xd0(%rbx), %rax
cmpl (%rax,%r14,4), %r15d
je 0x5058
movq 0x8(%rsp), %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x3676
movq %r12, %rdi
callq 0x2170
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
movq 0x18(%rsp), %rcx
callq 0x5062
cmpl $0x0, 0x58(%rbx)
movq 0x40(%rsp), %r15
jne 0x4dcd
movq %r12, %rdi
callq 0x2320
cmpl $0x0, 0x58(%rbx)
je 0x4e15
jmp 0x4dc5
movq %r12, %rdi
callq 0x2170
callq 0x2040
cmpl $0x4, (%rax)
jne 0x4dcd
cmpl $0x0, 0x58(%rbx)
je 0x5020
jmp 0x4dcd
movq %r12, %rdi
callq 0x3012
jmp 0x5011