// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
pushq $0x14
popq %rdi
callq 0xb540
andl $0x0, 0x10(%rax)
movq %rax, 0x40(%rbx)
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0xb0f0
movq 0x40(%rbx), %rcx
movl %eax, 0x10(%rcx)
cmpl $-0x1, %eax
je 0x4aded
xorl %r15d, %r15d
testq %r14, %r14
je 0x4ad83
cmpb $0x0, (%r14)
je 0x4ad83
movq %r14, %rdi
callq 0xb610
testq %rax, %rax
je 0x4af68
movq 0x40(%rbx), %rcx
jmp 0x4ad85
xorl %eax, %eax
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movq 0x40(%rbx), %rsi
movw $0x2, (%rsi)
testq %rax, %rax
je 0x4ada3
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %r15d
movl %r15d, 0x4(%rsi)
rolw $0x8, %bp
movw %bp, 0x2(%rsi)
movl 0x10(%rsi), %edi
pushq $0x10
popq %rdx
callq 0xb0a0
cmpl $-0x1, %eax
je 0x4ae7e
movq 0x40(%rbx), %rax
movl 0x10(%rax), %edi
pushq $0x10
popq %rsi
callq 0xb600
cmpl $-0x1, %eax
je 0x4aec7
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x49b3a
leaq 0x2a78c(%rip), %r14     # 0x75580
movq (%r14), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4af5b
addq $0x20, %rdi
callq 0xb800
movq (%r14), %rax
movq 0x18(%rax), %rdi
leaq 0x666f(%rip), %rsi      # 0x51488
callq 0xb520
leaq 0x9d8c(%rip), %rsi      # 0x54bb1
movq %rax, %rdi
callq 0xb520
leaq 0x9d8d(%rip), %rsi      # 0x54bc1
movq %rax, %rdi
callq 0xb520
movq %rax, %rbx
callq 0xb060
movl (%rax), %edi
callq 0xb180
movq %rbx, %rdi
movq %rax, %rsi
callq 0xb520
leaq 0x8506(%rip), %rsi      # 0x53363
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%r14), %rdi
addq $0x20, %rdi
callq 0xb3e0
jmp 0x4af5b
leaq 0x2a6fb(%rip), %r15     # 0x75580
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4af4f
addq $0x20, %rdi
callq 0xb800
movq (%r15), %rax
movq 0x18(%rax), %rdi
leaq 0x65de(%rip), %rsi      # 0x51488
callq 0xb520
leaq 0x9cfb(%rip), %rsi      # 0x54bb1
movq %rax, %rdi
callq 0xb520
leaq 0x9d41(%rip), %rsi      # 0x54c06
jmp 0x4af0a
leaq 0x2a6b2(%rip), %r15     # 0x75580
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4af4f
addq $0x20, %rdi
callq 0xb800
movq (%r15), %rax
movq 0x18(%rax), %rdi
leaq 0x6599(%rip), %rsi      # 0x51488
callq 0xb520
leaq 0x9cb6(%rip), %rsi      # 0x54bb1
movq %rax, %rdi
callq 0xb520
leaq 0x9d22(%rip), %rsi      # 0x54c2c
movq %rax, %rdi
callq 0xb520
movq %rax, %r14
callq 0xb060
movl (%rax), %edi
callq 0xb180
movq %r14, %rdi
movq %rax, %rsi
callq 0xb520
leaq 0x8430(%rip), %rsi      # 0x53363
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%r15), %rdi
addq $0x20, %rdi
callq 0xb3e0
movq 0x40(%rbx), %rax
movl 0x10(%rax), %edi
callq 0xbaa0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2a611(%rip), %r14     # 0x75580
movq (%r14), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4af5b
addq $0x20, %rdi
callq 0xb800
movq (%r14), %rax
movq 0x18(%rax), %rdi
leaq 0x64f8(%rip), %rsi      # 0x51488
callq 0xb520
leaq 0x9c15(%rip), %rsi      # 0x54bb1
movq %rax, %rdi
callq 0xb520
leaq 0x9c3d(%rip), %rsi      # 0x54be8
movq %rax, %rdi
callq 0xb520
movq %rax, %rbx
callq 0xb8a0
jmp 0x4ae44