// File: ctSkennerton[P]fxtract/util/sock.c
// Function: sock_recvfd
int
sock_recvfd(int skt, int *pfd, char *buf, int size)
{
    dyninit();

    int ret;
    char x;
    FDCMSG ctl = { {sizeof ctl, 0, 0} , -1 };
    struct iovec iov[2] = { {&x, sizeof x} , {buf, size} };
    struct msghdr msg = { 0, 0, iov, 1 + (buf && size), &ctl, sizeof ctl, 0 };

    do errno = 0, ret = recvmsg(skt, &msg, cmsg_cloexec);
    while (ret < 0 && errno == EINTR);

    if (ret >= 0 && !cmsg_cloexec && fcntl(ctl.fd, F_SETFD, FD_CLOEXEC))
        return close(ctl.fd), -1;

    if (pfd)
        *pfd = ctl.fd;

    return ret < 0 ? ret
        : memcmp(&ctl.c, &fdc_hdr, sizeof fdc_hdr) ? errno = ENOMSG, -1
        : ret - (int) sizeof(x) * (ret > 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
callq 0x8020
movq 0x2a93(%rip), %rax      # 0xbba8
movq %rax, -0x40(%rbp)
movq 0x2a90(%rip), %rax      # 0xbbb0
movq %rax, -0x38(%rbp)
movq 0x2a8d(%rip), %rax      # 0xbbb8
movq %rax, -0x30(%rbp)
leaq -0x21(%rbp), %rax
movq %rax, -0x60(%rbp)
movq $0x1, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movslq -0x1c(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x98(%rbp)
movl $0x0, -0x90(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x98(%rbp), %rax
addq $0x18, %rax
movq %rax, -0xa8(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0x99(%rbp)
je 0x919d
cmpl $0x0, -0x1c(%rbp)
setne %al
movb %al, -0x99(%rbp)
movq -0xa8(%rbp), %rax
movb -0x99(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rcx, (%rax)
leaq -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
movq $0x18, -0x70(%rbp)
movl $0x0, -0x68(%rbp)
callq 0x3040
movl $0x0, (%rax)
movl -0x8(%rbp), %edi
movl 0x6710(%rip), %edx      # 0xf8f4
leaq -0x98(%rbp), %rsi
callq 0x30d0
movl %eax, -0x20(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x20(%rbp)
movb %al, -0xa9(%rbp)
jge 0x9212
callq 0x3040
cmpl $0x4, (%rax)
sete %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
testb $0x1, %al
jne 0x91d0
cmpl $0x0, -0x20(%rbp)
jl 0x9258
cmpl $0x0, 0x66cb(%rip)      # 0xf8f4
jne 0x9258
movl -0x30(%rbp), %edi
movl $0x2, %esi
movl $0x1, %edx
movb $0x0, %al
callq 0x31e0
cmpl $0x0, %eax
je 0x9258
movl -0x30(%rbp), %edi
callq 0x3580
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x92e7
cmpq $0x0, -0x10(%rbp)
je 0x9268
movl -0x30(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x20(%rbp)
jge 0x9279
movl -0x20(%rbp), %eax
movl %eax, -0xb0(%rbp)
jmp 0x92de
leaq -0x40(%rbp), %rax
movups (%rax), %xmm0
movaps 0x2909(%rip), %xmm1     # 0xbb90
pcmpeqb %xmm1, %xmm0
pmovmskb %xmm0, %eax
subl $0xffff, %eax           # imm = 0xFFFF
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x92b7
callq 0x3040
movl $0x2a, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0xb4(%rbp)
jmp 0x92d2
movl -0x20(%rbp), %eax
cmpl $0x0, -0x20(%rbp)
setg %cl
andb $0x1, %cl
movzbl %cl, %ecx
shll $0x0, %ecx
subl %ecx, %eax
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)