// File: /workspace/github_cpp_makefile_star2_O1/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 0x2310
movl 0xe0(%rbx), %r15d
leal 0x1(%r15), %eax
movl %eax, 0xe0(%rbx)
movq %r14, %rdi
callq 0x2160
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), %r15
shlq $0x3, %r15
addq 0x68(%rbx), %r15
movq 0xc8(%rbx), %r12
movl $0x100000, %edi         # imm = 0x100000
callq 0x22a0
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x58(%rbx)
jne 0x4ecd
movq %r15, %rdi
callq 0x2310
cmpl $0x0, 0x58(%rbx)
je 0x4eeb
movq %r15, %rdi
callq 0x2160
movq 0x18(%rsp), %rdi
callq 0x2250
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 %r15, 0x28(%rsp)
movl %ebp, 0x10(%rsp)
movq %r13, 0x20(%rsp)
movq %r12, 0x40(%rsp)
cmpl $0x0, (%r12,%r14,4)
jg 0x4f36
movq 0x8(%rsp), %rax
movl (%rax), %edx
movl %ebp, %edi
movq %r13, %rsi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x20f0
movl %eax, (%r12,%r14,4)
movslq (%r12,%r14,4), %rcx
leaq -0x1(%rcx), %rax
movl %eax, (%r12,%r14,4)
testq %rcx, %rcx
js 0x50d9
leaq (%rax,%rax,2), %rax
movl 0x4(%r13,%rax,4), %r12d
cmpl 0x4c(%rbx), %r12d
jne 0x50fa
movq 0x8(%rsp), %r13
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x3568
movq %r15, %rdi
callq 0x2160
movl %r12d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20a0
testl %eax, %eax
js 0x50b7
movl %eax, %r15d
movq 0x38(%rsp), %rbp
movq %rbp, %rdi
callq 0x2310
movl 0x5c(%rbx), %r14d
incl %r14d
movl %r14d, 0x5c(%rbx)
movq %rbp, %rdi
callq 0x2160
movl $0x10, 0x14(%rsp)
movl %r15d, %edi
leaq 0x48(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0x2150
movq %r13, %rdi
movl %r15d, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x34a0
movq 0x50(%rbx), %rcx
movl 0xe4(%rbx), %eax
cltd
idivl 0x44(%rbx)
movslq %edx, %rax
movl (%rcx,%rax,4), %edx
movq %r13, %rdi
movl %r15d, %esi
callq 0x33da
leaq 0x58(%rsp), %r13
movq %r13, %rdi
callq 0x21d0
movq %r13, %rdi
leaq 0x80(%rsp), %r13
movq %r13, %rsi
callq 0x2100
movl $0x12, %esi
leaq 0x60(%rsp), %rdi
leaq 0xfdb(%rip), %rdx       # 0x6004
movq %r13, %rcx
callq 0x2180
movq 0x3fa0(%rip), %rax      # 0x8fd8
movq (%rax), %rbp
callq 0x21b0
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 0x1463(%rip), %rsi      # 0x64d6
leaq 0x60(%rsp), %rdx
movq %r13, %rcx
movq 0x8(%rsp), %r13
leaq 0x10f4(%rip), %r8       # 0x617b
xorl %eax, %eax
pushq %r10
pushq %r14
pushq %r15
pushq %r11
callq 0x22e0
addq $0x20, %rsp
incl 0xe4(%rbx)
movl %r12d, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x20a0
movl %eax, %r15d
testl %eax, %eax
jns 0x4f8f
movq %r13, %rdi
movl %r12d, %esi
movl 0x10(%rsp), %ebp
movl %ebp, %edx
callq 0x33da
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %r13
jmp 0x5130
movq %r15, %rdi
callq 0x2160
callq 0x2040
cmpl $0x4, (%rax)
jne 0x4ecd
cmpl $0x0, 0x58(%rbx)
je 0x513f
jmp 0x4ecd
movq 0xd0(%rbx), %rax
cmpl (%rax,%r14,4), %r12d
je 0x5156
movq 0x8(%rsp), %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x3568
movq %r15, %rdi
callq 0x2160
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
movq 0x18(%rsp), %rcx
callq 0x5160
cmpl $0x0, 0x58(%rbx)
movq 0x40(%rsp), %r12
jne 0x4ecd
movq %r15, %rdi
callq 0x2310
cmpl $0x0, 0x58(%rbx)
je 0x4f15
jmp 0x4ec5
movq %r15, %rdi
callq 0x2efc
jmp 0x5130