// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movzwl (%rsi), %eax
cmpl %eax, 0x4(%rcx)
jne 0x66f3
movq %r9, %r14
movl %r8d, %r15d
movq %rcx, %rbx
movq %rdi, %r13
movslq 0xce0(%rcx), %rax
testq %rax, %rax
jle 0x6709
leaq 0x30(%rbx), %r12
xorl %ebp, %ebp
movdqu (%r13), %xmm0
movd 0x10(%r13), %xmm1
movq %r12, %rcx
imulq $0xe8, %rbp, %r8
movdqu (%r12,%r8), %xmm2
pcmpeqb %xmm0, %xmm2
movd 0x10(%r12,%r8), %xmm3
pcmpeqb %xmm1, %xmm3
pand %xmm2, %xmm3
pmovmskb %xmm3, %edi
cmpl $0xffff, %edi           # imm = 0xFFFF
je 0x67c6
xorl %r11d, %r11d
movb (%r13,%r11), %dil
movb (%rcx,%r11), %r8b
cmpb %r8b, %dil
je 0x66c6
movb 0x10(%rbx,%r11), %r10b
movl %r10d, %r9d
xorb %dil, %r9b
xorb %r8b, %r10b
cmpb %r10b, %r9b
movl $0x0, %r9d
sbbl %r9d, %r9d
orl $0x1, %r9d
cmpb %r8b, %dil
jne 0x66d7
incq %r11
cmpq $0x14, %r11
jne 0x669a
xorl %r9d, %r9d
testl %r9d, %r9d
js 0x670b
incq %rbp
addq $0xe8, %rcx
cmpq %rax, %rbp
jne 0x6667
movl %eax, %ebp
jmp 0x670b
leaq 0x3170(%rip), %rdi      # 0x986a
xorl %r12d, %r12d
xorl %eax, %eax
callq 0x366b
jmp 0x684d
xorl %ebp, %ebp
cmpl $0xe, %ebp
jne 0x6718
xorl %r12d, %r12d
jmp 0x684d
movl %r15d, 0x4(%rsp)
movq %r14, 0x10(%rsp)
cmpl $0xd, %eax
jg 0x672f
incl %eax
movl %eax, 0xce0(%rbx)
movl %edx, (%rsp)
movq %rsi, 0x8(%rsp)
movslq 0xce0(%rbx), %r15
leal -0x1(%r15), %eax
cmpl %ebp, %eax
jle 0x677d
movslq %ebp, %r14
imulq $0xe8, %r15, %rax
decq %r15
leaq (%rax,%rbx), %rdi
addq $-0xb8, %rdi
leaq -0xe8(%rdi), %r12
movl $0xe8, %edx
movq %r12, %rsi
callq 0x2200
decq %r15
movq %r12, %rdi
cmpq %r14, %r15
jg 0x675e
movl %ebp, %eax
imulq $0xe8, %rax, %rax
leaq (%rbx,%rax), %r12
addq $0x30, %r12
movl $0xe8, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x2140
movdqu (%r13), %xmm0
movdqu %xmm0, (%r12)
movl 0x10(%r13), %eax
movl %eax, 0x10(%r12)
movq 0x10(%rsp), %r14
movl 0x4(%rsp), %r15d
movq 0x8(%rsp), %rsi
movl (%rsp), %edx
jmp 0x67c9
addq %r8, %r12
leaq 0x18(%r12), %rdi
movslq %edx, %rbx
movq %rbx, %rdx
callq 0x2200
movl %ebx, 0x98(%r12)
testl %r15d, %r15d
je 0x6819
movl $0x1, 0xe0(%r12)
movq 0x7417(%rip), %rax      # 0xdc10
movq %rax, 0xa8(%r12)
movq $0x0, 0xa0(%r12)
movl $0x0, 0xb0(%r12)
testq %r14, %r14
je 0x684d
movl 0x50(%rsp), %ebx
cmpl $0x28, %ebx
jl 0x6833
leaq 0x306b(%rip), %rdi      # 0x9899
jmp 0x66fd
leaq 0xb4(%r12), %rdi
movl %ebx, %edx
movq %r14, %rsi
callq 0x2200
movl %ebx, 0xdc(%r12)
movq %r12, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq