// File: /workspace/github_c_makefile_star2_O3/jech[P]shncpd/ra.c
// Function: setup_ra_socket
int
setup_ra_socket()
{
    int s, i, rc, one = 1, ff = 255;
    struct icmp6_filter filter;

    if(ra_socket >= 0) {
        close(ra_socket);
        ra_socket = -1;
    }

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

    rc = setsockopt(s, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ff, sizeof(ff));
    if(rc < 0)
        goto fail;

    rc = setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ff, sizeof(ff));
    if(rc < 0)
        goto fail;

    rc = setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &one, sizeof(one));
    if(rc < 0)
        goto fail;

    for(i = 0; i < numinterfaces; i++) {
        struct ipv6_mreq mreq;
        const unsigned char all_routers[16] =
            {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
        if(interfaces[i].ifindex <= 0)
            continue;
        memset(&mreq, 0, sizeof(mreq));
        memcpy(&mreq.ipv6mr_multiaddr, &all_routers, 16);
        mreq.ipv6mr_interface = interfaces[i].ifindex;
        rc = setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP,
                        (char*)&mreq, sizeof(mreq));
        if(rc < 0)
            goto fail;
    }

    ICMP6_FILTER_SETBLOCKALL(&filter);
    ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter);

    rc = setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, &filter, sizeof(filter));
    if(rc < 0)
        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;

    ra_socket = s;
    return s;

fail:
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl $0x1, 0xc(%rsp)
movl $0xff, 0x8(%rsp)
movl 0xbf50(%rip), %edi      # 0x131ec
testl %edi, %edi
js 0x72af
callq 0x2190
movl $0xffffffff, 0xbf3d(%rip) # imm = 0xFFFFFFFF
movl $0xa, %edi
movl $0x3, %esi
movl $0x3a, %edx
callq 0x2390
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x7444
movl %eax, %ebp
leaq 0x8(%rsp), %rcx
movl %eax, %edi
movl $0x29, %esi
movl $0x10, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x7444
leaq 0x8(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x12, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x7444
leaq 0xc(%rsp), %rcx
movl %ebp, %edi
movl $0x29, %esi
movl $0x33, %edx
movl $0x4, %r8d
callq 0x20a0
testl %eax, %eax
js 0x7444
leaq 0xbf5b(%rip), %r15      # 0x132a0
movl (%r15), %eax
testl %eax, %eax
jle 0x73b0
leaq 0xbf5d(%rip), %r12      # 0x132b0
addq $0x8, %r12
xorl %r13d, %r13d
leaq 0x10(%rsp), %r14
movl (%r12), %ecx
testl %ecx, %ecx
jle 0x739e
movdqa 0x6971(%rip), %xmm0     # 0xdce0
movdqa %xmm0, 0x10(%rsp)
movl %ecx, 0x20(%rsp)
movl %ebp, %edi
movl $0x29, %esi
movl $0x14, %edx
movq %r14, %rcx
movl $0x14, %r8d
callq 0x20a0
testl %eax, %eax
js 0x7444
movl (%r15), %eax
incq %r13
movslq %eax, %rcx
addq $0x98, %r12
cmpq %rcx, %r13
jl 0x735f
pcmpeqd %xmm0, %xmm0
leaq 0x10(%rsp), %rcx
movdqa %xmm0, 0x10(%rcx)
movdqa %xmm0, (%rcx)
movl $0xffffffdf, 0x10(%rcx) # imm = 0xFFFFFFDF
movl %ebp, %edi
movl $0x3a, %esi
movl $0x1, %edx
movl $0x20, %r8d
callq 0x20a0
testl %eax, %eax
js 0x7444
movl %ebp, %edi
movl $0x1, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x7444
orl $0x1, %eax
movl %ebp, %edi
movl $0x2, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x7444
movl %ebp, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x7444
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x20b0
testl %eax, %eax
js 0x7444
movl %ebp, 0xbdaa(%rip)      # 0x131ec
movl %ebp, %ebx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq