// File: /workspace/github_c_makefile_star2_O3/jech[P]shncpd/shncpd.c
// Function: hn_socket
int
hn_socket(int port)
{
    struct sockaddr_in6 sin6;
    int s, rc;
    int saved_errno;
    int one = 1, zero = 0;

    s = socket(PF_INET6, SOCK_DGRAM, 0);
    if(s < 0)
        return -1;

    rc = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
    if(rc < 0)
        perror("setsockopt(SO_REUSEADDR)");

    rc = setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
                    &zero, sizeof(zero));
    if(rc < 0)
        perror("setsockopt(IPV6_MULTICAST_LOOP)");

    rc = setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
                    &one, sizeof(one));
    if(rc < 0)
        perror("setsockopt(IPV6_MULTICAST_HOPS)");

#ifdef IPV6_V6ONLY
    rc = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
                    &one, sizeof(one));
    if(rc < 0)
        perror("setsockopt(IPV6_V6ONLY)");
#endif

    rc = setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO,  &one, sizeof(one));
    if(rc < 0) {
        perror("setsockopt(IPV6_RECVPKTINFO)");
        goto fail;
    }

    rc = fcntl(s, F_GETFD, 0);
    if(rc < 0)
        goto fail;

    rc = fcntl(s, F_SETFD, rc | FD_CLOEXEC);
    if(rc < 0)
        goto fail;

    rc = fcntl(s, F_GETFL, 0);
    if(rc < 0)
        goto fail;

    rc = fcntl(s, F_SETFL, (rc | O_NONBLOCK));
    if(rc < 0)
        goto fail;

    memset(&sin6, 0, sizeof(sin6));
    sin6.sin6_family = AF_INET6;
    sin6.sin6_port = htons(port);
    rc = bind(s, (struct sockaddr*)&sin6, sizeof(sin6));
    if(rc < 0)
        goto fail;

    return s;

 fail:
    saved_errno = errno;
    close(s);
    errno = saved_errno;
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movl %edi, %r14d
movl $0x1, 0x4(%rsp)
movl $0x0, 0x8(%rsp)
movl $0xa, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x2390
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x3431
movl %eax, %ebp
leaq 0x4(%rsp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x33cc
leaq 0x8(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x13, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x33dd
leaq 0x4(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x12, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x33ee
leaq 0x4(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x1a, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x33ff
leaq 0x4(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x31, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x3410
movl %ebp, %edi
movl $0x1, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x341c
orl $0x1, %eax
movl %ebp, %edi
movl $0x2, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x341c
movl %ebp, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x341c
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x341c
xorps %xmm0, %xmm0
leaq 0xc(%rsp), %rsi
movups %xmm0, 0x4(%rsi)
movq $0x0, 0x14(%rsi)
movw $0xa, (%rsi)
rolw $0x8, %r14w
movw %r14w, 0x2(%rsi)
movl %ebp, %edi
movl $0x1c, %edx
callq 0x22a0
testl %eax, %eax
js 0x341c
movl %ebp, %ebx
jmp 0x3431
leaq 0x9c6d(%rip), %rdi      # 0xd040
callq 0x22e0
jmp 0x329d
leaq 0x9c75(%rip), %rdi      # 0xd059
callq 0x22e0
jmp 0x32c1
leaq 0x9c84(%rip), %rdi      # 0xd079
callq 0x22e0
jmp 0x32e5
leaq 0x9c93(%rip), %rdi      # 0xd099
callq 0x22e0
jmp 0x3309
leaq 0x9c9a(%rip), %rdi      # 0xd0b1
callq 0x22e0
callq 0x2060
movq %rax, %r14
movl (%rax), %r15d
movl %ebp, %edi
callq 0x2190
movl %r15d, (%r14)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq