// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movl $0x2d8, %edi            # imm = 0x2D8
callq 0xb500
movq %rax, %rbx
movq %r14, (%rax)
movw $0x100, 0x8(%rax)       # imm = 0x100
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
leaq 0x2a418(%rip), %rax     # 0x8bd08
addq $0x10, %rax
movq %rax, 0x30(%rbx)
movups %xmm0, 0x38(%rbx)
xorl %ecx, %ecx
movb %cl, 0x48(%rbx)
movups %xmm0, 0x50(%rbx)
movups %xmm0, 0x60(%rbx)
movq %rax, 0x70(%rbx)
movups %xmm0, 0x78(%rbx)
movb %cl, 0x88(%rbx)
movups %xmm0, 0x90(%rbx)
movups %xmm0, 0xa0(%rbx)
movups %xmm0, 0x2c0(%rbx)
movq $0x0, 0x2d0(%rbx)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0xb0f0
movl %eax, 0x2d4(%rbx)
cmpl $-0x1, %eax
je 0x619af
movq %r15, %rdi
callq 0xb5e0
testq %rax, %rax
je 0x61a17
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%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
movl $0x10, %edx
callq 0xb400
cmpl $-0x1, %eax
je 0x61aab
movq %r14, %rdi
movq %rbx, %rsi
callq 0x60560
jmp 0x61c1f
leaq 0x2abba(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x61c1d
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq 0x18(%rax), %rbx
leaq 0x8aad(%rip), %rsi      # 0x6a488
movl $0xc, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc1c2(%rip), %rsi      # 0x6dbb1
movl $0xf, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc275(%rip), %rsi      # 0x6dc78
movl $0x29, %edx
movq %rbx, %rdi
callq 0xb5f0
callq 0xb070
jmp 0x61a7d
leaq 0x2ab52(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x61c1d
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq 0x18(%rax), %rbx
leaq 0x8a45(%rip), %rsi      # 0x6a488
movl $0xc, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc15a(%rip), %rsi      # 0x6dbb1
movl $0xf, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc237(%rip), %rsi      # 0x6dca2
movl $0x20, %edx
movq %rbx, %rdi
callq 0xb5f0
callq 0xb890
movl (%rax), %edi
callq 0xb190
testq %rax, %rax
je 0x61b3a
movq %rax, %r14
movq %rax, %rdi
callq 0xb200
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0xb5f0
jmp 0x61b51
leaq 0x2aabe(%rip), %r12     # 0x8c570
movq (%r12), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x61bfd
addq $0x20, %rdi
callq 0xb7d0
movq (%r12), %rax
movq 0x8(%rax), %r14
leaq 0x86af(%rip), %rsi      # 0x6a188
movl $0xb, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xc0c4(%rip), %rsi      # 0x6dbb1
movl $0xf, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xc1c2(%rip), %rsi      # 0x6dcc3
movl $0x27, %edx
movq %r14, %rdi
callq 0xb5f0
callq 0xb070
movl (%rax), %edi
callq 0xb190
testq %rax, %rax
je 0x61b9d
movq %rax, %r15
movq %rax, %rdi
callq 0xb200
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0xb5f0
jmp 0x61bb5
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0xb990
leaq 0xa803(%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 0x61c1d
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0xb990
leaq 0xa79f(%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
movl 0x2d4(%rbx), %edi
callq 0xbaa0
movq %rbx, %rdi
callq 0x611fa
movl $0x2d8, %esi            # imm = 0x2D8
movq %rbx, %rdi
callq 0xb510
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq