// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movl $0x1, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0xa, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x23b0
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jge 0x24ff
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x26ec
movl -0x28(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x34(%rbp), %rcx
movl $0x4, %r8d
callq 0x2090
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x2530
leaq 0xfba5(%rip), %rdi      # 0x120d0
callq 0x2300
movl -0x28(%rbp), %edi
movl $0x29, %esi
movl $0x13, %edx
leaq -0x38(%rbp), %rcx
movl $0x4, %r8d
callq 0x2090
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x2561
leaq 0xfb8d(%rip), %rdi      # 0x120e9
callq 0x2300
movl -0x28(%rbp), %edi
movl $0x29, %esi
movl $0x12, %edx
leaq -0x34(%rbp), %rcx
movl $0x4, %r8d
callq 0x2090
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x2592
leaq 0xfb7c(%rip), %rdi      # 0x12109
callq 0x2300
movl -0x28(%rbp), %edi
movl $0x29, %esi
movl $0x1a, %edx
leaq -0x34(%rbp), %rcx
movl $0x4, %r8d
callq 0x2090
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x25c3
leaq 0xfb6b(%rip), %rdi      # 0x12129
callq 0x2300
movl -0x28(%rbp), %edi
movl $0x29, %esi
movl $0x31, %edx
leaq -0x34(%rbp), %rcx
movl $0x4, %r8d
callq 0x2090
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x25f9
leaq 0xfb52(%rip), %rdi      # 0x12141
callq 0x2300
jmp 0x26c3
movl -0x28(%rbp), %edi
movl $0x1, %esi
xorl %edx, %edx
movb $0x0, %al
callq 0x20a0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x2618
jmp 0x26c3
movl -0x28(%rbp), %edi
movl -0x2c(%rbp), %edx
orl $0x1, %edx
movl $0x2, %esi
movb $0x0, %al
callq 0x20a0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x263b
jmp 0x26c3
movl -0x28(%rbp), %edi
movl $0x3, %esi
xorl %edx, %edx
movb $0x0, %al
callq 0x20a0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x2657
jmp 0x26c3
movl -0x28(%rbp), %edi
movl -0x2c(%rbp), %edx
orl $0x800, %edx            # imm = 0x800
movl $0x4, %esi
movb $0x0, %al
callq 0x20a0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x267a
jmp 0x26c3
leaq -0x24(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2170
movw $0xa, -0x24(%rbp)
movl -0x8(%rbp), %eax
movzwl %ax, %edi
callq 0x2100
movw %ax, -0x22(%rbp)
movl -0x28(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x1c, %edx
callq 0x22c0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x26bb
jmp 0x26c3
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x26ec
callq 0x2050
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %edi
callq 0x21a0
movl -0x30(%rbp), %eax
movl %eax, -0x3c(%rbp)
callq 0x2050
movl -0x3c(%rbp), %ecx
movl %ecx, (%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)