// File: /workspace/github_c_makefile_star2_O2/jech[P]dht/dht.c
// Function: insert_search_node
static struct search_node*
insert_search_node(const unsigned char *id,
                   const struct sockaddr *sa, int salen,
                   struct search *sr, int replied,
                   unsigned char *token, int token_len)
{
    struct search_node *n;
    int i, j;

    if(sa->sa_family != sr->af) {
        debugf("Attempted to insert node in the wrong family.\n");
        return NULL;
    }

    for(i = 0; i < sr->numnodes; i++) {
        if(id_cmp(id, sr->nodes[i].id) == 0) {
            n = &sr->nodes[i];
            goto found;
        }
        if(xorcmp(id, sr->nodes[i].id, sr->id) < 0)
            break;
    }

    if(i == SEARCH_NODES)
        return NULL;

    if(sr->numnodes < SEARCH_NODES)
        sr->numnodes++;

    for(j = sr->numnodes - 1; j > i; j--) {
        sr->nodes[j] = sr->nodes[j - 1];
    }

    n = &sr->nodes[i];

    memset(n, 0, sizeof(struct search_node));
    memcpy(n->id, id, 20);

found:
    memcpy(&n->ss, sa, salen);
    n->sslen = salen;

    if(replied) {
        n->replied = 1;
        n->reply_time = now.tv_sec;
        n->request_time = 0;
        n->pinged = 0;
    }
    if(token) {
        if(token_len >= 40) {
            debugf("Eek!  Overlong token.\n");
        } else {
            memcpy(n->token, token, token_len);
            n->token_len = token_len;
        }
    }

    return n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movzwl (%rsi), %eax
cmpl %eax, 0x4(%rcx)
jne 0x6296
movq %rcx, %rbx
movq %rdi, %r13
movl %edx, 0x4(%rsp)
movq %rsi, 0x18(%rsp)
movl %r8d, 0x8(%rsp)
movq %r9, 0x20(%rsp)
movl 0xce0(%rcx), %eax
leaq 0x30(%rcx), %r12
leaq 0x10(%rcx), %rbp
xorl %r15d, %r15d
testl %eax, %eax
movl $0x0, %r14d
movl %eax, 0xc(%rsp)
cmovgl %eax, %r14d
movq %r12, 0x10(%rsp)
cmpq %r15, %r14
je 0x62af
movq %r13, %rdi
movq %r12, %rsi
callq 0x33d2
testl %eax, %eax
je 0x633f
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x77fa
testl %eax, %eax
js 0x62ac
incq %r15
addq $0xe8, %r12
jmp 0x6260
leaq 0x25bd(%rip), %rdi      # 0x885a
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x3324
jmp 0x63c8
movl %r15d, %r14d
cmpl $0xe, %r14d
movl 0xc(%rsp), %eax
jne 0x62c1
xorl %r12d, %r12d
jmp 0x63c8
cmpl $0xd, %eax
jg 0x62ce
incl %eax
movl %eax, 0xce0(%rbx)
movslq %eax, %r15
movslq %r14d, %r12
imulq $0xe8, %r15, %rax
leaq (%rax,%rbx), %rdi
addq $-0xb8, %rdi
decq %r15
cmpq %r12, %r15
jle 0x630a
leaq -0xe8(%rdi), %rbx
movl $0xe8, %edx
movq %rbx, %rsi
callq 0x2200
decq %r15
movq %rbx, %rdi
jmp 0x62e9
movl %r14d, %eax
imulq $0xe8, %rax, %rbx
movq 0x10(%rsp), %r14
leaq (%r14,%rbx), %r12
movl $0xe8, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2140
movups (%r13), %xmm0
movups %xmm0, (%r14,%rbx)
movl 0x10(%r13), %eax
movl %eax, 0x10(%r14,%rbx)
leaq 0x18(%r12), %rdi
movslq 0x4(%rsp), %rbx
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
callq 0x2200
movl %ebx, 0x98(%r12)
cmpl $0x0, 0x8(%rsp)
movq 0x20(%rsp), %rsi
je 0x6397
movl $0x1, 0xe0(%r12)
movq 0x7893(%rip), %rax      # 0xdc10
movq %rax, 0xa8(%r12)
andq $0x0, 0xa0(%r12)
andl $0x0, 0xb0(%r12)
testq %rsi, %rsi
movl 0x60(%rsp), %ebx
je 0x63c8
cmpl $0x28, %ebx
jl 0x63b1
leaq 0x24dd(%rip), %rdi      # 0x8889
jmp 0x62a0
leaq 0xb4(%r12), %rdi
movl %ebx, %edx
callq 0x2200
movl %ebx, 0xdc(%r12)
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq