// File: /workspace/github_c_makefile_star2_O2/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)
andl $0x0, 0x8(%rsp)
pushq $0xa
popq %rdi
pushq $0x2
popq %rsi
xorl %edx, %edx
callq 0x23a0
pushq $-0x1
popq %rbx
testl %eax, %eax
js 0x271d
movl %eax, %ebp
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
leaq 0x4(%rsp), %rcx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x20a0
testl %eax, %eax
js 0x26b8
pushq $0x29
popq %rsi
pushq $0x13
popq %rdx
leaq 0x8(%rsp), %rcx
pushq $0x4
popq %r8
movl %ebp, %edi
callq 0x20a0
testl %eax, %eax
js 0x26c9
pushq $0x29
popq %rsi
pushq $0x12
popq %rdx
leaq 0x4(%rsp), %rcx
pushq $0x4
popq %r8
movl %ebp, %edi
callq 0x20a0
testl %eax, %eax
js 0x26da
pushq $0x29
popq %rsi
pushq $0x1a
popq %rdx
leaq 0x4(%rsp), %rcx
pushq $0x4
popq %r8
movl %ebp, %edi
callq 0x20a0
testl %eax, %eax
js 0x26eb
pushq $0x29
popq %rsi
pushq $0x31
popq %rdx
leaq 0x4(%rsp), %rcx
pushq $0x4
popq %r8
movl %ebp, %edi
callq 0x20a0
testl %eax, %eax
js 0x26fc
pushq $0x1
popq %rsi
movl %ebp, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x2708
orl $0x1, %eax
pushq $0x2
popq %rsi
movl %ebp, %edi
movl %eax, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x2708
pushq $0x3
popq %rsi
movl %ebp, %edi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x2708
orl $0x800, %eax            # imm = 0x800
pushq $0x4
popq %rsi
movl %ebp, %edi
movl %eax, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x2708
xorps %xmm0, %xmm0
leaq 0xc(%rsp), %rsi
movups %xmm0, 0x4(%rsi)
andq $0x0, 0x14(%rsi)
movw $0xa, (%rsi)
rolw $0x8, %r14w
movw %r14w, 0x2(%rsi)
pushq $0x1c
popq %rdx
movl %ebp, %edi
callq 0x22b0
testl %eax, %eax
js 0x2708
movl %ebp, %ebx
jmp 0x271d
leaq 0x9981(%rip), %rdi      # 0xc040
callq 0x22f0
jmp 0x25ae
leaq 0x9989(%rip), %rdi      # 0xc059
callq 0x22f0
jmp 0x25cc
leaq 0x9998(%rip), %rdi      # 0xc079
callq 0x22f0
jmp 0x25ea
leaq 0x99a7(%rip), %rdi      # 0xc099
callq 0x22f0
jmp 0x2608
leaq 0x99ae(%rip), %rdi      # 0xc0b1
callq 0x22f0
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