// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/ip/iptee.c
// Function: ipConnect
int ipConnect(const char *host, const char *service, ConnectionType ct, struct sockaddr *sockaddr, socklen_t *socklen)
{
  int             sockfd = -1;
  int             n;
  struct addrinfo hints, *res, *addr;

  memset(&hints, 0, sizeof(hints));
  hints.ai_family   = AF_INET;
  hints.ai_socktype = (ct == ClientUDP) ? SOCK_DGRAM : SOCK_STREAM;

  n = getaddrinfo(host, service, &hints, &res);
  if (n != 0)
  {
    logError("Unable to open connection to %s:%s: %s\n", host, service, gai_strerror(n));
  }

  for (addr = res; addr; addr = addr->ai_next)
  {
    sockfd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
    if (sockfd < 0)
    {
      continue;
    }

    if (ct == ServerTCP)
    {
      if (!bind(sockfd, addr->ai_addr, addr->ai_addrlen) && !listen(sockfd, 10))
      {
        break;
      }
    }
    else if (ct == ClientTCP)
    {
      if (!connect(sockfd, addr->ai_addr, addr->ai_addrlen))
      {
        break;
      }
    }
    else /* ClientUDP */
    {
      break;
    }
    close(sockfd);
    sockfd = -1;
  }
  if (!addr)
  {
    logError("Unable to open connection to %s:%s: %s\n", host, service, strerror(errno));
  }
  else
  {
    *socklen = addr->ai_addrlen;
    memcpy(sockaddr, addr->ai_addr, addr->ai_addrlen);
  }

  freeaddrinfo(res);

  if (sockfd >= 0 && ct != ClientUDP)
  {
    unsigned long nonblock = 1;
    ioctl(sockfd, FIONBIO, &nonblock); /* Set to non-blocking */
    logInfo("Opened %s %s:%s\n", ((ct == ServerTCP) ? "server for" : "connection to"), host, service);
  }

  return sockfd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x2150
movl $0x2, -0x5c(%rbp)
movl -0x14(%rbp), %edx
movl $0x1, %eax
movl $0x2, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x60(%rbp), %rdx
leaq -0x68(%rbp), %rcx
callq 0x22d0
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
je 0x24f7
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movl -0x30(%rbp), %edi
callq 0x2110
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq %rax, %rcx
leaq 0x3b14(%rip), %rdi      # 0x6004
movb $0x0, %al
callq 0x3620
movq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x25b1
movq -0x70(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x70(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x70(%rbp), %rax
movl 0xc(%rax), %edx
callq 0x2340
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x252f
jmp 0x25a0
cmpl $0x2, -0x14(%rbp)
jne 0x2567
movl -0x2c(%rbp), %edi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x70(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x2260
cmpl $0x0, %eax
jne 0x2565
movl -0x2c(%rbp), %edi
movl $0xa, %esi
callq 0x2230
cmpl $0x0, %eax
jne 0x2565
jmp 0x25b1
jmp 0x2591
cmpl $0x1, -0x14(%rbp)
jne 0x258d
movl -0x2c(%rbp), %edi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x70(%rbp), %rax
movl 0x10(%rax), %edx
callq 0x22c0
cmpl $0x0, %eax
jne 0x258b
jmp 0x25b1
jmp 0x258f
jmp 0x25b1
jmp 0x2591
movl -0x2c(%rbp), %edi
callq 0x2180
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq -0x70(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x24ff
cmpq $0x0, -0x70(%rbp)
jne 0x25fb
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
callq 0x2060
movl (%rax), %edi
callq 0x22f0
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
movq %rax, %rcx
leaq 0x3a12(%rip), %rdi      # 0x6004
movb $0x0, %al
callq 0x3620
jmp 0x2622
movq -0x70(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rdi
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x70(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %edx
callq 0x21e0
movq -0x68(%rbp), %rdi
callq 0x2330
cmpl $0x0, -0x2c(%rbp)
jl 0x2680
cmpl $0x0, -0x14(%rbp)
je 0x2680
movq $0x1, -0x78(%rbp)
movl -0x2c(%rbp), %edi
movl $0x5421, %esi           # imm = 0x5421
leaq -0x78(%rbp), %rdx
movb $0x0, %al
callq 0x2160
movl -0x14(%rbp), %ecx
leaq 0x39ec(%rip), %rsi      # 0x6048
leaq 0x39da(%rip), %rax      # 0x603d
cmpl $0x2, %ecx
cmoveq %rax, %rsi
movq -0x8(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x39b3(%rip), %rdi      # 0x602c
movb $0x0, %al
callq 0x3420
movl -0x2c(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)