// File: /workspace/github_c_makefile_star2_O3/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, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, %r12
leaq 0x6029(%rip), %rdi      # 0xdc30
movl $0x2, %esi
callq 0x3593
xorl %ebp, %ebp
movl $0x0, %r15d
testq %rax, %rax
je 0x7cff
movq 0x28(%rax), %rax
xorl %r15d, %r15d
testq %rax, %rax
je 0x7c7f
cmpl (%r14), %r15d
jge 0x7c7f
cmpl $0x2, 0xb8(%rax)
jg 0x7c76
movq 0x5fcd(%rip), %rcx      # 0xdc10
leaq -0x1c20(%rcx), %rdx
cmpq %rdx, 0xa8(%rax)
jl 0x7c76
addq $-0x384, %rcx           # imm = 0xFC7C
cmpq %rcx, 0xa0(%rax)
jl 0x7c76
movslq %r15d, %rcx
shlq $0x4, %rcx
movups 0x18(%rax), %xmm0
movups %xmm0, (%r12,%rcx)
incl %r15d
movq 0xc0(%rax), %rax
jmp 0x7c29
movq 0x5fca(%rip), %r13      # 0xdc50
testq %r13, %r13
je 0x7cff
cmpl (%r14), %r15d
jge 0x7cff
movq %r13, %rdi
callq 0x7e4c
testl %eax, %eax
je 0x7ca5
movq 0xb8(%r13), %r13
jmp 0x7c86
movq 0x28(%r13), %rax
testq %rax, %rax
je 0x7c9c
cmpl (%r14), %r15d
jge 0x7c9c
cmpl $0x2, 0xb8(%rax)
jg 0x7cf6
movq 0x5f4d(%rip), %rcx      # 0xdc10
leaq -0x1c20(%rcx), %rdx
cmpq %rdx, 0xa8(%rax)
jl 0x7cf6
addq $-0x384, %rcx           # imm = 0xFC7C
cmpq %rcx, 0xa0(%rax)
jl 0x7cf6
movslq %r15d, %rcx
shlq $0x4, %rcx
movups 0x18(%rax), %xmm0
movups %xmm0, (%r12,%rcx)
incl %r15d
movq 0xc0(%rax), %rax
jmp 0x7ca9
leaq 0x5f2a(%rip), %rdi      # 0xdc30
movl $0xa, %esi
callq 0x3593
testq %rax, %rax
je 0x7e33
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x7d8c
movq 0x5ee7(%rip), %rcx      # 0xdc10
leaq -0x1c20(%rcx), %rdx
addq $-0x384, %rcx           # imm = 0xFC7C
xorl %ebp, %ebp
cmpl (%rbx), %ebp
jge 0x7d8e
cmpl $0x2, 0xb8(%rax)
jg 0x7d7e
cmpq %rdx, 0xa8(%rax)
jl 0x7d7e
cmpq %rcx, 0xa0(%rax)
jl 0x7d7e
movslq %ebp, %rsi
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
movups 0x18(%rax), %xmm0
movups 0x24(%rax), %xmm1
movq 0x8(%rsp), %rsi
movups %xmm1, 0xc(%rsi,%rdi)
movups %xmm0, (%rsi,%rdi)
incl %ebp
movq 0xc0(%rax), %rax
testq %rax, %rax
jne 0x7d39
jmp 0x7d8e
xorl %ebp, %ebp
movq 0x5ec3(%rip), %r12      # 0xdc58
testq %r12, %r12
je 0x7e33
movq 0x5e6b(%rip), %rax      # 0xdc10
leaq -0x1c20(%rax), %r13
addq $-0x384, %rax           # imm = 0xFC7C
movq %rax, 0x10(%rsp)
cmpl (%rbx), %ebp
jge 0x7e33
movq %r12, %rdi
callq 0x7e4c
testl %eax, %eax
je 0x7dd6
movq 0xb8(%r12), %r12
testq %r12, %r12
jne 0x7db7
jmp 0x7e33
movq 0x28(%r12), %rax
testq %rax, %rax
je 0x7dc7
cmpl (%rbx), %ebp
jge 0x7dc7
cmpl $0x2, 0xb8(%rax)
jg 0x7e2a
cmpq %r13, 0xa8(%rax)
jl 0x7e2a
movq 0x10(%rsp), %rcx
cmpq %rcx, 0xa0(%rax)
jl 0x7e2a
movslq %ebp, %rcx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x18(%rax), %xmm0
movups 0x24(%rax), %xmm1
movq 0x8(%rsp), %rcx
movups %xmm1, 0xc(%rcx,%rdx)
movups %xmm0, (%rcx,%rdx)
incl %ebp
movq 0xc0(%rax), %rax
jmp 0x7ddb
movl %r15d, (%r14)
movl %ebp, (%rbx)
addl %r15d, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq