// File: mh0fm4[P]SCDC/src/components/transport/transport_tcp.cc
// Function: scdc_transport_tcp::open(char const*, int)
bool scdc_transport_tcp::open(const char *address, int port)
{
  SCDC_TRACE("open: address: '" << ((address && address[0] != '\0')?address:"<ANY>") << "', port: " << port);

  tcp_server = new scdc_transport_tcp_server_t();

  tcp_server->server_socket = ::socket(AF_INET, SOCK_STREAM, 0);
  if (tcp_server->server_socket == -1)
  {
    SCDC_ERROR("open: creating server socket failed: '" << strerror(errno) << "'");
    return false;
  }

  struct hostent *h = 0;

  if (address && address[0] != '\0')
  {
    h = gethostbyname(address);

    if (!h)
    {
      SCDC_ERROR("open: gethostbyname failed: '" << strerror(h_errno) << "'");
      return false;
    }
  }

  memset(&tcp_server->saddr, 0, sizeof(tcp_server->saddr));

  tcp_server->saddr.sin_family = AF_INET;
  if (h) tcp_server->saddr.sin_addr = *((struct in_addr **) h->h_addr_list)[0];
  else tcp_server->saddr.sin_addr.s_addr = htonl(INADDR_ANY);
  tcp_server->saddr.sin_port = htons(port);

  if (::bind(tcp_server->server_socket, (struct sockaddr *) &tcp_server->saddr, sizeof(tcp_server->saddr)) == -1)
  {
    SCDC_ERROR("open: binding server socket failed: '" << strerror(errno) << "'");
    ::close(tcp_server->server_socket);
    return false;
  }

  if (::listen(tcp_server->server_socket, TRANSPORT_TCP_LISTEN_BACKLOG) == -1)
  {
    SCDC_ERROR("open: listen server socket failed: '" << strerror(errno) << "'");
    ::close(tcp_server->server_socket);
    return false;
  }

  return scdc_transport::open();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x9b40d
movl $0x14, %edi
callq 0xc690
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x48(%rbp)
callq 0x9c340
jmp 0x9b428
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
movq %rcx, 0x40(%rax)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0xc130
movl %eax, %edx
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rcx
movl %edx, 0x10(%rcx)
movq 0x40(%rax), %rax
cmpl $-0x1, 0x10(%rax)
jne 0x9b53b
jmp 0x9b462
leaq 0x3923f(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
cmpq $0x0, %rax
je 0x9b530
leaq 0x39226(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e900
leaq 0x39217(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
movq %rax, %rdi
leaq 0xb005(%rip), %rsi      # 0xa64a8
callq 0xc670
movq %rax, %rdi
leaq 0xe747(%rip), %rsi      # 0xa9bf9
callq 0xc670
movq %rax, %rdi
leaq 0xe748(%rip), %rsi      # 0xa9c09
callq 0xc670
movq %rax, -0x50(%rbp)
callq 0xc080
movl (%rax), %edi
callq 0xc1d0
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0xc670
movq %rax, %rdi
leaq 0xcee7(%rip), %rsi      # 0xa83d3
callq 0xc670
movq %rax, %rdi
movq 0x38ac5(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x391a1(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e920
jmp 0x9b530
movq -0x48(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x14, %esi
callq 0xc6a0
jmp 0x9b888
jmp 0x9b532
movb $0x0, -0x1(%rbp)
jmp 0x9b87d
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x9b632
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x9b632
movq -0x18(%rbp), %rdi
callq 0xc7c0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x9b630
jmp 0x9b578
leaq 0x39129(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
cmpq $0x0, %rax
je 0x9b625
leaq 0x39110(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e900
leaq 0x39101(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
movq %rax, %rdi
leaq 0xaeef(%rip), %rsi      # 0xa64a8
callq 0xc670
movq %rax, %rdi
leaq 0xe631(%rip), %rsi      # 0xa9bf9
callq 0xc670
movq %rax, %rdi
leaq 0xe659(%rip), %rsi      # 0xa9c30
callq 0xc670
movq %rax, -0x58(%rbp)
callq 0xca90
movl (%rax), %edi
callq 0xc1d0
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0xc670
movq %rax, %rdi
leaq 0xcdd1(%rip), %rsi      # 0xa83d3
callq 0xc670
movq %rax, %rdi
movq 0x389af(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x3908b(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e920
jmp 0x9b627
movb $0x0, -0x1(%rbp)
jmp 0x9b87d
jmp 0x9b632
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xc350
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movw $0x2, (%rax)
cmpq $0x0, -0x38(%rbp)
je 0x9b674
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq (%rcx), %rcx
movq 0x40(%rax), %rax
movl (%rcx), %ecx
movl %ecx, 0x4(%rax)
jmp 0x9b688
xorl %edi, %edi
callq 0xc4d0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movl %ecx, 0x4(%rax)
movl -0x1c(%rbp), %eax
movzwl %ax, %edi
callq 0xc090
movw %ax, %dx
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rcx
movw %dx, 0x2(%rcx)
movq 0x40(%rax), %rcx
movl 0x10(%rcx), %edi
movq 0x40(%rax), %rsi
movl $0x10, %edx
callq 0xc0c0
cmpl $-0x1, %eax
jne 0x9b78a
jmp 0x9b6c2
leaq 0x38fdf(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
cmpq $0x0, %rax
je 0x9b76f
leaq 0x38fc6(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e900
leaq 0x38fb7(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
movq %rax, %rdi
leaq 0xada5(%rip), %rsi      # 0xa64a8
callq 0xc670
movq %rax, %rdi
leaq 0xe4e7(%rip), %rsi      # 0xa9bf9
callq 0xc670
movq %rax, %rdi
leaq 0xe52d(%rip), %rsi      # 0xa9c4e
callq 0xc670
movq %rax, -0x60(%rbp)
callq 0xc080
movl (%rax), %edi
callq 0xc1d0
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0xc670
movq %rax, %rdi
leaq 0xcc87(%rip), %rsi      # 0xa83d3
callq 0xc670
movq %rax, %rdi
movq 0x38865(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x38f41(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e920
jmp 0x9b771
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x10(%rax), %edi
callq 0xccd0
movb $0x0, -0x1(%rbp)
jmp 0x9b87d
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x10(%rax), %edi
movl $0x10, %esi
callq 0xc7b0
cmpl $-0x1, %eax
jne 0x9b86f
jmp 0x9b7aa
leaq 0x38ef7(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
cmpq $0x0, %rax
je 0x9b857
leaq 0x38ede(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e900
leaq 0x38ecf(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
movq %rax, %rdi
leaq 0xacbd(%rip), %rsi      # 0xa64a8
callq 0xc670
movq %rax, %rdi
leaq 0xe3ff(%rip), %rsi      # 0xa9bf9
callq 0xc670
movq %rax, %rdi
leaq 0xe46b(%rip), %rsi      # 0xa9c74
callq 0xc670
movq %rax, -0x68(%rbp)
callq 0xc080
movl (%rax), %edi
callq 0xc1d0
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0xc670
movq %rax, %rdi
leaq 0xcb9f(%rip), %rsi      # 0xa83d3
callq 0xc670
movq %rax, %rdi
movq 0x3877d(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x38e59(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e920
jmp 0x9b859
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movl 0x10(%rax), %edi
callq 0xccd0
movb $0x0, -0x1(%rbp)
jmp 0x9b87d
movq -0x40(%rbp), %rdi
callq 0x98640
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0xcba0
nopw %cs:(%rax,%rax)