// File: tylerkaraszewski[P]Argyle/Server.cpp
// Function: Server::bindPort()
bool Server::bindPort()
{
  m_mainSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (m_mainSocket == -1)
  {
    m_logger.logError("Socket error(" + Utils::llToString(errno) + "): " + strerror(errno));
    return false;
  }

  int reuseAddr = 1;
  if (setsockopt(m_mainSocket, SOL_SOCKET, SO_REUSEADDR, (char*)&reuseAddr, sizeof(reuseAddr)))
  {
    m_logger.logError("Setsockopt error(" + Utils::llToString(errno) + "): " + strerror(errno));
    close(m_mainSocket);
    return false;
  }
  
  if (bind(m_mainSocket, (struct sockaddr*)&m_address, sizeof(m_address)))
  {
    m_logger.logError("Bind error(" + Utils::llToString(errno) + "): " + strerror(errno));
    close(m_mainSocket);
    return false;
  }
  return true;
}

// Assembly:
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, 0x1c8(%rsp)
movq 0x1c8(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x40f0
movl %eax, %ecx
movq 0x30(%rsp), %rax
movl %ecx, (%rax)
cmpl $-0x1, (%rax)
jne 0x50ad
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x20(%rsp)
callq 0x4060
movslq (%rax), %rsi
leaq 0x148(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x10f70
movq 0x28(%rsp), %rdx
leaq 0xe08e(%rip), %rsi      # 0x13004
leaq 0x168(%rsp), %rdi
callq 0x6230
jmp 0x4f85
leaq 0xe086(%rip), %rdx      # 0x13012
leaq 0x188(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x61e0
jmp 0x4fa3
callq 0x4060
movl (%rax), %edi
callq 0x4150
movq %rax, %rdx
leaq 0x1a8(%rsp), %rdi
leaq 0x188(%rsp), %rsi
callq 0x61e0
jmp 0x4fc9
movq 0x20(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x10f40
jmp 0x4fdd
leaq 0x1a8(%rsp), %rdi
callq 0x4788
leaq 0x188(%rsp), %rdi
callq 0x4788
leaq 0x168(%rsp), %rdi
callq 0x4788
leaq 0x148(%rsp), %rdi
callq 0x4788
movb $0x0, 0x1d7(%rsp)
jmp 0x53d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x509b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x508e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x5081
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
leaq 0x1a8(%rsp), %rdi
callq 0x4788
leaq 0x188(%rsp), %rdi
callq 0x4788
leaq 0x168(%rsp), %rdi
callq 0x4788
leaq 0x148(%rsp), %rdi
callq 0x4788
jmp 0x53e4
movq 0x30(%rsp), %rax
movl $0x1, 0x138(%rsp)
movl (%rax), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq 0x138(%rsp), %rcx
movl $0x4, %r8d
callq 0x46d0
cmpl $0x0, %eax
je 0x525c
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x4060
movslq (%rax), %rsi
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x10f70
movq 0x18(%rsp), %rdx
leaq 0xdefd(%rip), %rsi      # 0x13016
leaq 0xd8(%rsp), %rdi
callq 0x6230
jmp 0x5128
leaq 0xdee3(%rip), %rdx      # 0x13012
leaq 0xf8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x61e0
jmp 0x5146
callq 0x4060
movl (%rax), %edi
callq 0x4150
movq %rax, %rdx
leaq 0x118(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x61e0
jmp 0x516c
movq 0x10(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x10f40
jmp 0x5180
leaq 0x118(%rsp), %rdi
callq 0x4788
leaq 0xf8(%rsp), %rdi
callq 0x4788
leaq 0xd8(%rsp), %rdi
callq 0x4788
leaq 0xb8(%rsp), %rdi
callq 0x4788
movq 0x30(%rsp), %rax
movl (%rax), %edi
callq 0x4750
movb $0x0, 0x1d7(%rsp)
jmp 0x53d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x524a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x523d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x5230
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x4788
leaq 0xf8(%rsp), %rdi
callq 0x4788
leaq 0xd8(%rsp), %rdi
callq 0x4788
leaq 0xb8(%rsp), %rdi
callq 0x4788
jmp 0x53e4
movq 0x30(%rsp), %rsi
movl (%rsi), %edi
addq $0x48, %rsi
movl $0x10, %edx
callq 0x40c0
cmpl $0x0, %eax
je 0x53cb
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movq %rax, (%rsp)
callq 0x4060
movslq (%rax), %rsi
leaq 0x38(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x10f70
movq 0x8(%rsp), %rdx
leaq 0xdd7e(%rip), %rsi      # 0x13028
leaq 0x58(%rsp), %rdi
callq 0x6230
jmp 0x52b6
leaq 0xdd55(%rip), %rdx      # 0x13012
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x61e0
jmp 0x52ce
callq 0x4060
movl (%rax), %edi
callq 0x4150
movq %rax, %rdx
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x61e0
jmp 0x52f1
movq (%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x10f40
jmp 0x5304
leaq 0x98(%rsp), %rdi
callq 0x4788
leaq 0x78(%rsp), %rdi
callq 0x4788
leaq 0x58(%rsp), %rdi
callq 0x4788
leaq 0x38(%rsp), %rdi
callq 0x4788
movq 0x30(%rsp), %rax
movl (%rax), %edi
callq 0x4750
movb $0x0, 0x1d7(%rsp)
jmp 0x53d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x53bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x53b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x53ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x4788
leaq 0x78(%rsp), %rdi
callq 0x4788
leaq 0x58(%rsp), %rdi
callq 0x4788
leaq 0x38(%rsp), %rdi
callq 0x4788
jmp 0x53e4
movb $0x1, 0x1d7(%rsp)
movb 0x1d7(%rsp), %al
andb $0x1, %al
addq $0x1d8, %rsp            # imm = 0x1D8
retq
movq 0x140(%rsp), %rdi
callq 0x46b0
nopw %cs:(%rax,%rax)