// File: mh0fm4[P]SCDC/src/lib/redirect/redirect/redirect_call.cc
// Function: void consume_input_dense<char>(_redirect_call_t*, char*, long)
static void consume_input_dense(redirect_call_t *rc, T *buf, rdint_t size)
{
  rdint_t size_left = size * sizeof(T);

  char *src = static_cast<char *>(SCDC_DATASET_INOUT_BUF_PTR(rc->input));
  char *dst = reinterpret_cast<char *>(buf);

  do
  {
    rdint_t t = z_min(size_left, SCDC_DATASET_INOUT_BUF_CURRENT(rc->input) - rc->input_offset);
    if (dst != src + rc->input_offset) memcpy(dst, src + rc->input_offset, t);
    rc->input_offset += t;
    dst += t;
    size_left -= t;

    /* done */
    if (size_left <= 0) break;

    /* have no next or next fails? */
    if (rc->input->next == 0 || rc->input->next(rc->input, 0) != SCDC_SUCCESS) break;

    src = static_cast<char *>(SCDC_DATASET_INOUT_BUF_PTR(rc->input));
    rc->input_offset = 0;

  } while (1);

#if REDIRECT_CALL_PARAMS_CACHE
  /* try to add an entry to the cache (dense input is cacheable) */
  if (rc->cache)
  {
    rdint_t size_cache = size * sizeof(T);
    rdint_t buf_index = redirect_call_find_buf(rc, buf);
    rdint_t entry_index = redirect_cache_find_entry(rc->cache, get_type<T>(), size_cache, buf);

    /* caching entry if buffer is allocated or entry is already cached */
    if (buf_index >= 0 || entry_index >= 0)
    {
      if (entry_index >= 0)
      {
        TRACE_F("updating entry %" rdint_fmt " of cache", entry_index);
        redirect_cache_update_entry(rc->cache, entry_index);

      } else
      {
        TRACE_F("adding entry [%d,%" rdint_fmt ",%p] to cache", get_type<T>(), size_cache, buf);
        redirect_cache_put_entry(rc->cache, get_type<T>(), size_cache, buf);
      }

      if (buf_index >= 0) redirect_call_remove_buf(rc, buf_index);
    }
  }
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
shlq $0x0, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0xb08(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0xb08(%rcx), %rcx
movq 0x20(%rcx), %rcx
movq -0x8(%rbp), %rdx
movslq 0xb00(%rdx), %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jge 0x173bb
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x173dc
movq -0x8(%rbp), %rax
movq 0xb08(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0xb00(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rdx
movslq 0xb00(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
je 0x1741e
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x8(%rbp), %rax
movslq 0xb00(%rax), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rdx
callq 0xc530
movq -0x38(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq 0xb00(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0xb00(%rax)
movq -0x38(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jg 0x1745a
jmp 0x174c1
movq -0x8(%rbp), %rax
movq 0xb08(%rax), %rax
cmpq $0x0, 0x38(%rax)
je 0x17492
movq -0x8(%rbp), %rax
movq 0xb08(%rax), %rax
movq 0x38(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0xb08(%rcx), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
callq *%rax
cmpq $0x1, %rax
je 0x17494
jmp 0x174c1
movq -0x8(%rbp), %rax
movq 0xb08(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movl $0x0, 0xb00(%rax)
movb $0x1, %al
testb $0x1, %al
jne 0x1738b
jmp 0x174c1
movq -0x8(%rbp), %rax
cmpq $0x0, 0xba8(%rax)
je 0x17649
movq -0x18(%rbp), %rax
shlq $0x0, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x17650
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0xba8(%rax), %rax
movq %rax, -0x60(%rbp)
callq 0x152e0
movq -0x60(%rbp), %rdi
movl %eax, %esi
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rcx
callq 0x116f0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
jge 0x1752d
cmpq $0x0, -0x50(%rbp)
jl 0x17647
cmpq $0x0, -0x50(%rbp)
jl 0x175a2
jmp 0x17536
movq 0xbca73(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x8e2ca(%rip), %rsi     # 0xa5811
leaq 0x8e592(%rip), %rdx     # 0xa5ae0
movb $0x0, %al
callq 0xc9a0
movq 0xbca54(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x50(%rbp), %rdx
leaq 0x8e58a(%rip), %rsi     # 0xa5af4
movb $0x0, %al
callq 0xc9a0
movq 0xbca38(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x8e326(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x8(%rbp), %rax
movq 0xba8(%rax), %rdi
movq -0x50(%rbp), %rsi
callq 0x117b0
jmp 0x17631
jmp 0x175a4
movq 0xbca05(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x8e25c(%rip), %rsi     # 0xa5811
leaq 0x8e524(%rip), %rdx     # 0xa5ae0
movb $0x0, %al
callq 0xc9a0
movq 0xbc9e6(%rip), %rax     # 0xd3fb0
movq (%rax), %rax
movq %rax, -0x68(%rbp)
callq 0x152e0
movq -0x68(%rbp), %rdi
movl %eax, %edx
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %r8
leaq 0x8e525(%rip), %rsi     # 0xa5b10
movb $0x0, %al
callq 0xc9a0
movq 0xbc9b7(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x8e2a5(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x8(%rbp), %rax
movq 0xba8(%rax), %rax
movq %rax, -0x70(%rbp)
callq 0x152e0
movq -0x70(%rbp), %rdi
movl %eax, %esi
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rcx
callq 0x11520
cmpq $0x0, -0x48(%rbp)
jl 0x17645
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x176c0
jmp 0x17647
jmp 0x17649
addq $0x70, %rsp
popq %rbp
retq
nop