// File: /workspace/github_cpp_makefile_star2_O2/mh0fm4[P]SCDC/src/components/transport/transport_tcp.cc
// Function: scdc_transport_tcp::connect(char const*, int)
scdc_transport_connection_t *scdc_transport_tcp::connect(const char *host, int port)
{
  SCDC_TRACE("connect: host: '" << host << "', port: " << port);

  scdc_transport_tcp_connection_t *tcp_conn = new scdc_transport_tcp_connection_t(this);

  tcp_conn->socket = ::socket(AF_INET, SOCK_STREAM, 0);
  if (tcp_conn->socket == -1)
  {
    SCDC_ERROR("connect: creating client socket failed: '" << strerror(errno) << "'");
    return 0;
  }

  struct hostent *h = gethostbyname(host);
  if (!h)
  {
    SCDC_ERROR("connect: gethostbyname failed: '" << strerror(h_errno) << "'");
    return 0;
  }
  
  struct sockaddr_in saddr;
  memset(&saddr, 0, sizeof(saddr));

  saddr.sin_family = AF_INET;
  saddr.sin_addr = *((struct in_addr **) h->h_addr_list)[0];
  saddr.sin_port = htons(port);

  int r;
  bool except = false;

#if SCDC_TRANSPORT_TCP_USE_SHUTDOWN_EXCEPTION
  try
  {
#endif
    r = ::connect(tcp_conn->socket, (struct sockaddr *) &saddr, sizeof(saddr));

#if SCDC_TRANSPORT_TCP_USE_SHUTDOWN_EXCEPTION
  } catch (const scdc_transport_tcp_shutdown_ex &ex)
  {
    SCDC_INFO("connect: catch shutdown exception");
    r = -1;
    except = true;
  }
#endif

  if (r == -1)
  {
    if (!except) SCDC_FAIL("connect: connecting to server failed: '" << strerror(errno) << "'");
    ::close(tcp_conn->socket);
    delete tcp_conn;
    return 0;
  }

  return scdc_transport::connect(tcp_conn);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movl $0x2d8, %edi            # imm = 0x2D8
callq 0xb540
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x4b622
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0xb0f0
movl %eax, 0x2d4(%rbx)
cmpl $-0x1, %eax
je 0x4b22d
movq %r15, %rdi
callq 0xb610
testq %rax, %rax
je 0x4b286
leaq 0x8(%rsp), %rsi
andq $0x0, 0x8(%rsi)
movw $0x2, (%rsi)
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x4(%rsi)
rolw $0x8, %bp
movw %bp, 0x2(%rsi)
movl 0x2d4(%rbx), %edi
pushq $0x10
popq %rdx
callq 0xb430
cmpl $-0x1, %eax
je 0x4b317
movq %r14, %rdi
movq %rbx, %rsi
callq 0x49f66
jmp 0x4b3c1
leaq 0x2a34c(%rip), %r14     # 0x75580
movq (%r14), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4b3bf
addq $0x20, %rdi
callq 0xb800
movq (%r14), %rax
movq 0x18(%rax), %rdi
leaq 0x622f(%rip), %rsi      # 0x51488
callq 0xb520
leaq 0x994c(%rip), %rsi      # 0x54bb1
movq %rax, %rdi
callq 0xb520
leaq 0x9a04(%rip), %rsi      # 0x54c78
movq %rax, %rdi
callq 0xb520
movq %rax, %rbx
callq 0xb060
jmp 0x4b2dd
leaq 0x2a2f3(%rip), %r14     # 0x75580
movq (%r14), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4b3bf
addq $0x20, %rdi
callq 0xb800
movq (%r14), %rax
movq 0x18(%rax), %rdi
leaq 0x61d6(%rip), %rsi      # 0x51488
callq 0xb520
leaq 0x98f3(%rip), %rsi      # 0x54bb1
movq %rax, %rdi
callq 0xb520
leaq 0x99d5(%rip), %rsi      # 0x54ca2
movq %rax, %rdi
callq 0xb520
movq %rax, %rbx
callq 0xb8a0
movl (%rax), %edi
callq 0xb180
movq %rbx, %rdi
movq %rax, %rsi
callq 0xb520
leaq 0x806d(%rip), %rsi      # 0x53363
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%r14), %rdi
addq $0x20, %rdi
callq 0xb3e0
jmp 0x4b3bf
leaq 0x2a262(%rip), %r15     # 0x75580
movq (%r15), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x4b39f
addq $0x20, %rdi
callq 0xb800
movq (%r15), %rax
movq 0x8(%rax), %rdi
leaq 0x5e49(%rip), %rsi      # 0x51188
callq 0xb520
leaq 0x9866(%rip), %rsi      # 0x54bb1
movq %rax, %rdi
callq 0xb520
leaq 0x9969(%rip), %rsi      # 0x54cc3
movq %rax, %rdi
callq 0xb520
movq %rax, %r14
callq 0xb060
movl (%rax), %edi
callq 0xb180
movq %r14, %rdi
movq %rax, %rsi
callq 0xb520
leaq 0x7fe0(%rip), %rsi      # 0x53363
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%r15), %rdi
addq $0x20, %rdi
callq 0xb3e0
movl 0x2d4(%rbx), %edi
callq 0xbaa0
movq %rbx, %rdi
callq 0x4ac4e
movl $0x2d8, %esi            # imm = 0x2D8
movq %rbx, %rdi
callq 0xb550
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movl $0x2d8, %esi            # imm = 0x2D8
movq %rbx, %rdi
callq 0xb550
movq %r14, %rdi
callq 0xb9a0