// File: /workspace/github_cpp_makefile_star2_O3/mh0fm4[P]SCDC/src/lib/redirect/redirect/redirect_call.cc
// Function: do_input_next(_scdc_dataset_inout_t*, _scdc_result_t*)
static scdcint_t do_input_next(scdc_dataset_input_t *input, scdc_result_t *result)
{
  redirect_call_t *rc = static_cast<redirect_call_t *>(input->data);

  bool finish = true;

#if REDIRECT_CALL_PARAMS_CACHE
do_state:
#endif

#if REDIRECT_CALL_PARAMS_NEW
  TRACE_F("params state %" rdint_fmt " of %" rdint_fmt, rc->params_state[0], rc->nparams);

  if (rc->params_state[0] < rc->nparams)
  {
    rdint_t i = rc->params_state[0];

#if REDIRECT_CALL_PARAMS_CACHE
    if (rc->cache && rc->params[i].cacheable)
    {
      rdint_t entry_index = redirect_cache_get_next_param_entry_index(rc->cache);

      if (entry_index >= 0)
      {
        TRACE_F("param %" rdint_fmt ": in cache, skipping to next", i);
        ++rc->params_state[0];
        goto do_state;
      }
    }
#endif

    if (rc->params[i].type == REDIRECT_PARAM_TYPE_DENSE)
    {
      TRACE_F("param %" rdint_fmt ": dense", i);

      finish = false;

      SCDC_DATASET_INOUT_BUF_PTR(rc->input) = rc->params[i].p.dense.buf;
      SCDC_DATASET_INOUT_BUF_SIZE(rc->input) = SCDC_DATASET_INOUT_BUF_CURRENT(rc->input) = rc->params[i].p.dense.size;

      ++rc->params_state[0];

    } else if (rc->params[i].type == REDIRECT_PARAM_TYPE_BLOCKS)
    {
      TRACE_F("param %" rdint_fmt ": blocks, state: %" rdint_fmt " of %" rdint_fmt, i, rc->params_state[1], rc->params[i].p.blocks.count);

      if (rc->params_state[1] < rc->params[i].p.blocks.count)
      {
        finish = false;

        SCDC_DATASET_INOUT_BUF_PTR(rc->input) = static_cast<char *>(rc->params[i].p.blocks.buf) + (rc->params_state[1] * rc->params[i].p.blocks.stride);
        SCDC_DATASET_INOUT_BUF_SIZE(rc->input) = SCDC_DATASET_INOUT_BUF_CURRENT(rc->input) = rc->params[i].p.blocks.size;

        ++rc->params_state[1];
      }

    } else ASSERT(false);
  }
#else
  TRACE_F("dense state %d of %d", rc->input_state, rc->dense_nparams);

  if (rc->input_state < rc->dense_nparams)
  {
    finish = false;

    rdint_t i = rc->input_state;

    SCDC_DATASET_INOUT_BUF_PTR(rc->input) = rc->dense_params[i].buf;
    SCDC_DATASET_INOUT_BUF_SIZE(rc->input) = SCDC_DATASET_INOUT_BUF_CURRENT(rc->input) = rc->dense_params[i].size;

    ++rc->input_state;
  }
#endif

  if (finish)
  {
    TRACE_F("freeing %d buffers", rc->free_nbufs);

    redirect_call_free_bufs(rc);

    SCDC_DATASET_INOUT_BUF_PTR(rc->input) = NULL;
    SCDC_DATASET_INOUT_BUF_SIZE(rc->input) = 0;
    SCDC_DATASET_INOUT_BUF_CURRENT(rc->input) = 0;

    input->next = NULL;
    input->data = NULL;
  }

  return SCDC_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, (%rsp)
movq 0x40(%rdi), %rbx
leaq 0x880(%rbx), %rbp
movq 0x7c212(%rip), %r14     # 0x8bfa0
leaq 0x59a94(%rip), %r12     # 0x69829
leaq 0x59b54(%rip), %r13     # 0x698f0
movq (%r14), %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rdi
movq 0x868(%rbx), %rcx
movq 0x870(%rbx), %rdx
leaq 0x59b3a(%rip), %rsi     # 0x698fe
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rsi
movl $0xa, %edi
callq 0xb690
movq 0x870(%rbx), %r15
cmpq 0x868(%rbx), %r15
jge 0xff56
movq 0xba8(%rbx), %rdi
testq %rdi, %rdi
je 0xfe4a
leaq (%r15,%r15,4), %rax
cmpl $0x0, 0x4(%rbp,%rax,8)
je 0xfe4a
callq 0xf8d9
testq %rax, %rax
js 0xfe4a
movq (%r14), %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rdi
leaq 0x59aef(%rip), %rsi     # 0x69916
movq %r15, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rsi
movl $0xa, %edi
callq 0xb690
incq 0x870(%rbx)
jmp 0xfd9c
leaq (%r15,%r15,4), %rax
leaq (,%rax,8), %r12
addq %rbp, %r12
movl (%r12), %eax
cmpl $0x1, %eax
je 0xfecc
testl %eax, %eax
jne 0xff51
movq (%r14), %rdi
leaq 0x599b5(%rip), %rsi     # 0x69829
leaq 0x59a75(%rip), %rdx     # 0x698f0
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rdi
leaq 0x59ab0(%rip), %rsi     # 0x6993c
movq %r15, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rsi
movl $0xa, %edi
callq 0xb690
movq 0x8(%r12), %rax
movq 0xb08(%rbx), %rcx
movq %rax, 0x10(%rcx)
movq 0x10(%r12), %rax
movq %rax, 0x20(%rcx)
movq %rax, 0x18(%rcx)
incq 0x870(%rbx)
jmp 0xffb8
movq (%r14), %rdi
leaq 0x59953(%rip), %rsi     # 0x69829
leaq 0x59a13(%rip), %rdx     # 0x698f0
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rdi
movq 0x878(%rbx), %rcx
movq 0x10(%r12), %r8
leaq 0x59a53(%rip), %rsi     # 0x6994d
movq %r15, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rsi
movl $0xa, %edi
callq 0xb690
movq 0x878(%rbx), %rax
cmpq 0x10(%r12), %rax
jge 0xff56
movq 0x20(%r12), %rcx
imulq %rax, %rcx
addq 0x8(%r12), %rcx
movq 0xb08(%rbx), %rdx
movq %rcx, 0x10(%rdx)
movq 0x18(%r12), %rcx
movq %rcx, 0x20(%rdx)
movq %rcx, 0x18(%rdx)
incq %rax
movq %rax, 0x878(%rbx)
jmp 0xffb8
callq 0xbad0
movq (%r14), %rdi
leaq 0x598c9(%rip), %rsi     # 0x69829
leaq 0x59989(%rip), %rdx     # 0x698f0
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rdi
movl 0xb20(%rbx), %edx
leaq 0x59a0d(%rip), %rsi     # 0x6998b
xorl %eax, %eax
callq 0xb7a0
movq (%r14), %rsi
movl $0xa, %edi
callq 0xb690
movq %rbx, %rdi
callq 0xf9f4
movq 0xb08(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq $0x0, 0x20(%rax)
movq (%rsp), %rax
movups %xmm0, 0x38(%rax)
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq