// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x1, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpl 0xce0(%rdx), %ecx
movb %al, -0x4d(%rbp)
jge 0x3ec7
cmpl $0x8, -0x20(%rbp)
setl %al
movb %al, -0x4d(%rbp)
movb -0x4d(%rbp), %al
testb $0x1, %al
jne 0x3ed0
jmp 0x3f23
movq -0x8(%rbp), %rax
addq $0x30, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x3, 0xb0(%rax)
jl 0x3ef9
jmp 0x3f18
movq -0x30(%rbp), %rax
cmpl $0x0, 0xe0(%rax)
jne 0x3f0f
movl $0x0, -0x24(%rbp)
jmp 0x3f23
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3ea9
cmpl $0x0, -0x24(%rbp)
je 0x40fe
movq -0x8(%rbp), %rax
movzwl 0x24(%rax), %eax
cmpl $0x0, %eax
jne 0x3f3f
jmp 0x4180
movl $0x1, -0x34(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpl 0xce0(%rdx), %ecx
movb %al, -0x4e(%rbp)
jge 0x3f72
cmpl $0x8, -0x20(%rbp)
setl %al
movb %al, -0x4e(%rbp)
movb -0x4e(%rbp), %al
testb $0x1, %al
jne 0x3f7e
jmp 0x40dd
movq -0x8(%rbp), %rax
addq $0x30, %rax
movslq -0x1c(%rbp), %rcx
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x3, 0xb0(%rax)
jl 0x3faa
jmp 0x40cf
movq -0x40(%rbp), %rax
cmpl $0x0, 0xdc(%rax)
jne 0x3fc5
movq -0x40(%rbp), %rax
movl $0x1, 0xe4(%rax)
movq -0x40(%rbp), %rax
cmpl $0x0, 0xe4(%rax)
jne 0x40c6
movl $0x0, -0x34(%rbp)
leaq 0x8692(%rip), %rdi      # 0xc676
movb $0x0, %al
callq 0x3aa0
leaq -0x4c(%rbp), %rdi
movq -0x8(%rbp), %rax
leaq 0x846c(%rip), %rsi      # 0xc466
movzwl (%rax), %edx
callq 0x9990
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
leaq -0x4c(%rbp), %rdx
movq -0x8(%rbp), %r8
addq $0x10, %r8
movq -0x8(%rbp), %rax
movw 0x24(%rax), %r9w
movq -0x40(%rbp), %r11
addq $0xb4, %r11
movq -0x40(%rbp), %rax
movl 0xdc(%rax), %r10d
movq -0x40(%rbp), %rax
movq 0xa8(%rax), %rax
movq 0xcbc9(%rip), %rcx      # 0x10c10
subq $0xf, %rcx
cmpq %rcx, %rax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl $0x80, %esi
movl $0x4, %ecx
movzwl %r9w, %r9d
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x9c70
movq -0x40(%rbp), %rax
movl 0xb0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xb0(%rax)
movq 0xcb80(%rip), %rcx      # 0x10c10
movq -0x40(%rbp), %rax
movq %rcx, 0xa0(%rax)
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
movzwl 0x18(%rax), %esi
callq 0x4cb0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x40c4
movq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xa090
jmp 0x40c6
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3f54
cmpl $0x0, -0x34(%rbp)
je 0x40e8
jmp 0x4180
jmp 0x40ea
movq 0xcb1f(%rip), %rcx      # 0x10c10
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x41d2
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
addq $0xa, %rax
cmpq 0xcaff(%rip), %rax      # 0x10c10
jl 0x4118
jmp 0x41d2
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xce0(%rcx), %eax
jge 0x416f
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x30, %rsi
movslq -0x1c(%rbp), %rax
imulq $0xe8, %rax, %rax
addq %rax, %rsi
callq 0x7cd0
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x4, -0x20(%rbp)
jl 0x4162
jmp 0x416f
jmp 0x4164
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4126
movq 0xca9a(%rip), %rcx      # 0x10c10
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x41d2
movq -0x8(%rbp), %rax
movl $0x1, 0x28(%rax)
cmpq $0x0, -0x10(%rbp)
je 0x41c3
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %edx
movl $0x4, %esi
movl $0x3, %ecx
cmpl $0x2, %edx
cmovel %ecx, %esi
movq -0x8(%rbp), %rdx
addq $0x10, %rdx
xorl %ecx, %ecx
movl %ecx, %r8d
movq %r8, %rcx
callq *%rax
movq 0xca46(%rip), %rcx      # 0x10c10
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)