// File: /workspace/github_cpp_makefile_star2_O3/tylerkaraszewski[P]Argyle/Server.cpp
// Function: Server::start()
bool Server::start()
{
  if (listen(m_mainSocket, 10))
  {
    m_logger.logError("Listen error(" + Utils::llToString(errno) + "): " + strerror(errno));
    close(m_mainSocket);
    return false;
  }

  initSocketList();

  while (m_shouldQuit == false)
  {
    int n = poll(m_sockets, m_socketCount, 1000);
    if (n == -1)
    {
      if (errno == EINTR)
      {
        // This happens when we try and exit. For a legit exit, m_shouldQuit should be set. For some other signal,
        // we'll just try and continue.
        continue;
      }
      m_logger.logError("Poll error(" + Utils::llToString(errno) + "): " + strerror(errno));
      close(m_mainSocket);
      return false;
    }
    // No socket activity, just start the next loop.
    if (n == 0)
    {
      continue;
    }

    int socketToWatch = -1;
    vector<int> socketsToUnwatch;
    for (int i = 0; i < m_socketCount; ++i)
    {
      // General error check.
      if (m_sockets[i].revents & POLLERR)
      {
        socketsToUnwatch.push_back(m_sockets[i].fd);
        continue;
      }
      if (m_sockets[i].revents & POLLHUP)
      {
        socketsToUnwatch.push_back(m_sockets[i].fd);
        continue;
      }
      if (m_sockets[i].revents & POLLNVAL)
      {
        socketsToUnwatch.push_back(m_sockets[i].fd);
        continue;
      }

      // Special socket.
      if (m_sockets[i].fd == m_mainSocket)
      {
        if (m_sockets[i].revents & POLLIN)
        {
          struct sockaddr_in newAddress;
          socklen_t newAddressSize = sizeof(newAddress);
          int newSocket = accept(m_mainSocket, (struct sockaddr*)&m_address, &newAddressSize);
          if (newSocket != -1)
          {
            socketToWatch = newSocket;
          }
          else
          {
            m_logger.logError("Accept error(" + Utils::llToString(errno) + "): " + strerror(errno));
          }
        }
      }
      else
      {
        bool isFinished = m_connections[m_sockets[i].fd]->process(m_sockets[i].events, m_sockets[i].revents);
        if (isFinished)
        {
          socketsToUnwatch.push_back(m_sockets[i].fd);
        }
      }
    }

    // @TODO: Timeout expiration goes here (or possibly after the 'unwatchSockets' call below).

    // Rebuild our socket list if anything has changed.
    unwatchSockets(socketsToUnwatch);
    watchSocket(socketToWatch);
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
movl (%rdi), %edi
movl $0xa, %esi
callq 0x32d0
testl %eax, %eax
je 0x4100
movq 0x58(%rbx), %r14
callq 0x3040
movq %rax, %r15
movslq (%rax), %rsi
leaq 0x88(%rsp), %r12
movq %r12, %rdi
callq 0xabbc
leaq 0x7f90(%rip), %rcx      # 0xc050
movl $0xd, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq 0x20(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x44a4
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x44ac
movq %rbx, %rdi
callq 0x4956
movb $0x1, %al
cmpb $0x0, 0x16(%rbx)
jne 0x45f3
leaq 0x18(%rbx), %r14
leaq 0x48(%rbx), %rax
movq %rax, 0xc0(%rsp)
leaq 0x70(%rsp), %r13
movq %r14, 0xb0(%rsp)
movq 0x8(%rbx), %rdi
movslq 0x10(%rbx), %rsi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x3410
testl %eax, %eax
je 0x4493
cmpl $-0x1, %eax
jne 0x4167
callq 0x3040
movslq (%rax), %rsi
cmpq $0x4, %rsi
je 0x4493
jmp 0x4605
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
cmpl $0x0, 0x10(%rbx)
jle 0x445a
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x8(%rbx), %rdx
movzwl 0x6(%rdx,%rbp), %eax
addq %rbp, %rdx
testb $0x8, %al
jne 0x4260
testb $0x10, %al
jne 0x4260
testb $0x20, %al
jne 0x4260
movl (%rdx), %edi
cmpl (%rbx), %edi
jne 0x429f
testb $0x1, %al
je 0x4286
movl $0x10, 0xac(%rsp)
movq 0xc0(%rsp), %rsi
leaq 0xac(%rsp), %rdx
callq 0x3100
cmpl $-0x1, %eax
jne 0x4451
movq 0x58(%rbx), %rax
movq %rax, 0xb8(%rsp)
callq 0x3040
movq %rax, %r14
movslq (%rax), %rsi
leaq 0x88(%rsp), %r12
movq %r12, %rdi
callq 0xabbc
movl $0xd, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
leaq 0x7e3e(%rip), %rcx      # 0xc06a
callq 0x32e0
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x42ea
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x42f0
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
je 0x427e
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x78(%rsp)
jmp 0x4286
movq %r13, %rdi
callq 0x4dfa
incq %r15
movslq 0x10(%rbx), %rax
addq $0x8, %rbp
cmpq %rax, %r15
jl 0x4192
jmp 0x4462
movq %r14, %rdi
movq %rdx, %rsi
callq 0x4d3a
movq (%rax), %rdi
movq 0x8(%rbx), %rax
leaq (%rax,%rbp), %rsi
addq $0x4, %rsi
leaq (%rax,%rbp), %rdx
addq $0x6, %rdx
callq 0x532e
testb %al, %al
je 0x4286
movq 0x8(%rbx), %rdx
addq %rbp, %rdx
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
jne 0x426f
movq %r13, %rdi
callq 0x4dfa
jmp 0x4286
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x10(%rsp), %rdi
leaq 0x7d1a(%rip), %rsi      # 0xc02e
callq 0x3560
leaq 0x40(%rsp), %rsi
movq %rsi, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4341
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x4347
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl (%r14), %edi
callq 0x3120
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x3560
leaq 0x60(%rsp), %rsi
movq %rsi, 0x50(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0x20(%rsp), %r14
je 0x43a1
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x43a7
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xb8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xabae
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x43ed
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4409
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x4420
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
movq 0xb0(%rsp), %r14
je 0x444d
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
movl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
jmp 0x4286
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4a02
movq %rbx, %rdi
movl 0xc(%rsp), %esi
callq 0x4b62
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x4493
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
cmpb $0x0, 0x16(%rbx)
je 0x4131
movb $0x1, %al
jmp 0x45f3
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x7b5f(%rip), %rsi      # 0xc02e
callq 0x3560
leaq 0x40(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x44fb
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x4502
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
leaq 0x30(%rsp), %r12
movq %rdx, 0x8(%r12)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl (%r15), %edi
callq 0x3120
movq %r12, %rdi
movq %rax, %rsi
callq 0x3560
leaq 0x60(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4559
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x4560
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x50(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0xabae
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x459b
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x45b2
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x45c9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x45ea
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
movl (%rbx), %edi
callq 0x3580
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq 0x58(%rbx), %r14
leaq 0x88(%rsp), %r12
movq %r12, %rdi
callq 0xabbc
leaq 0x7a3b(%rip), %rcx      # 0xc05e
movl $0xb, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x32e0
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x465d
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x4663
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x79a8(%rip), %rsi      # 0xc02e
callq 0x3560
leaq 0x40(%rsp), %rsi
movq %rsi, 0x30(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x46b3
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x46b9
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x30(%rsp), %r12
movq %rdx, 0x8(%r12)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl (%r15), %edi
callq 0x3120
movq %r12, %rdi
movq %rax, %rsi
callq 0x3560
leaq 0x60(%rsp), %rsi
movq %rsi, 0x50(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x4711
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x4717
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x50(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0xabae
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
leaq 0x20(%rsp), %r14
je 0x475c
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4778
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x478f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
jmp 0x45d5
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x47c8
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x47c8
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x47e9
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x47e9
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x480a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x480a
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
jmp 0x4918
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x4843
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4843
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4864
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4864
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4885
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4885
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x4933
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x4933
jmp 0x4930
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x48d4
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x48d4
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x48f0
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x48f0
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x490c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3290
jmp 0x490c
movq %rax, %rbx
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x494d
movq 0x98(%rsp), %rsi
incq %rsi
jmp 0x4948
jmp 0x4930
jmp 0x4930
jmp 0x4930
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x494d
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x3290
movq %rbx, %rdi
callq 0x3520
nop