// File: /workspace/github_c_makefile_star2_O1/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 0x61bf(%rip), %rdi      # 0xdc30
movl %ebp, %esi
callq 0x35d4
xorl %ebx, %ebx
testq %rax, %rax
je 0x7be8
movq %rax, %r15
movl 0x61b4(%rip), %eax      # 0xdc40
movl %eax, 0x20(%rsp)
movaps 0x6199(%rip), %xmm0     # 0xdc30
movaps %xmm0, 0x10(%rsp)
callq 0x2230
movb %al, 0x23(%rsp)
cmpq $0x0, 0xb8(%r15)
movq %r15, %r14
je 0x7acc
cmpl $0x0, 0x18(%r15)
je 0x7ac5
callq 0x2230
movq %r15, %r14
testb $0x7, %al
jne 0x7acc
movq 0xb8(%r15), %r14
cmpl $0x0, 0x18(%r14)
je 0x7adc
callq 0x2230
testb $0x7, %al
jne 0x7b1f
cmpl $0x2, (%r15)
leaq 0x6169(%rip), %rax      # 0xdc50
leaq 0x616a(%rip), %rcx      # 0xdc58
cmoveq %rax, %rcx
movq (%rcx), %rcx
cmpq %r15, %rcx
je 0x7b10
movq %rcx, %rax
movq 0xb8(%rcx), %rcx
testq %rcx, %rcx
je 0x7b10
cmpq %r15, %rcx
jne 0x7afa
jmp 0x7b12
xorl %eax, %eax
testq %rax, %rax
je 0x7b1f
cmpl $0x0, 0x18(%rax)
cmovgq %rax, %r14
testq %r14, %r14
je 0x7be8
movl 0x4699(%rip), %r12d     # 0xc1c8
movl 0x4696(%rip), %r13d     # 0xc1cc
movq %r14, %rdi
callq 0x8373
movl $0x1, %ebx
testq %rax, %rax
je 0x7be8
movq %rax, %r15
orl %r13d, %r12d
sarl $0x1f, %r12d
orl $0x3, %r12d
cmpl $0xa, %ebp
leaq 0x19df(%rip), %rax      # 0x9543
leaq 0x17bd(%rip), %rsi      # 0x9328
cmoveq %rax, %rsi
leaq 0x1dee(%rip), %rdi      # 0x9964
xorl %eax, %eax
callq 0x366b
leaq 0xc(%rsp), %rdx
movl $0x6e66, (%rdx)         # imm = 0x6E66
movq %r15, %rdi
addq $0x18, %rdi
movl 0x98(%r15), %esi
movq 0x6073(%rip), %rax      # 0xdc10
addq $-0xf, %rax
xorl %r9d, %r9d
cmpq %rax, 0xa8(%r15)
setge %r9b
leaq 0x10(%rsp), %rcx
movl %r12d, %r8d
callq 0x83bd
movl 0xb8(%r15), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0xb8(%r15)
movq 0x603c(%rip), %rcx      # 0xdc10
movq %rcx, 0xb0(%r15)
cmpl $0x2, %eax
jl 0x7be8
movq %r14, %rdi
callq 0x80ff
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq