// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
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 0x2a8d0(%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 0x614f9
movl %eax, %r15d
movq %r12, %rdi
callq 0xb5e0
testq %rax, %rax
je 0x61561
movq %rsp, %rsi
movq $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 %r15d, %edi
movl $0x10, %edx
callq 0xb400
cmpl $-0x1, %eax
je 0x615f5
movq %r14, %rdi
movq %rbx, %rsi
callq 0x60066
jmp 0x6176d
leaq 0x2b070(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x6176b
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq 0x18(%rax), %rbx
leaq 0x8f83(%rip), %rsi      # 0x6a4a8
movl $0xc, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc6e8(%rip), %rsi      # 0x6dc21
movl $0xf, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc79b(%rip), %rsi      # 0x6dce8
movl $0x29, %edx
movq %rbx, %rdi
callq 0xb5f0
callq 0xb070
jmp 0x615c7
leaq 0x2b008(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x6176b
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq 0x18(%rax), %rbx
leaq 0x8f1b(%rip), %rsi      # 0x6a4a8
movl $0xc, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc680(%rip), %rsi      # 0x6dc21
movl $0xf, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0xc75d(%rip), %rsi      # 0x6dd12
movl $0x20, %edx
movq %rbx, %rdi
callq 0xb5f0
callq 0xb890
movl (%rax), %edi
callq 0xb190
testq %rax, %rax
je 0x61684
movq %rax, %r14
movq %rax, %rdi
callq 0xb200
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0xb5f0
jmp 0x6169b
leaq 0x2af74(%rip), %r12     # 0x8c570
movq (%r12), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x6174e
addq $0x20, %rdi
callq 0xb7d0
movq (%r12), %rax
movq 0x8(%rax), %r14
leaq 0x8b85(%rip), %rsi      # 0x6a1a8
movl $0xb, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xc5ea(%rip), %rsi      # 0x6dc21
movl $0xf, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0xc6e8(%rip), %rsi      # 0x6dd33
movl $0x27, %edx
movq %r14, %rdi
callq 0xb5f0
callq 0xb070
movl (%rax), %edi
callq 0xb190
testq %rax, %rax
je 0x616e7
movq %rax, %r15
movq %rax, %rdi
callq 0xb200
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0xb5f0
jmp 0x616ff
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0xb990
leaq 0xad31(%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 0x6176b
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0xb990
leaq 0xaccd(%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
movl 0x2d4(%rbx), %r15d
movl %r15d, %edi
callq 0xbaa0
movq %rbx, %rdi
callq 0x60d40
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