// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rax
movzwl (%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x7a9d
leaq 0x4de3(%rip), %rdi      # 0xc86c
movb $0x0, %al
callq 0x3aa0
movq $0x0, -0x8(%rbp)
jmp 0x7cbf
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0xce0(%rcx), %eax
jge 0x7b38
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x30, %rsi
movslq -0x44(%rbp), %rax
imulq $0xe8, %rax, %rax
addq %rax, %rsi
callq 0x3b70
cmpl $0x0, %eax
jne 0x7afa
movq -0x28(%rbp), %rax
addq $0x30, %rax
movslq -0x44(%rbp), %rcx
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
jmp 0x7c0e
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x30, %rsi
movslq -0x44(%rbp), %rax
imulq $0xe8, %rax, %rax
addq %rax, %rsi
movq -0x28(%rbp), %rdx
addq $0x10, %rdx
callq 0xa930
cmpl $0x0, %eax
jge 0x7b28
jmp 0x7b38
jmp 0x7b2a
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x7aa4
cmpl $0xe, -0x44(%rbp)
jne 0x7b4b
movq $0x0, -0x8(%rbp)
jmp 0x7cbf
movq -0x28(%rbp), %rax
cmpl $0xe, 0xce0(%rax)
jge 0x7b6b
movq -0x28(%rbp), %rax
movl 0xce0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xce0(%rax)
movq -0x28(%rbp), %rax
movl 0xce0(%rax), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x7bc8
movq -0x28(%rbp), %rdi
addq $0x30, %rdi
movslq -0x48(%rbp), %rax
imulq $0xe8, %rax, %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
addq $0x30, %rsi
movl -0x48(%rbp), %eax
subl $0x1, %eax
cltq
imulq $0xe8, %rax, %rax
addq %rax, %rsi
movl $0xe8, %edx
callq 0x2200
movl -0x48(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x7b7b
movq -0x28(%rbp), %rax
addq $0x30, %rax
movslq -0x44(%rbp), %rcx
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0xe8, %edx
callq 0x2150
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rdi
addq $0x18, %rdi
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
callq 0x2200
movl -0x1c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x98(%rax)
cmpl $0x0, -0x2c(%rbp)
je 0x7c73
movq -0x40(%rbp), %rax
movl $0x1, 0xe0(%rax)
movq 0x8fc5(%rip), %rcx      # 0x10c10
movq -0x40(%rbp), %rax
movq %rcx, 0xa8(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0xa0(%rax)
movq -0x40(%rbp), %rax
movl $0x0, 0xb0(%rax)
cmpq $0x0, -0x38(%rbp)
je 0x7cb7
cmpl $0x28, 0x10(%rbp)
jl 0x7c90
leaq 0x4c14(%rip), %rdi      # 0xc89b
movb $0x0, %al
callq 0x3aa0
jmp 0x7cb5
movq -0x40(%rbp), %rdi
addq $0xb4, %rdi
movq -0x38(%rbp), %rsi
movslq 0x10(%rbp), %rdx
callq 0x2200
movl 0x10(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0xdc(%rax)
jmp 0x7cb7
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)