// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movl %edi, %r14d
movl $0x1, 0x8(%rsp)
movl $0x0, 0xc(%rsp)
movl $0xa, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x2390
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x352c
movl %eax, %ebp
leaq 0x8(%rsp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x34c7
leaq 0xc(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x13, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x34d8
leaq 0x8(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x12, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x34e9
leaq 0x8(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x1a, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x34fa
leaq 0x8(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x31, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x350b
movl %ebp, %edi
movl $0x1, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x3517
orl $0x1, %eax
movl %ebp, %edi
movl $0x2, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x3517
movl %ebp, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x3517
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x3517
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movaps %xmm0, (%rsi)
movups %xmm0, 0xc(%rsi)
movw $0xa, (%rsi)
rolw $0x8, %r14w
movw %r14w, 0x2(%rsi)
movl %ebp, %edi
movl $0x1c, %edx
callq 0x22a0
testl %eax, %eax
js 0x3517
movl %ebp, %ebx
jmp 0x352c
leaq 0x9b72(%rip), %rdi      # 0xd040
callq 0x22e0
jmp 0x339d
leaq 0x9b7a(%rip), %rdi      # 0xd059
callq 0x22e0
jmp 0x33c1
leaq 0x9b89(%rip), %rdi      # 0xd079
callq 0x22e0
jmp 0x33e5
leaq 0x9b98(%rip), %rdi      # 0xd099
callq 0x22e0
jmp 0x3409
leaq 0x9b9f(%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 $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq