// File: /workspace/github_c_makefile_star2_O1/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, %r10
movq %rsi, %r9
movq %rdi, %rbx
movslq 0xce0(%rdi), %rcx
xorl %eax, %eax
testq %rcx, %rcx
jle 0x384c
leaq 0x110(%rbx), %rdx
movl $0x1, %esi
movl $0x1, %edi
xorl %r8d, %r8d
cmpl $0x2, -0x30(%rdx)
jg 0x382e
cmpl $0x0, (%rdx)
je 0x3829
incl %eax
xorl %r8d, %r8d
jmp 0x382e
movb $0x1, %r8b
xorl %esi, %esi
testb %r8b, %r8b
jne 0x3847
cmpq %rcx, %rdi
jae 0x3847
addq $0xe8, %rdx
incq %rdi
cmpl $0x7, %eax
jle 0x3814
testl %esi, %esi
sete %al
testb %al, %al
je 0x38ae
movq 0x8(%rbx), %rax
addq $0xa, %rax
cmpq 0xa3b1(%rip), %rax      # 0xdc10
jge 0x3bbd
cmpl $0x0, 0xce0(%rbx)
jle 0x3bb2
leaq 0x30(%rbx), %r14
xorl %r15d, %r15d
xorl %eax, %eax
movl %eax, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0x685f
addl %ebp, %eax
cmpl $0x4, %eax
jae 0x3bb2
incq %r15
movslq 0xce0(%rbx), %rcx
addq $0xe8, %r14
cmpq %rcx, %r15
jl 0x387b
jmp 0x3bb2
cmpw $0x0, 0x24(%rbx)
je 0x3b8a
cmpl $0x0, 0xce0(%rbx)
jle 0x3b8a
movq %r10, 0x18(%rsp)
movq %r9, 0x20(%rsp)
leaq 0x30(%rbx), %r12
leaq 0x10(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x48(%rbx), %rbp
movl $0x1, %r13d
movl $0x1, %r15d
movl $0xe8, %ecx
xorl %r14d, %r14d
cmpl $0x2, 0x98(%rbp)
jg 0x3b2a
cmpl $0x0, 0xc4(%rbp)
jne 0x3915
movl $0x1, 0xcc(%rbp)
cmpl $0x0, 0xcc(%rbp)
jne 0x3b27
leaq 0x5d4b(%rip), %rdi      # 0x9674
xorl %eax, %eax
callq 0x366b
movzwl (%rbx), %eax
movl %eax, 0xc(%rsp)
movzwl 0x24(%rbx), %ecx
movl 0xc4(%rbp), %r13d
movq 0x90(%rbp), %rax
movq %rax, 0x30(%rsp)
movq 0xa2bb(%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 0xa2c2(%rip), %eax      # 0xdc40
leaq 0x4c(%rsp), %rsi
movl %eax, 0x10(%rsi)
movaps 0xa2a3(%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 0x5cd6(%rip), %rdx      # 0x96a8
movl %r13d, %r8d
xorl %eax, %eax
callq 0x2110
testl %eax, %eax
js 0x3ae5
cmpl $0x1bf, %eax            # imm = 0x1BF
setge %cl
testl %r13d, %r13d
sets %dl
orb %cl, %dl
jne 0x3ae5
addl $0x42, %eax
leal (%rax,%r13), %ecx
cmpl $0x200, %ecx            # imm = 0x200
jg 0x3ae5
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 0x5c75(%rip), %rdx      # 0x96bd
movl $0x4, %ecx
xorl %eax, %eax
callq 0x2110
movq 0x10(%rsp), %rcx
testl %eax, %eax
js 0x3ae5
movl %eax, %eax
addq %rax, %rcx
cmpl $0x200, %ecx            # imm = 0x200
jg 0x3ae5
cmpl $0x1fc, %ecx            # imm = 0x1FC
jg 0x3ae5
leal 0x4(%rcx), %edx
movl 0xc(%rsp), %eax
shll $0x10, %eax
orl $0x7061, %eax           # imm = 0x7061
movl %eax, 0x40(%rsp,%rcx)
cmpb $0x1, 0xa1ec(%rip)      # 0xdc7c
jne 0x3ab5
cmpl $0x1f3, %ecx            # imm = 0x1F3
ja 0x3ae5
movl %edx, %eax
leal 0xd(%rcx), %edx
movb 0xa1d3(%rip), %cl       # 0xdc78
movb %cl, 0x48(%rsp,%rax)
movq 0xa1c0(%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 0x5c08(%rip), %rdx      # 0x96d8
xorl %eax, %eax
callq 0x2110
testl %eax, %eax
js 0x3ae5
addl %r13d, %eax
cmpl $0x200, %eax            # imm = 0x200
jle 0x3b4b
callq 0x2060
movl $0x1c, (%rax)
incl 0x98(%rbp)
movq 0xa113(%rip), %rax      # 0xdc10
movq %rax, 0x88(%rbp)
movzwl (%rbp), %esi
movq %r12, %rdi
callq 0x4354
xorl %r13d, %r13d
testq %rax, %rax
je 0x3b22
movq %rax, %rdi
xorl %esi, %esi
callq 0x8017
movl $0xe8, %ecx
incl %r14d
movslq 0xce0(%rbx), %rax
cmpq %rax, %r15
jge 0x3b7b
addq %rcx, %rbp
addq %rcx, %r12
incq %r15
cmpl $0x8, %r14d
jl 0x38f5
jmp 0x3b7b
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 0x8058
jmp 0x3af0
testl %r13d, %r13d
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r10
je 0x3bb2
movl $0x1, 0x28(%rbx)
testq %r9, %r9
je 0x3bb2
xorl %esi, %esi
cmpl $0x2, 0x4(%rbx)
setne %sil
addl $0x3, %esi
leaq 0x10(%rbx), %rdx
movq %r10, %rdi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq *%r9
movq 0xa057(%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