// File: /workspace/github_c_makefile_star2_O3/jech[P]dht/dht.c
// Function: neighbourhood_maintenance
static int
neighbourhood_maintenance(int af)
{
    unsigned char id[20];
    struct bucket *b = find_bucket(myid, af);
    struct bucket *q;
    struct node *n;

    if(b == NULL)
        return 0;

    memcpy(id, myid, 20);
    id[19] = random() & 0xFF;
    q = b;
    if(q->next && (q->count == 0 || (random() & 7) == 0))
        q = b->next;
    if(q->count == 0 || (random() & 7) == 0) {
        struct bucket *r;
        r = previous_bucket(b);
        if(r && r->count > 0)
            q = r;
    }

    if(q) {
        /* Since our node-id is the same in both DHTs, it's probably
           profitable to query both families. */
        int want = dht_socket >= 0 && dht_socket6 >= 0 ? (WANT4 | WANT6) : -1;
        n = random_node(q);
        if(n) {
            unsigned char tid[4];
            debugf("Sending find_node for%s neighborhood maintenance.\n",
                   af == AF_INET6 ? " IPv6" : "");
            make_tid(tid, "fn", 0);
            send_find_node((struct sockaddr*)&n->ss, n->sslen,
                           tid, 4, id, want,
                           n->reply_time >= now.tv_sec - 15);
            pinged(n, q);
        }
        return 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, %ebp
leaq 0x61d7(%rip), %rdi      # 0xdc30
movl %ebp, %esi
callq 0x3593
xorl %ebx, %ebx
testq %rax, %rax
je 0x7bd3
movq %rax, %r15
movl 0x61cc(%rip), %eax      # 0xdc40
movl %eax, 0x20(%rsp)
movaps 0x61b1(%rip), %xmm0     # 0xdc30
movaps %xmm0, 0x10(%rsp)
callq 0x2230
movb %al, 0x23(%rsp)
movq 0xb8(%r15), %rax
movq %r15, %r12
testq %rax, %rax
je 0x7ab9
cmpl $0x0, 0x18(%r15)
movq %rax, %r12
je 0x7ab9
callq 0x2230
movq %r15, %r12
testb $0x7, %al
jne 0x7ab9
movq 0xb8(%r15), %r12
cmpl $0x0, 0x18(%r12)
je 0x7aca
callq 0x2230
testb $0x7, %al
jne 0x7b10
cmpl $0x2, (%r15)
leaq 0x617b(%rip), %rax      # 0xdc50
leaq 0x617c(%rip), %rcx      # 0xdc58
cmoveq %rax, %rcx
movq (%rcx), %rax
cmpq %r15, %rax
je 0x7b10
movq %rax, %r14
movq 0xb8(%rax), %rax
testq %rax, %rax
je 0x7b03
cmpq %r15, %rax
jne 0x7ae8
cmpl $0x0, 0x18(%r14)
jg 0x7b13
movq %r12, %r14
testq %r12, %r12
jne 0x7b13
jmp 0x7bd3
movq %r12, %r14
movl 0x46ae(%rip), %r12d     # 0xc1c8
movl 0x46ab(%rip), %r13d     # 0xc1cc
movq %r14, %rdi
callq 0x8385
movl $0x1, %ebx
testq %rax, %rax
je 0x7bd3
movq %rax, %r15
orl %r13d, %r12d
sarl $0x1f, %r12d
orl $0x3, %r12d
cmpl $0xa, %ebp
leaq 0x19e4(%rip), %rax      # 0x9533
leaq 0x17c2(%rip), %rsi      # 0x9318
cmoveq %rax, %rsi
leaq 0x1df3(%rip), %rdi      # 0x9954
xorl %eax, %eax
callq 0x362c
leaq 0xc(%rsp), %rdx
movl $0x6e66, (%rdx)         # imm = 0x6E66
movq %r15, %rdi
addq $0x18, %rdi
movl 0x98(%r15), %esi
movq 0x6088(%rip), %rax      # 0xdc10
addq $-0xf, %rax
xorl %r9d, %r9d
cmpq %rax, 0xa8(%r15)
setge %r9b
leaq 0x10(%rsp), %rcx
movl %r12d, %r8d
callq 0x83cf
movl 0xb8(%r15), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0xb8(%r15)
movq 0x6051(%rip), %rcx      # 0xdc10
movq %rcx, 0xb0(%r15)
cmpl $0x2, %eax
jl 0x7bd3
movq %r14, %rdi
callq 0x80e9
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq