// File: /workspace/github_c_makefile_star2_O3/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 0x66a8
movq %r9, %r14
movl %r8d, %r15d
movq %rcx, %rbx
movq %rdi, %r12
movslq 0xce0(%rcx), %rax
testq %rax, %rax
jle 0x66b7
leaq 0x30(%rbx), %r13
xorl %ebp, %ebp
movdqu (%r12), %xmm0
movd 0x10(%r12), %xmm1
movq %r13, %rcx
imulq $0xe8, %rbp, %r8
movdqu (%r13,%r8), %xmm2
pcmpeqb %xmm0, %xmm2
movd 0x10(%r13,%r8), %xmm3
pcmpeqb %xmm1, %xmm3
pand %xmm2, %xmm3
pmovmskb %xmm3, %edi
cmpl $0xffff, %edi           # imm = 0xFFFF
je 0x675d
xorl %r9d, %r9d
movb (%r12,%r9), %r8b
movb (%rcx,%r9), %dil
cmpb %dil, %r8b
jne 0x6676
incq %r9
cmpq $0x14, %r9
jne 0x665e
jmp 0x6686
movb 0x10(%rbx,%r9), %r9b
xorb %r9b, %r8b
xorb %r9b, %dil
cmpb %dil, %r8b
jb 0x6697
incq %rbp
addq $0xe8, %rcx
cmpq %rax, %rbp
jne 0x662a
movl %eax, %ebp
cmpl $0xe, %ebp
jne 0x67f2
xorl %r13d, %r13d
jmp 0x67c6
leaq 0x31ab(%rip), %rdi      # 0x985a
xorl %r13d, %r13d
jmp 0x67bf
xorl %ebp, %ebp
movl %r15d, (%rsp)
movq %r14, 0x8(%rsp)
incl %eax
movl %eax, 0xce0(%rbx)
movl %edx, 0x4(%rsp)
movq %rsi, 0x10(%rsp)
leal -0x1(%rax), %ecx
cmpl %ebp, %ecx
jle 0x6714
movslq %eax, %r15
movslq %ebp, %r14
imulq $0xe8, %r15, %rax
decq %r15
leaq (%rax,%rbx), %rdi
addq $-0xb8, %rdi
leaq -0xe8(%rdi), %r13
movl $0xe8, %edx
movq %r13, %rsi
callq 0x2200
decq %r15
movq %r13, %rdi
cmpq %r14, %r15
jg 0x66f5
movl %ebp, %eax
imulq $0xe8, %rax, %rax
leaq (%rbx,%rax), %r13
addq $0x30, %r13
movl $0xe8, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x2140
movdqu (%r12), %xmm0
movdqu %xmm0, (%r13)
movl 0x10(%r12), %eax
movl %eax, 0x10(%r13)
movq 0x8(%rsp), %r14
movl (%rsp), %r15d
movq 0x10(%rsp), %rsi
movl 0x4(%rsp), %edx
jmp 0x6760
addq %r8, %r13
leaq 0x18(%r13), %rdi
movslq %edx, %rbx
movq %rbx, %rdx
callq 0x2200
movl %ebx, 0x98(%r13)
testl %r15d, %r15d
je 0x67aa
movl $0x1, 0xe0(%r13)
movq 0x7483(%rip), %rax      # 0xdc10
movq %rax, 0xa8(%r13)
movq $0x0, 0xa0(%r13)
movl $0x0, 0xb0(%r13)
testq %r14, %r14
je 0x67c6
movl 0x50(%rsp), %ebx
cmpl $0x28, %ebx
jl 0x67d8
leaq 0x30ca(%rip), %rdi      # 0x9889
xorl %eax, %eax
callq 0x362c
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb4(%r13), %rdi
movl %ebx, %edx
movq %r14, %rsi
callq 0x2200
movl %ebx, 0xdc(%r13)
jmp 0x67c6
cmpl $0xd, %eax
jle 0x66b9
movl %r15d, (%rsp)
movq %r14, 0x8(%rsp)
jmp 0x66ca