// File: mh0fm4[P]SCDC/src/lib/redirect/redirect/redirect_cache.cc
// Function: redirect_cache_put_entry
rdint_t redirect_cache_put_entry(redirect_cache_t *rch, int type, rdint_t size, const void *buf)
{
  rdint_t entry_index = redirect_cache_find_entry(rch, type, size, buf);

  if (entry_index >= 0)
  {
    TRACE_F("entry [%d,%" rdint_fmt ",%p] / %" rdint_fmt " already in cache", type, size, buf, entry_index);
    redirect_cache_update_entry(rch, entry_index);
    return entry_index;
  }

  if (rch->nentries >= REDIRECT_CACHE_ENTRIES_MAX)
  {
    TRACE_F("max. number of entries %" rdint_fmt " in cache", rch->nentries);
    // FIXME: cache replacement strategy: FIFO, LRU, LFU
    return -1;
  }

  entry_index = rch->nentries;

  rch->entries[entry_index].type = type;
  rch->entries[entry_index].size = size;
  rch->entries[entry_index].buf = const_cast<void *>(buf);
  rch->entries[entry_index].hash_set = 0;

  ++rch->nentries;

  return entry_index;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x116f0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jl 0x115d0
jmp 0x11558
movq 0xc2a51(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x9400e(%rip), %rsi     # 0xa5577
leaq 0x94211(%rip), %rdx     # 0xa5781
movb $0x0, %al
callq 0xc9a0
movq 0xc2a32(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movl -0x14(%rbp), %edx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
leaq 0x94203(%rip), %rsi     # 0xa579a
movb $0x0, %al
callq 0xc9a0
movq 0xc2a0b(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x942f9(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x117b0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x116e4
movq -0x10(%rbp), %rax
cmpq $0x10, 0x298(%rax)
jl 0x11647
jmp 0x115e0
movq 0xc29c9(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x93f86(%rip), %rsi     # 0xa5577
leaq 0x94189(%rip), %rdx     # 0xa5781
movb $0x0, %al
callq 0xc9a0
movq 0xc29aa(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x298(%rax), %rdx
leaq 0x941a8(%rip), %rsi     # 0xa57c3
movb $0x0, %al
callq 0xc9a0
movq 0xc2987(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x94275(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq $-0x1, -0x8(%rbp)
jmp 0x116e4
movq -0x10(%rbp), %rax
movq 0x298(%rax), %rax
movq %rax, -0x30(%rbp)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
addq $0x2a0, %rax            # imm = 0x2A0
movq -0x30(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
addq $0x2a0, %rax            # imm = 0x2A0
movq -0x30(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
addq $0x2a0, %rax            # imm = 0x2A0
movq -0x30(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
addq $0x2a0, %rax            # imm = 0x2A0
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x298(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x298(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop