// File: nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: mg_connect
static struct mg_connection *mg_connect(struct mg_connection *conn,
                                 const char *host, int port, int use_ssl) {
  struct mg_connection *newconn = NULL;
  struct sockaddr_in sin;
  struct hostent *he;
  int sock;

  if (conn->ctx->ssl_ctx == NULL && use_ssl) {
    cry(conn, "%s: SSL is not initialized", __func__);
  } else if ((he = gethostbyname(host)) == NULL) {
    cry(conn, "%s: gethostbyname(%s): %s", __func__, host, strerror(ERRNO));
  } else if ((sock = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
    cry(conn, "%s: socket: %s", __func__, strerror(ERRNO));
  } else {
    sin.sin_family = AF_INET;
    sin.sin_port = htons((uint16_t) port);
    sin.sin_addr = * (struct in_addr *) he->h_addr_list[0];
    if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) != 0) {
      cry(conn, "%s: connect(%s:%d): %s", __func__, host, port,
          strerror(ERRNO));
      closesocket(sock);
    } else if ((newconn = (struct mg_connection *)
                calloc(1, sizeof(*newconn))) == NULL) {
      cry(conn, "%s: calloc: %s", __func__, strerror(ERRNO));
      closesocket(sock);
    } else {
      newconn->client.sock = sock;
      newconn->client.rsa.u.sin = sin;
      if (use_ssl) {
        sslize(newconn, SSL_connect);
      }
    }
  }

  return newconn;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movl %edx, 0x64(%rsp)
movl %ecx, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq 0x70(%rsp), %rax
movq 0x458(%rax), %rax
cmpq $0x0, 0x8(%rax)
jne 0x1d2b8
cmpl $0x0, 0x60(%rsp)
je 0x1d2b8
movq 0x70(%rsp), %rdi
leaq 0x5d2c(%rip), %rsi      # 0x22fd1
leaq 0x5d40(%rip), %rdx      # 0x22fec
movb $0x0, %al
callq 0x184e0
jmp 0x1d4a9
movq 0x68(%rsp), %rdi
callq 0x5670
movq %rax, 0x40(%rsp)
cmpq $0x0, %rax
jne 0x1d314
movq 0x70(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x30(%rsp)
callq 0x5060
movl (%rax), %edi
callq 0x5190
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rcx
movq %rax, %r8
leaq 0x5cf6(%rip), %rsi      # 0x22ff7
leaq 0x5ce4(%rip), %rdx      # 0x22fec
movb $0x0, %al
callq 0x184e0
jmp 0x1d4a7
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x5120
movl %eax, 0x3c(%rsp)
cmpl $-0x1, %eax
jne 0x1d366
movq 0x70(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0x5060
movl (%rax), %edi
callq 0x5190
movq 0x20(%rsp), %rdi
movq %rax, %rcx
leaq 0x5cbe(%rip), %rsi      # 0x23011
leaq 0x5c92(%rip), %rdx      # 0x22fec
movb $0x0, %al
callq 0x184e0
jmp 0x1d4a5
movw $0x2, 0x48(%rsp)
movl 0x64(%rsp), %eax
movzwl %ax, %edi
callq 0x5080
movw %ax, 0x4a(%rsp)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, 0x4c(%rsp)
movl 0x3c(%rsp), %edi
leaq 0x48(%rsp), %rsi
movl $0x10, %edx
callq 0x5470
cmpl $0x0, %eax
je 0x1d405
movq 0x70(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x64(%rsp), %eax
movl %eax, 0x1c(%rsp)
callq 0x5060
movl (%rax), %edi
callq 0x5190
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rcx
movl 0x1c(%rsp), %r8d
movq %rax, %r9
leaq 0x5c37(%rip), %rsi      # 0x23020
leaq 0x5bfc(%rip), %rdx      # 0x22fec
movb $0x0, %al
callq 0x184e0
movl 0x3c(%rsp), %edi
callq 0x5b70
jmp 0x1d4a3
movl $0x1, %edi
movl $0x4e0, %esi            # imm = 0x4E0
callq 0x5350
movq %rax, 0x58(%rsp)
cmpq $0x0, %rax
jne 0x1d45b
movq 0x70(%rsp), %rax
movq %rax, (%rsp)
callq 0x5060
movl (%rax), %edi
callq 0x5190
movq (%rsp), %rdi
movq %rax, %rcx
leaq 0x5bf5(%rip), %rsi      # 0x23037
leaq 0x5ba3(%rip), %rdx      # 0x22fec
movb $0x0, %al
callq 0x184e0
movl 0x3c(%rsp), %edi
callq 0x5b70
jmp 0x1d4a1
movl 0x3c(%rsp), %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x470(%rax)
movq 0x58(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, 0x48c(%rax)
movq 0x50(%rsp), %rcx
movq %rcx, 0x494(%rax)
cmpl $0x0, 0x60(%rsp)
je 0x1d49f
movq 0x58(%rsp), %rdi
movq 0xe45e(%rip), %rsi      # 0x2b8f8
callq 0x1b530
jmp 0x1d4a1
jmp 0x1d4a3
jmp 0x1d4a5
jmp 0x1d4a7
jmp 0x1d4a9
movq 0x58(%rsp), %rax
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)