// File: /workspace/github_cpp_makefile_star2_O1/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 0x61384
testq %r14, %r14
je 0x61355
cmpb $0x0, (%r14)
je 0x61355
movq %r14, %rdi
callq 0xb5e0
testq %rax, %rax
jne 0x61357
leaq 0x2b27f(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x61617
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq 0x18(%rax), %rbx
leaq 0x9172(%rip), %rsi      # 0x6a488
movl $0xc, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc887(%rip), %rsi      # 0x6dbb1
movl $0xf, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc8aa(%rip), %rsi      # 0x6dbe8
movl $0x1d, %edx
movq %rbx, %rdi
callq 0xb5f0
callq 0xb890
jmp 0x613ea
xorl %eax, %eax
movq 0x40(%rbx), %rcx
xorps %xmm0, %xmm0
movups %xmm0, (%rcx)
movq 0x40(%rbx), %rsi
movw $0x2, (%rsi)
testq %rax, %rax
je 0x61418
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x4(%rsi)
jmp 0x6141f
leaq 0x2b1e5(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x61617
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq 0x18(%rax), %rbx
leaq 0x90d8(%rip), %rsi      # 0x6a488
movl $0xc, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc7ed(%rip), %rsi      # 0x6dbb1
movl $0xf, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc7e9(%rip), %rsi      # 0x6dbc1
movl $0x26, %edx
movq %rbx, %rdi
callq 0xb5f0
callq 0xb070
movl (%rax), %edi
callq 0xb190
testq %rax, %rax
je 0x6154b
movq %rax, %r14
movq %rax, %rdi
callq 0xb200
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0xb5f0
jmp 0x61562
movl $0x0, 0x4(%rsi)
rolw $0x8, %bp
movw %bp, 0x2(%rsi)
movl 0x10(%rsi), %edi
movl $0x10, %edx
callq 0xb0b0
cmpl $-0x1, %eax
je 0x6145f
movq 0x40(%rbx), %rax
movl 0x10(%rax), %edi
movl $0x10, %esi
callq 0xb5c0
cmpl $-0x1, %eax
je 0x614bc
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x60022
leaq 0x2b10a(%rip), %r12     # 0x8c570
movq (%r12), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x6160b
addq $0x20, %rdi
callq 0xb7d0
movq (%r12), %rax
movq 0x18(%rax), %r14
leaq 0x8ffb(%rip), %rsi      # 0x6a488
movl $0xc, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xc710(%rip), %rsi      # 0x6dbb1
movl $0xf, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xc751(%rip), %rsi      # 0x6dc06
movl $0x25, %edx
jmp 0x61517
leaq 0x2b0ad(%rip), %r12     # 0x8c570
movq (%r12), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x6160b
addq $0x20, %rdi
callq 0xb7d0
movq (%r12), %rax
movq 0x18(%rax), %r14
leaq 0x8f9e(%rip), %rsi      # 0x6a488
movl $0xc, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xc6b3(%rip), %rsi      # 0x6dbb1
movl $0xf, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xc71a(%rip), %rsi      # 0x6dc2c
movl $0x24, %edx
movq %r14, %rdi
callq 0xb5f0
callq 0xb070
movl (%rax), %edi
callq 0xb190
testq %rax, %rax
je 0x615ab
movq %rax, %r15
movq %rax, %rdi
callq 0xb200
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0xb5f0
jmp 0x615c3
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0xb990
leaq 0xadf2(%rip), %rsi      # 0x6c35b
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 0x61617
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0xb990
leaq 0xad91(%rip), %rsi      # 0x6c35b
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