// File: Rjerk[P]ratabase/Sockets.cpp
// Function: sockets::accept(int, sockaddr_in6*)
int sockets::accept(int sockfd, struct sockaddr_in6* addr)
{
    socklen_t addrlen = static_cast<socklen_t>(sizeof(*addr));
    int connfd = ::accept(sockfd,
            static_cast<struct sockaddr*>((void*)addr), &addrlen);
    setNonBlockAndCloseOnExec(connfd);
    if (connfd < 0) {
        auto saved_errno = errno;
        LOG_ERROR << "sockets::accept";
        switch (saved_errno) {
            case EAGAIN:
            case ECONNABORTED:
            case EINTR:
            case EPROTO:
            case EPERM:
            case EMFILE:
                errno = saved_errno;
                break;
            case EBADF:
            case EFAULT:
            case EINVAL:
            case ENFILE:
            case ENOBUFS:
            case ENOMEM:
            case ENOTSOCK:
            case EOPNOTSUPP:
                LOG_FATAL << "unexpected error of ::accpet: "
                          << saved_errno << ::strerror(saved_errno);
                break;
            default:
                LOG_FATAL << "unknown error of ::accept: " << saved_errno;
                break;
        }
    }
    return connfd;
}

// Assembly:
subq $0x528, %rsp            # imm = 0x528
movl %edi, 0x524(%rsp)
movq %rsi, 0x518(%rsp)
movl $0x1c, 0x514(%rsp)
movl 0x524(%rsp), %edi
movq 0x518(%rsp), %rsi
leaq 0x514(%rsp), %rdx
callq 0x2090
movl %eax, 0x510(%rsp)
movl 0x510(%rsp), %edi
callq 0x3350
cmpl $0x0, 0x510(%rsp)
jge 0x3a04
callq 0x2030
movl (%rax), %eax
movl %eax, 0x50c(%rsp)
leaq 0xa95(%rip), %rsi       # 0x4278
leaq 0xb66(%rip), %rcx       # 0x4350
leaq 0x380(%rsp), %rdi
movq %rdi, 0x50(%rsp)
movl $0x37, %edx
movl $0x4, %r8d
callq 0x28e0
movq 0x50(%rsp), %rdi
callq 0x2c80
movq %rax, 0x58(%rsp)
jmp 0x3818
movq 0x58(%rsp), %rdi
addq $0x10, %rdi
leaq 0xb1f(%rip), %rsi       # 0x4347
callq 0x2200
jmp 0x382f
leaq 0x380(%rsp), %rdi
callq 0x2b40
movl 0x50c(%rsp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x48(%rsp)
subl $0x68, %eax
ja 0x396e
movq 0x48(%rsp), %rax
leaq 0x873(%rip), %rcx       # 0x40d4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
leaq 0x380(%rsp), %rdi
callq 0x2b40
jmp 0x3a13
movl 0x50c(%rsp), %eax
movl %eax, 0x44(%rsp)
callq 0x2030
movl 0x44(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x3a02
leaq 0x9c6(%rip), %rsi       # 0x4278
leaq 0xa97(%rip), %rcx       # 0x4350
leaq 0x1e8(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movl $0x49, %edx
movl $0x5, %r8d
callq 0x28e0
movq 0x30(%rsp), %rdi
callq 0x2c80
movq %rax, 0x38(%rsp)
jmp 0x38e7
movq 0x38(%rsp), %rdi
addq $0x10, %rdi
leaq 0xa60(%rip), %rsi       # 0x4357
callq 0x2200
movq %rax, 0x28(%rsp)
jmp 0x3903
movq 0x28(%rsp), %rdi
movl 0x50c(%rsp), %esi
callq 0x22c0
movq %rax, 0x20(%rsp)
jmp 0x391b
movl 0x50c(%rsp), %edi
callq 0x20a0
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x2200
jmp 0x3936
leaq 0x1e8(%rsp), %rdi
callq 0x2b40
jmp 0x3a02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x2b40
jmp 0x3a13
leaq 0x903(%rip), %rsi       # 0x4278
leaq 0x9d4(%rip), %rcx       # 0x4350
leaq 0x60(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movl $0x4d, %edx
movl $0x5, %r8d
callq 0x28e0
movq 0x10(%rsp), %rdi
callq 0x2c80
movq %rax, 0x18(%rsp)
jmp 0x39a7
movq 0x18(%rsp), %rdi
addq $0x10, %rdi
leaq 0x9bf(%rip), %rsi       # 0x4376
callq 0x2200
movq %rax, 0x8(%rsp)
jmp 0x39c3
movq 0x8(%rsp), %rdi
movl 0x50c(%rsp), %esi
callq 0x22c0
jmp 0x39d6
leaq 0x60(%rsp), %rdi
callq 0x2b40
jmp 0x3a02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x378(%rsp)
movl %eax, 0x374(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x2b40
jmp 0x3a13
jmp 0x3a04
movl 0x510(%rsp), %eax
addq $0x528, %rsp            # imm = 0x528
retq
movq 0x378(%rsp), %rdi
callq 0x22e0