// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_socketpair
int mg_socketpair(sock_t sp[2], int sock_type) {
  union socket_address sa;
  sock_t sock;
  socklen_t len = sizeof(sa.sin);
  int ret = 0;

  sock = 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); /* 127.0.0.1 */

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

  if (!ret) {
    if (sp[0] != INVALID_SOCKET) mg_socketpair_close(&sp[0]);
    if (sp[1] != INVALID_SOCKET) mg_socketpair_close(&sp[1]);
    if (sock != INVALID_SOCKET) mg_socketpair_close(&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
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
leaq -0x1c(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3260
movw $0x2, -0x1c(%rbp)
xorl %edi, %edi
callq 0x31a0
movw %ax, -0x1a(%rbp)
movl $0x7f000001, %edi       # imm = 0x7F000001
callq 0x3250
movl %eax, -0x18(%rbp)
movl -0xc(%rbp), %esi
movl $0x2, %edi
xorl %edx, %edx
callq 0x36b0
movl %eax, -0x20(%rbp)
cmpl $-0x1, %eax
jne 0xe353
jmp 0xe47e
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %edx
leaq -0x1c(%rbp), %rsi
callq 0x3500
cmpl $0x0, %eax
je 0xe36c
jmp 0xe47c
cmpl $0x1, -0xc(%rbp)
jne 0xe389
movl -0x20(%rbp), %edi
movl $0x1, %esi
callq 0x3480
cmpl $0x0, %eax
je 0xe389
jmp 0xe47a
movl -0x20(%rbp), %edi
leaq -0x1c(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0x35a0
cmpl $0x0, %eax
je 0xe3a3
jmp 0xe478
movl -0xc(%rbp), %esi
movl $0x2, %edi
xorl %edx, %edx
callq 0x36b0
movq -0x8(%rbp), %rcx
movl %eax, (%rcx)
cmpl $-0x1, %eax
jne 0xe3c2
jmp 0xe476
movq -0x8(%rbp), %rax
movl (%rax), %edi
movl -0x24(%rbp), %edx
leaq -0x1c(%rbp), %rsi
callq 0x3600
cmpl $0x0, %eax
je 0xe3de
jmp 0xe474
cmpl $0x2, -0xc(%rbp)
jne 0xe412
movq -0x8(%rbp), %rax
movl (%rax), %edi
leaq -0x1c(%rbp), %rsi
leaq -0x24(%rbp), %rdx
callq 0x35a0
cmpl $0x0, %eax
jne 0xe410
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %edx
leaq -0x1c(%rbp), %rsi
callq 0x3600
cmpl $0x0, %eax
je 0xe412
jmp 0xe472
cmpl $0x2, -0xc(%rbp)
jne 0xe420
movl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0xe432
movl -0x20(%rbp), %edi
movl -0x24(%rbp), %edx
leaq -0x1c(%rbp), %rsi
callq 0xed80
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x8(%rbp), %rcx
movl %eax, 0x4(%rcx)
cmpl $-0x1, %eax
jne 0xe443
jmp 0xe470
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0xe240
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
callq 0xe240
cmpl $0x1, -0xc(%rbp)
jne 0xe469
leaq -0x20(%rbp), %rdi
callq 0xedd0
movl $0x1, -0x28(%rbp)
jmp 0xe472
jmp 0xe474
jmp 0xe476
jmp 0xe478
jmp 0xe47a
jmp 0xe47c
jmp 0xe47e
cmpl $0x0, -0x28(%rbp)
jne 0xe4be
movq -0x8(%rbp), %rax
cmpl $-0x1, (%rax)
je 0xe496
movq -0x8(%rbp), %rdi
callq 0xedd0
movq -0x8(%rbp), %rax
cmpl $-0x1, 0x4(%rax)
je 0xe4ad
movq -0x8(%rbp), %rdi
addq $0x4, %rdi
callq 0xedd0
cmpl $-0x1, -0x20(%rbp)
je 0xe4bc
leaq -0x20(%rbp), %rdi
callq 0xedd0
jmp 0xe4be
movl -0x28(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)