// File: /workspace/github_c_makefile_star2_O2/jech[P]dht/dht.c
// Function: dht_get_nodes
int
dht_get_nodes(struct sockaddr_in *sin, int *num,
              struct sockaddr_in6 *sin6, int *num6)
{
    int i, j;
    struct bucket *b;
    struct node *n;

    i = 0;

    /* For restoring to work without discarding too many nodes, the list
       must start with the contents of our bucket. */
    b = find_bucket(myid, AF_INET);
    if(b == NULL)
        goto no_ipv4;

    n = b->nodes;
    while(n && i < *num) {
        if(node_good(n)) {
            sin[i] = *(struct sockaddr_in*)&n->ss;
            i++;
        }
        n = n->next;
    }

    b = buckets;
    while(b && i < *num) {
        if(!in_bucket(myid, b)) {
            n = b->nodes;
            while(n && i < *num) {
                if(node_good(n)) {
                    sin[i] = *(struct sockaddr_in*)&n->ss;
                    i++;
                }
                n = n->next;
            }
        }
        b = b->next;
    }

 no_ipv4:

    j = 0;

    b = find_bucket(myid, AF_INET6);
    if(b == NULL)
        goto no_ipv6;

    n = b->nodes;
    while(n && j < *num6) {
        if(node_good(n)) {
            sin6[j] = *(struct sockaddr_in6*)&n->ss;
            j++;
        }
        n = n->next;
    }

    b = buckets6;
    while(b && j < *num6) {
        if(!in_bucket(myid, b)) {
            n = b->nodes;
            while(n && j < *num6) {
                if(node_good(n)) {
                    sin6[j] = *(struct sockaddr_in6*)&n->ss;
                    j++;
                }
                n = n->next;
            }
        }
        b = b->next;
    }

 no_ipv6:

    *num = i;
    *num6 = j;
    return i + j;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
leaq 0x6ac4(%rip), %rdi      # 0xdc30
pushq $0x2
popq %rsi
callq 0x329c
xorl %ebp, %ebp
movl $0x0, %r14d
testq %rax, %rax
je 0x7242
movq %rax, %r13
addq $0x28, %r13
xorl %r14d, %r14d
movq (%r13), %r13
testq %r13, %r13
je 0x71cb
movq 0x8(%rsp), %rax
cmpl (%rax), %r14d
jge 0x71cb
movq %r13, %rdi
callq 0x3956
testl %eax, %eax
je 0x71c2
movslq %r14d, %rax
shlq $0x4, %rax
movups 0x18(%r13), %xmm0
movups %xmm0, (%r12,%rax)
incl %r14d
addq $0xc0, %r13
jmp 0x718f
leaq 0x6a7e(%rip), %r13      # 0xdc50
movq %rbx, 0x10(%rsp)
movq (%r13), %r13
testq %r13, %r13
je 0x7242
movq 0x8(%rsp), %rax
cmpl (%rax), %r14d
jge 0x7242
movq %r13, %rdi
callq 0x7331
testl %eax, %eax
jne 0x7239
leaq 0x28(%r13), %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x7234
movq 0x8(%rsp), %rax
cmpl (%rax), %r14d
jge 0x7234
movq %rbx, %rdi
callq 0x3956
testl %eax, %eax
je 0x722b
movslq %r14d, %rax
shlq $0x4, %rax
movups 0x18(%rbx), %xmm0
movups %xmm0, (%r12,%rax)
incl %r14d
addq $0xc0, %rbx
jmp 0x71fa
movq 0x10(%rsp), %rbx
addq $0xb8, %r13
jmp 0x71d7
leaq 0x69e7(%rip), %rdi      # 0xdc30
pushq $0xa
popq %rsi
callq 0x329c
testq %rax, %rax
je 0x7313
movq %rax, %r12
addq $0x28, %r12
xorl %ebp, %ebp
movq (%r12), %r12
testq %r12, %r12
je 0x72a5
cmpl (%rbx), %ebp
jge 0x72a5
movq %r12, %rdi
callq 0x3956
testl %eax, %eax
je 0x729c
movslq %ebp, %rax
imulq $0x1c, %rax, %rax
movups 0x18(%r12), %xmm0
movups 0x24(%r12), %xmm1
movups %xmm1, 0xc(%r15,%rax)
movups %xmm0, (%r15,%rax)
incl %ebp
addq $0xc0, %r12
jmp 0x7263
leaq 0x69ac(%rip), %r12      # 0xdc58
movq (%r12), %r12
testq %r12, %r12
je 0x7313
cmpl (%rbx), %ebp
jge 0x7313
movq %r12, %rdi
callq 0x7331
testl %eax, %eax
je 0x72ce
addq $0xb8, %r12
jmp 0x72ac
leaq 0x28(%r12), %r13
movq (%r13), %r13
testq %r13, %r13
je 0x72c5
cmpl (%rbx), %ebp
jge 0x72c5
movq %r13, %rdi
callq 0x3956
testl %eax, %eax
je 0x730a
movslq %ebp, %rax
imulq $0x1c, %rax, %rax
movups 0x18(%r13), %xmm0
movups 0x24(%r13), %xmm1
movups %xmm1, 0xc(%r15,%rax)
movups %xmm0, (%r15,%rax)
incl %ebp
addq $0xc0, %r13
jmp 0x72d3
movq 0x8(%rsp), %rax
movl %r14d, (%rax)
movl %ebp, (%rbx)
addl %r14d, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq