// File: /workspace/github_c_makefile_star2_O1/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 0x6014(%rip), %rdi      # 0xdc30
movl $0x2, %esi
callq 0x35d4
xorl %ebp, %ebp
movl $0x0, %r15d
testq %rax, %rax
je 0x7d14
movq 0x28(%rax), %rax
xorl %r15d, %r15d
testq %rax, %rax
je 0x7c94
cmpl (%r14), %r15d
jge 0x7c94
cmpl $0x2, 0xb8(%rax)
jg 0x7c8b
movq 0x5fb8(%rip), %rcx      # 0xdc10
leaq -0x1c20(%rcx), %rdx
cmpq %rdx, 0xa8(%rax)
jl 0x7c8b
addq $-0x384, %rcx           # imm = 0xFC7C
cmpq %rcx, 0xa0(%rax)
jl 0x7c8b
movslq %r15d, %rcx
shlq $0x4, %rcx
movups 0x18(%rax), %xmm0
movups %xmm0, (%r12,%rcx)
incl %r15d
movq 0xc0(%rax), %rax
jmp 0x7c3e
movq 0x5fb5(%rip), %r13      # 0xdc50
testq %r13, %r13
je 0x7d14
cmpl (%r14), %r15d
jge 0x7d14
movq %r13, %rdi
callq 0x7e61
testl %eax, %eax
je 0x7cba
movq 0xb8(%r13), %r13
jmp 0x7c9b
movq 0x28(%r13), %rax
testq %rax, %rax
je 0x7cb1
cmpl (%r14), %r15d
jge 0x7cb1
cmpl $0x2, 0xb8(%rax)
jg 0x7d0b
movq 0x5f38(%rip), %rcx      # 0xdc10
leaq -0x1c20(%rcx), %rdx
cmpq %rdx, 0xa8(%rax)
jl 0x7d0b
addq $-0x384, %rcx           # imm = 0xFC7C
cmpq %rcx, 0xa0(%rax)
jl 0x7d0b
movslq %r15d, %rcx
shlq $0x4, %rcx
movups 0x18(%rax), %xmm0
movups %xmm0, (%r12,%rcx)
incl %r15d
movq 0xc0(%rax), %rax
jmp 0x7cbe
leaq 0x5f15(%rip), %rdi      # 0xdc30
movl $0xa, %esi
callq 0x35d4
testq %rax, %rax
je 0x7e48
movq 0x28(%rax), %rax
testq %rax, %rax
je 0x7da1
movq 0x5ed2(%rip), %rcx      # 0xdc10
leaq -0x1c20(%rcx), %rdx
addq $-0x384, %rcx           # imm = 0xFC7C
xorl %ebp, %ebp
cmpl (%rbx), %ebp
jge 0x7da3
cmpl $0x2, 0xb8(%rax)
jg 0x7d93
cmpq %rdx, 0xa8(%rax)
jl 0x7d93
cmpq %rcx, 0xa0(%rax)
jl 0x7d93
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 0x7d4e
jmp 0x7da3
xorl %ebp, %ebp
movq 0x5eae(%rip), %r12      # 0xdc58
testq %r12, %r12
je 0x7e48
movq 0x5e56(%rip), %rax      # 0xdc10
leaq -0x1c20(%rax), %r13
addq $-0x384, %rax           # imm = 0xFC7C
movq %rax, 0x10(%rsp)
cmpl (%rbx), %ebp
jge 0x7e48
movq %r12, %rdi
callq 0x7e61
testl %eax, %eax
je 0x7deb
movq 0xb8(%r12), %r12
testq %r12, %r12
jne 0x7dcc
jmp 0x7e48
movq 0x28(%r12), %rax
testq %rax, %rax
je 0x7ddc
cmpl (%rbx), %ebp
jge 0x7ddc
cmpl $0x2, 0xb8(%rax)
jg 0x7e3f
cmpq %r13, 0xa8(%rax)
jl 0x7e3f
movq 0x10(%rsp), %rcx
cmpq %rcx, 0xa0(%rax)
jl 0x7e3f
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 0x7df0
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