// File: /workspace/github_c_makefile_star2_O2/jech[P]dht/dht.c
// Function: search_step
static void
search_step(struct search *sr, dht_callback_t *callback, void *closure)
{
    int i, j;
    int all_done = 1;

    /* Check if the first 8 live nodes have replied. */
    j = 0;
    for(i = 0; i < sr->numnodes && j < 8; i++) {
        struct search_node *n = &sr->nodes[i];
        if(n->pinged >= 3)
            continue;
        if(!n->replied) {
            all_done = 0;
            break;
        }
        j++;
    }

    if(all_done) {
        if(sr->port == 0) {
            goto done;
        } else {
            int all_acked = 1;
            j = 0;
            for(i = 0; i < sr->numnodes && j < 8; i++) {
                struct search_node *n = &sr->nodes[i];
                struct node *node;
                unsigned char tid[4];
                if(n->pinged >= 3)
                    continue;
                /* A proposed extension to the protocol consists in
                   omitting the token when storage tables are full.  While
                   I don't think this makes a lot of sense -- just sending
                   a positive reply is just as good --, let's deal with it. */
                if(n->token_len == 0)
                    n->acked = 1;
                if(!n->acked) {
                    all_acked = 0;
                    debugf("Sending announce_peer.\n");
                    make_tid(tid, "ap", sr->tid);
                    send_announce_peer((struct sockaddr*)&n->ss,
                                       sizeof(struct sockaddr_storage),
                                       tid, 4, sr->id, sr->port,
                                       n->token, n->token_len,
                                       n->reply_time >= now.tv_sec - 15);
                    n->pinged++;
                    n->request_time = now.tv_sec;
                    node = find_node(n->id, n->ss.ss_family);
                    if(node) pinged(node, NULL);
                }
                j++;
            }
            if(all_acked)
                goto done;
        }
        sr->step_time = now.tv_sec;
        return;
    }

    if(sr->step_time + DHT_SEARCH_RETRANSMIT >= now.tv_sec)
        return;

    j = 0;
    for(i = 0; i < sr->numnodes; i++) {
        j += search_send_get_peers(sr, &sr->nodes[i]);
        if(j >= DHT_INFLIGHT_QUERIES)
            break;
    }
    sr->step_time = now.tv_sec;
    return;

 done:
    sr->done = 1;
    if(callback)
        (*callback)(closure,
                    sr->af == AF_INET ?
                    DHT_EVENT_SEARCH_DONE : DHT_EVENT_SEARCH_DONE6,
                    sr->id, NULL, 0);
    sr->step_time = now.tv_sec;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdx, %r8
movq %rsi, %r9
movq %rdi, %rbx
movl 0xce0(%rdi), %eax
leaq 0x30(%rdi), %r14
movslq %eax, %rcx
leaq 0xe0(%rdi), %rdx
xorl %esi, %esi
xorl %edi, %edi
cmpq %rcx, %rsi
jge 0x3518
cmpl $0x7, %edi
jg 0x3518
cmpl $0x2, (%rdx)
jg 0x350c
cmpl $0x0, 0x30(%rdx)
je 0x3830
incl %edi
incq %rsi
addq $0xe8, %rdx
jmp 0x34f1
cmpw $0x0, 0x24(%rbx)
je 0x37eb
movq %r8, 0x18(%rsp)
movq %r9, 0x20(%rsp)
leaq 0x10(%rbx), %rcx
movq %rcx, 0x38(%rsp)
leaq 0x48(%rbx), %rbp
pushq $0x1
popq %r13
movl $0xe8, %edx
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq %eax, %rcx
cmpq %rcx, %r15
jge 0x37dc
cmpl $0x7, %r12d
jg 0x37dc
cmpl $0x2, 0x98(%rbp)
jg 0x379e
cmpl $0x0, 0xc4(%rbp)
je 0x378b
cmpl $0x0, 0xcc(%rbp)
jne 0x3795
leaq 0x50d7(%rip), %rdi      # 0x8664
xorl %eax, %eax
callq 0x3324
movzwl (%rbx), %eax
movl %eax, 0xc(%rsp)
movzwl 0x24(%rbx), %ecx
movl 0xc4(%rbp), %r13d
movq 0x90(%rbp), %rax
movq %rax, 0x30(%rsp)
movq 0xa657(%rip), %rax      # 0xdc10
movq %rax, 0x28(%rsp)
movabsq $0x3a303264693a32, %rax # imm = 0x3A303264693A32
movq %rax, 0x45(%rsp)
movabsq $0x693a3264613a3164, %rax # imm = 0x693A3264613A3164
movq %rax, 0x40(%rsp)
movl 0xa65e(%rip), %eax      # 0xdc40
leaq 0x4c(%rsp), %rsi
movl %eax, 0x10(%rsi)
movaps 0xa63f(%rip), %xmm0     # 0xdc30
movups %xmm0, (%rsi)
movabsq $0x3a303268736168, %rax # imm = 0x3A303268736168
movq %rax, 0x1b(%rsi)
movabsq $0x685f6f666e693a39, %rax # imm = 0x685F6F666E693A39
movq %rax, 0x14(%rsi)
movq 0x38(%rsp), %rdx
movl 0x10(%rdx), %eax
movl %eax, 0x32(%rsi)
movups (%rdx), %xmm0
movups %xmm0, 0x22(%rsi)
movl $0x1be, %esi            # imm = 0x1BE
leaq 0x82(%rsp), %rdi
leaq 0x5062(%rip), %rdx      # 0x8698
movl %r13d, %r8d
xorl %eax, %eax
callq 0x2110
testl %eax, %eax
js 0x3747
cmpl $0x1bf, %eax            # imm = 0x1BF
setae %cl
testl %r13d, %r13d
sets %dl
orb %cl, %dl
jne 0x3747
addl $0x42, %eax
leal (%rax,%r13), %ecx
cmpl $0x200, %ecx            # imm = 0x200
ja 0x3747
leaq 0x9c(%rbp), %rsi
movl %eax, %eax
leaq (%rsp,%rax), %rdi
addq $0x40, %rdi
movq %r13, %rdx
movl %ecx, %r13d
callq 0x2200
movl %r13d, %eax
movq %rax, 0x10(%rsp)
leaq (%rsp,%rax), %rdi
addq $0x40, %rdi
movl $0x200, %esi            # imm = 0x200
subl %r13d, %esi
leaq 0x5001(%rip), %rdx      # 0x86ad
pushq $0x4
popq %rcx
xorl %eax, %eax
callq 0x2110
movq 0x10(%rsp), %rcx
testl %eax, %eax
js 0x3747
movl %eax, %eax
addq %rax, %rcx
cmpl $0x200, %ecx            # imm = 0x200
ja 0x3747
cmpl $0x1fc, %ecx            # imm = 0x1FC
ja 0x3747
leal 0x4(%rcx), %edx
movl 0xc(%rsp), %eax
shll $0x10, %eax
orl $0x7061, %eax           # imm = 0x7061
movl %eax, 0x40(%rsp,%rcx)
cmpb $0x1, 0xa58a(%rip)      # 0xdc7c
jne 0x3717
cmpl $0x1f3, %ecx            # imm = 0x1F3
ja 0x3747
movl %edx, %eax
leal 0xd(%rcx), %edx
movb 0xa571(%rip), %cl       # 0xdc78
movb %cl, 0x48(%rsp,%rax)
movq 0xa55e(%rip), %rcx      # 0xdc70
movq %rcx, 0x40(%rsp,%rax)
movl %edx, %eax
leaq (%rsp,%rax), %rdi
addq $0x40, %rdi
movl $0x200, %esi            # imm = 0x200
subl %edx, %esi
movl %edx, %r13d
leaq 0x4f96(%rip), %rdx      # 0x86c8
xorl %eax, %eax
callq 0x2110
testl %eax, %eax
js 0x3747
addl %r13d, %eax
cmpl $0x200, %eax            # imm = 0x200
jbe 0x37ac
callq 0x2060
movl $0x1c, (%rax)
incl 0x98(%rbp)
movq 0xa4b1(%rip), %rax      # 0xdc10
movq %rax, 0x88(%rbp)
movzwl (%rbp), %esi
movq %r14, %rdi
callq 0x3f70
xorl %r13d, %r13d
testq %rax, %rax
je 0x3784
movq %rax, %rdi
xorl %esi, %esi
callq 0x74d5
movl $0xe8, %edx
jmp 0x3795
movl $0x1, 0xcc(%rbp)
incl %r12d
movl 0xce0(%rbx), %eax
incq %r15
addq %rdx, %rbp
addq %rdx, %r14
jmp 0x3549
movq 0x28(%rsp), %rcx
addq $-0xf, %rcx
xorl %edx, %edx
cmpq %rcx, 0x30(%rsp)
setl %dl
movl %eax, %esi
shll $0xb, %edx
leaq 0x40(%rsp), %rdi
movq %rbp, %rcx
movl $0x80, %r8d
callq 0x7516
jmp 0x3752
testl %r13d, %r13d
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r8
je 0x3813
movl $0x1, 0x28(%rbx)
testq %r9, %r9
je 0x3813
xorl %esi, %esi
cmpl $0x2, 0x4(%rbx)
setne %sil
addl $0x3, %esi
leaq 0x10(%rbx), %rdx
movq %r8, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq *%r9
movq 0xa3f6(%rip), %rax      # 0xdc10
movq %rax, 0x8(%rbx)
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rbx), %rax
addq $0xa, %rax
cmpq 0xa3d1(%rip), %rax      # 0xdc10
jge 0x381e
xorl %ebp, %ebp
pushq $-0x1
popq %r15
movslq 0xce0(%rbx), %rax
incq %r15
cmpq %rax, %r15
jge 0x3813
leaq 0xe8(%r14), %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x63da
addl %eax, %ebp
movq %r12, %r14
cmpl $0x4, %ebp
jb 0x3847
jmp 0x3813