// File: /workspace/github_c_makefile_star2_O3/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
movslq 0xce0(%rdi), %rax
testq %rax, %rax
jle 0x3b24
leaq 0x30(%rbx), %r12
leaq 0xe0(%rbx), %rcx
xorl %edx, %edx
movl $0x1, %esi
cmpl $0x2, (%rcx)
jg 0x37e9
cmpl $0x0, 0x30(%rcx)
je 0x3ad3
incl %edx
cmpq %rax, %rsi
jae 0x37fd
addq $0xe8, %rcx
incq %rsi
cmpl $0x8, %edx
jl 0x37d8
testl %eax, %eax
setle %cl
cmpw $0x0, 0x24(%rbx)
sete %dl
orb %cl, %dl
jne 0x3b24
movq %r8, 0x18(%rsp)
movq %r9, 0x20(%rsp)
leaq 0x30(%rbx), %r12
leaq 0x10(%rbx), %rcx
movq %rcx, 0x38(%rsp)
leaq 0x48(%rbx), %rbp
movl $0x1, %r13d
movl $0x1, %r15d
movl $0xe8, %edx
xorl %r14d, %r14d
cmpl $0x2, 0x98(%rbp)
jg 0x3a82
cmpl $0x0, 0xc4(%rbp)
je 0x3a6f
cmpl $0x0, 0xcc(%rbp)
jne 0x3a79
leaq 0x5df5(%rip), %rdi      # 0x9664
xorl %eax, %eax
callq 0x362c
movzwl (%rbx), %eax
movl %eax, 0xc(%rsp)
movzwl 0x24(%rbx), %ecx
movl 0xc4(%rbp), %r13d
movq 0x90(%rbp), %rax
movq %rax, 0x30(%rsp)
movq 0xa375(%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 0xa37c(%rip), %eax      # 0xdc40
leaq 0x4c(%rsp), %rsi
movl %eax, 0x10(%rsi)
movaps 0xa35d(%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 0x5d80(%rip), %rdx      # 0x9698
movl %r13d, %r8d
xorl %eax, %eax
callq 0x2110
testl %eax, %eax
js 0x3a2b
cmpl $0x1bf, %eax            # imm = 0x1BF
setae %cl
testl %r13d, %r13d
sets %dl
orb %cl, %dl
jne 0x3a2b
addl $0x42, %eax
leal (%rax,%r13), %ecx
cmpl $0x200, %ecx            # imm = 0x200
ja 0x3a2b
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 0x5d1f(%rip), %rdx      # 0x96ad
movl $0x4, %ecx
xorl %eax, %eax
callq 0x2110
movq 0x10(%rsp), %rcx
testl %eax, %eax
js 0x3a2b
movl %eax, %eax
addq %rax, %rcx
cmpl $0x200, %ecx            # imm = 0x200
ja 0x3a2b
cmpl $0x1fc, %ecx            # imm = 0x1FC
ja 0x3a2b
leal 0x4(%rcx), %edx
movl 0xc(%rsp), %eax
shll $0x10, %eax
orl $0x7061, %eax           # imm = 0x7061
movl %eax, 0x40(%rsp,%rcx)
cmpb $0x1, 0xa2a6(%rip)      # 0xdc7c
jne 0x39fb
cmpl $0x1f3, %ecx            # imm = 0x1F3
ja 0x3a2b
movl %edx, %eax
leal 0xd(%rcx), %edx
movb 0xa28d(%rip), %cl       # 0xdc78
movb %cl, 0x48(%rsp,%rax)
movq 0xa27a(%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 0x5cb2(%rip), %rdx      # 0x96c8
xorl %eax, %eax
callq 0x2110
testl %eax, %eax
js 0x3a2b
addl %r13d, %eax
cmpl $0x200, %eax            # imm = 0x200
jbe 0x3aa3
callq 0x2060
movl $0x1c, (%rax)
incl 0x98(%rbp)
movq 0xa1cd(%rip), %rax      # 0xdc10
movq %rax, 0x88(%rbp)
movzwl (%rbp), %esi
movq %r12, %rdi
callq 0x42f4
xorl %r13d, %r13d
testq %rax, %rax
je 0x3a68
movq %rax, %rdi
xorl %esi, %esi
callq 0x8002
movl $0xe8, %edx
jmp 0x3a79
movl $0x1, 0xcc(%rbp)
incl %r14d
movl 0xce0(%rbx), %eax
movslq %eax, %rcx
cmpq %rcx, %r15
jge 0x3b15
addq %rdx, %rbp
addq %rdx, %r12
incq %r15
cmpl $0x8, %r14d
jl 0x3841
jmp 0x3b15
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 0x8043
jmp 0x3a36
movq 0x8(%rbx), %rax
addq $0xa, %rax
cmpq 0xa12e(%rip), %rax      # 0xdc10
jge 0x3b57
xorl %r14d, %r14d
xorl %eax, %eax
movl %eax, %ebp
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6809
addl %ebp, %eax
cmpl $0x4, %eax
jae 0x3b4c
incq %r14
movslq 0xce0(%rbx), %rcx
addq $0xe8, %r12
cmpq %rcx, %r14
jl 0x3ae9
jmp 0x3b4c
testl %r13d, %r13d
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r8
je 0x3b4c
movl $0x1, 0x28(%rbx)
testq %r9, %r9
je 0x3b4c
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 0xa0bd(%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