// File: /workspace/github_cpp_makefile_star2_O1/Neuromancer2701[P]OpenTool/lib/sockets/Server.cpp
// Function: Server::Available()
int Server::Available() {

	Client client;

	if(error_state == Error::NONE)
	{
		int epoll_events = epoll_wait (event_fd, events, MAX_EVENTS, -1);
		DEBUG("Epoll events, %d\n ",epoll_events);

		for (int i = 0; i < epoll_events; i++)
		{
			if((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || (!(events[i].events & EPOLLIN ))) /*Epoll error occured*/
			{
			  perror("epoll wait error\n");
			  error_state = Error::EPOLL_WAIT;
			  close (events[i].data.fd);

			}
			else if(server_fd == events[i].data.fd)
			{
				if(active_connections >= MAX_CONNECTIONS)
				{
					break;
				}

				while (error_state != Error::ACCEPT_DONE)
				{
					error_state = client_list[active_connections].Accept(server_fd);
					if(error_state == Error::NONE)
					{
						AddClientToEvent(client_list[active_connections]);
						active_connections++;
					}
				}
				error_state = Error::NONE;
			}
			else if(isClient(events[i].data.fd, client))
			{
				client.Read(read_buffer);
			}
			else
			{
				perror ("Unknown epoll event");
				error_state = Error::EPOLL_UNKNOWN;
			}
		}
	}
	else
	{
	  perror ("Setup did not work so can't wait for a connection.");
	}

	DEBUG("Active Connections:%d and Error State:%d\n", active_connections, error_state);
	return active_connections;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x6340
cmpl $0x2, 0x1b4(%rbx)
jne 0xa3d7
movl 0x1b8(%rbx), %edi
leaq 0x1c8(%rbx), %rsi
movq %rsi, -0x40(%rbp)
movl $0x10, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x6200
movl %eax, %r13d
leaq 0x113c(%rip), %rdi      # 0xb390
movl %eax, %esi
xorl %eax, %eax
callq 0x6060
testl %r13d, %r13d
jle 0xa3e3
leaq 0x190(%rbx), %rax
movq %rax, -0x30(%rbp)
leaq 0x10(%rbx), %r14
movl %r13d, %eax
movq %rax, -0x38(%rbp)
xorl %r12d, %r12d
movq 0x4d42(%rip), %r15      # 0xefc8
addq $0x10, %r15
leaq (%r12,%r12,2), %rax
movq -0x40(%rbp), %rcx
leaq (%rcx,%rax,4), %r13
movl (%r13), %eax
andl $0x19, %eax
cmpl $0x1, %eax
jne 0xa3a3
movl 0x4(%r13), %esi
cmpl %esi, 0x1a8(%rbx)
jne 0xa371
cmpl $0x5, 0x8(%rbx)
jg 0xa3e3
movl $0x2, %eax
cmpl $0x10, 0x1b4(%rbx)
je 0xa369
movslq 0x8(%rbx), %rdi
shlq $0x6, %rdi
addq %r14, %rdi
movl 0x1a8(%rbx), %esi
callq 0x66c0
movl %eax, 0x1b4(%rbx)
cmpl $0x2, %eax
jne 0xa357
movslq 0x8(%rbx), %r13
shlq $0x6, %r13
movq %r15, -0x80(%rbp)
movb 0x10(%r14,%r13), %al
leaq -0x78(%rbp), %rcx
movb %al, 0x8(%rcx)
movq 0x8(%r14,%r13), %rax
movq %rax, (%rcx)
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq 0x18(%r14,%r13), %rsi
movq 0x20(%r14,%r13), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x61c0
addq %r14, %r13
movzwl 0x38(%r13), %eax
movw %ax, -0x48(%rbp)
movq %rbx, %rdi
leaq -0x80(%rbp), %r13
movq %r13, %rsi
callq 0x6530
movq %r13, %rdi
callq 0x60e0
incl 0x8(%rbx)
cmpl $0x10, 0x1b4(%rbx)
jne 0xa2d2
movl $0x2, %eax
movl %eax, 0x1b4(%rbx)
jmp 0xa394
movq %rbx, %rdi
leaq -0xc0(%rbp), %rdx
callq 0x6390
testb %al, %al
je 0xa3c4
leaq -0xc0(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x6220
incq %r12
cmpq -0x38(%rbp), %r12
jne 0xa28a
jmp 0xa3e3
leaq 0xf29(%rip), %rdi       # 0xb2d3
callq 0x6370
movl $0xd, 0x1b4(%rbx)
movl 0x4(%r13), %edi
callq 0x6720
jmp 0xa394
leaq 0xfd8(%rip), %rdi       # 0xb3a3
callq 0x6370
movl $0xe, %eax
jmp 0xa369
leaq 0xfd9(%rip), %rdi       # 0xb3b7
callq 0x6370
movl 0x8(%rbx), %esi
movl 0x1b4(%rbx), %edx
leaq 0xff7(%rip), %rdi       # 0xb3ea
xorl %eax, %eax
callq 0x6060
movl 0x8(%rbx), %ebx
leaq -0xc0(%rbp), %rdi
callq 0x60e0
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa421
jmp 0xa421
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x60e0
movq %rbx, %rdi
callq 0x6680