// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl $0x14, %edi
callq 0xb500
movl $0x0, 0x10(%rax)
movq %rax, 0x40(%rbx)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0xb0f0
movq 0x40(%rbx), %rcx
movl %eax, 0x10(%rcx)
cmpl $-0x1, %eax
je 0x60eb1
testq %r14, %r14
je 0x60e53
cmpb $0x0, (%r14)
je 0x60e53
movq %r14, %rdi
callq 0xb5e0
testq %rax, %rax
je 0x6109b
movq 0x40(%rbx), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movq 0x40(%rbx), %rsi
movw $0x2, (%rsi)
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x4(%rsi)
jmp 0x60e69
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movq 0x40(%rbx), %rsi
movw $0x2, (%rsi)
movl $0x0, 0x4(%rsi)
rolw $0x8, %bp
movw %bp, 0x2(%rsi)
movl 0x10(%rsi), %edi
movl $0x10, %edx
callq 0xb0b0
cmpl $-0x1, %eax
je 0x60f45
movq 0x40(%rbx), %rax
movl 0x10(%rax), %edi
movl $0x10, %esi
callq 0xb5c0
cmpl $-0x1, %eax
je 0x60fa2
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x5fb34
leaq 0x2b6b8(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x61172
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq 0x18(%rax), %rbx
leaq 0x95cb(%rip), %rsi      # 0x6a4a8
movl $0xc, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xcd30(%rip), %rsi      # 0x6dc21
movl $0xf, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xcd2c(%rip), %rsi      # 0x6dc31
movl $0x26, %edx
movq %rbx, %rdi
callq 0xb5f0
callq 0xb070
movl (%rax), %edi
callq 0xb190
testq %rax, %rax
je 0x61038
movq %rax, %r14
movq %rax, %rdi
callq 0xb200
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0xb5f0
jmp 0x6104f
leaq 0x2b624(%rip), %r12     # 0x8c570
movq (%r12), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x61166
addq $0x20, %rdi
callq 0xb7d0
movq (%r12), %rax
movq 0x18(%rax), %r14
leaq 0x9535(%rip), %rsi      # 0x6a4a8
movl $0xc, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xcc9a(%rip), %rsi      # 0x6dc21
movl $0xf, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xccdb(%rip), %rsi      # 0x6dc76
movl $0x25, %edx
jmp 0x60ffd
leaq 0x2b5c7(%rip), %r12     # 0x8c570
movq (%r12), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x61166
addq $0x20, %rdi
callq 0xb7d0
movq (%r12), %rax
movq 0x18(%rax), %r14
leaq 0x94d8(%rip), %rsi      # 0x6a4a8
movl $0xc, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xcc3d(%rip), %rsi      # 0x6dc21
movl $0xf, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xcca4(%rip), %rsi      # 0x6dc9c
movl $0x24, %edx
movq %r14, %rdi
callq 0xb5f0
callq 0xb070
movl (%rax), %edi
callq 0xb190
testq %rax, %rax
je 0x61106
movq %rax, %r15
movq %rax, %rdi
callq 0xb200
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0xb5f0
jmp 0x6111e
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0xb990
leaq 0xb37d(%rip), %rsi      # 0x6c3d3
movl $0x1, %edx
movq %rbx, %rdi
callq 0xb5f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0xb4d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0xb050
movq %rax, %rdi
callq 0xb340
movq (%r15), %rdi
addq $0x20, %rdi
callq 0xb3b0
jmp 0x61172
leaq 0x2b4ce(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x61172
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq 0x18(%rax), %rbx
leaq 0x93e1(%rip), %rsi      # 0x6a4a8
movl $0xc, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xcb46(%rip), %rsi      # 0x6dc21
movl $0xf, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xcb69(%rip), %rsi      # 0x6dc58
movl $0x1d, %edx
movq %rbx, %rdi
callq 0xb5f0
callq 0xb890
jmp 0x60f17
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0xb990
leaq 0xb2ae(%rip), %rsi      # 0x6c3d3
movl $0x1, %edx
movq %r14, %rdi
callq 0xb5f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0xb4d0
movsbl %al, %esi
movq %r14, %rdi
callq 0xb050
movq %rax, %rdi
callq 0xb340
movq (%r12), %rdi
addq $0x20, %rdi
callq 0xb3b0
movq 0x40(%rbx), %rax
movl 0x10(%rax), %edi
callq 0xbaa0
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop