// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: ns_socketpair2
int ns_socketpair2(sock_t sp[2], int sock_type) {
  union socket_address sa;
  sock_t sock;
  socklen_t len = sizeof(sa.sin);
  int ret = 0;

  sp[0] = sp[1] = INVALID_SOCKET;

  (void) memset(&sa, 0, sizeof(sa));
  sa.sin.sin_family = AF_INET;
  sa.sin.sin_port = htons(0);
  sa.sin.sin_addr.s_addr = htonl(0x7f000001);

  if ((sock = socket(AF_INET, sock_type, 0)) != INVALID_SOCKET &&
      !bind(sock, &sa.sa, len) &&
      (sock_type == SOCK_DGRAM || !listen(sock, 1)) &&
      !getsockname(sock, &sa.sa, &len) &&
      (sp[0] = socket(AF_INET, sock_type, 0)) != INVALID_SOCKET &&
      !connect(sp[0], &sa.sa, len) &&
      (sock_type == SOCK_STREAM ||
       (!getsockname(sp[0], &sa.sa, &len) && !connect(sock, &sa.sa, len))) &&
      (sp[1] = (sock_type == SOCK_DGRAM ? sock :
                accept(sock, &sa.sa, &len))) != INVALID_SOCKET) {
    ns_set_close_on_exec(sp[0]);
    ns_set_close_on_exec(sp[1]);
    ret = 1;
  } else {
    if (sp[0] != INVALID_SOCKET) closesocket(sp[0]);
    if (sp[1] != INVALID_SOCKET) closesocket(sp[1]);
    sp[0] = sp[1] = INVALID_SOCKET;
  }
  if (sock_type != SOCK_DGRAM) closesocket(sock);

  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x10, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq -0x1c(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0xd430
movw $0x2, -0x1c(%rbp)
xorl %edi, %edi
callq 0xd920
movw %ax, -0x1a(%rbp)
movl $0x7f000001, %edi       # imm = 0x7F000001
callq 0xd930
movl %eax, -0x18(%rbp)
movl -0xc(%rbp), %esi
movl $0x2, %edi
xorl %edx, %edx
callq 0xd640
movl %eax, -0x20(%rbp)
cmpl $-0x1, %eax
je 0xaf323
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %edx
leaq -0x1c(%rbp), %rsi
callq 0xdbf0
cmpl $0x0, %eax
jne 0xaf323
cmpl $0x2, -0xc(%rbp)
je 0xaf24f
movl -0x20(%rbp), %edi
movl $0x1, %esi
callq 0xde10
cmpl $0x0, %eax
jne 0xaf323
movl -0x20(%rbp), %edi
leaq -0x1c(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0xd090
cmpl $0x0, %eax
jne 0xaf323
movl -0xc(%rbp), %esi
movl $0x2, %edi
xorl %edx, %edx
callq 0xd640
movq -0x8(%rbp), %rcx
movl %eax, (%rcx)
cmpl $-0x1, %eax
je 0xaf323
movq -0x8(%rbp), %rax
movl (%rax), %edi
movl -0x24(%rbp), %edx
leaq -0x1c(%rbp), %rsi
callq 0xd4f0
cmpl $0x0, %eax
jne 0xaf323
cmpl $0x1, -0xc(%rbp)
je 0xaf2d3
movq -0x8(%rbp), %rax
movl (%rax), %edi
leaq -0x1c(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0xd090
cmpl $0x0, %eax
jne 0xaf323
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %edx
leaq -0x1c(%rbp), %rsi
callq 0xd4f0
cmpl $0x0, %eax
jne 0xaf323
cmpl $0x2, -0xc(%rbp)
jne 0xaf2e1
movl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0xaf2f4
movl -0x20(%rbp), %edi
leaq -0x1c(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0xdac0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl %eax, 0x4(%rcx)
cmpl $-0x1, %eax
je 0xaf323
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0xaf170
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
callq 0xaf170
movl $0x1, -0x28(%rbp)
jmp 0xaf362
movq -0x8(%rbp), %rax
cmpl $-0x1, (%rax)
je 0xaf337
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0xd350
movq -0x8(%rbp), %rax
cmpl $-0x1, 0x4(%rax)
je 0xaf34d
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
callq 0xd350
movq -0x8(%rbp), %rax
movl $0xffffffff, 0x4(%rax)  # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
cmpl $0x2, -0xc(%rbp)
je 0xaf370
movl -0x20(%rbp), %edi
callq 0xd350
movl -0x28(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)