// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0x40(%rdi), %rbx
leaq 0x880(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x65e19(%rip), %rbp     # 0x74fb8
leaq 0x41663(%rip), %rsi     # 0x50809
leaq 0x41723(%rip), %rdx     # 0x508d0
pushq $0xa
popq %r15
movq (%rbp), %rdi
movq %rsi, %r13
movq %rdx, %r14
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rdi
movq 0x868(%rbx), %rcx
movq 0x870(%rbx), %rdx
leaq 0x41703(%rip), %rsi     # 0x508de
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rsi
movl %r15d, %r12d
movl %r15d, %edi
callq 0xb6b0
movq 0x870(%rbx), %r15
cmpq 0x868(%rbx), %r15
jge 0xf38d
movq 0xba8(%rbx), %rdi
testq %rdi, %rdi
je 0xf272
imulq $0x28, %r15, %rax
movq 0x8(%rsp), %rcx
cmpl $0x0, 0x4(%rcx,%rax)
je 0xf272
callq 0xed05
testq %rax, %rax
js 0xf272
movq (%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rdi
leaq 0x416af(%rip), %rsi     # 0x508f6
movq %r15, %rdx
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rsi
movl %r12d, %r15d
movl %r12d, %edi
callq 0xb6b0
movq %r14, %rdx
movq %r13, %rsi
incq 0x870(%rbx)
jmp 0xf1b1
imulq $0x28, %r15, %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax), %r14
movl (%rcx,%rax), %eax
cmpl $0x1, %eax
je 0xf2f0
testl %eax, %eax
jne 0xf371
movq (%rbp), %rdi
leaq 0x4156f(%rip), %rsi     # 0x50809
leaq 0x4162f(%rip), %rdx     # 0x508d0
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rdi
leaq 0x41669(%rip), %rsi     # 0x5091c
movq %r15, %rdx
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rsi
pushq $0xa
popq %rdi
callq 0xb6b0
movq 0x8(%r14), %rax
movq 0xb08(%rbx), %rcx
movq %rax, 0x10(%rcx)
movq 0x10(%r14), %rax
movq %rax, 0x20(%rcx)
movq %rax, 0x18(%rcx)
incq 0x870(%rbx)
jmp 0xf3ee
movq (%rbp), %rdi
leaq 0x4150e(%rip), %rsi     # 0x50809
leaq 0x415ce(%rip), %rdx     # 0x508d0
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rdi
movq 0x878(%rbx), %rcx
movq 0x10(%r14), %r8
leaq 0x4160e(%rip), %rsi     # 0x5092d
movq %r15, %rdx
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rsi
pushq $0xa
popq %rdi
callq 0xb6b0
movq 0x878(%rbx), %rax
cmpq 0x10(%r14), %rax
jge 0xf38d
movq 0x20(%r14), %rcx
imulq %rax, %rcx
addq 0x8(%r14), %rcx
movq 0xb08(%rbx), %rdx
movq %rcx, 0x10(%rdx)
movq 0x18(%r14), %rcx
movq %rcx, 0x20(%rdx)
movq %rcx, 0x18(%rdx)
incq %rax
movq %rax, 0x878(%rbx)
jmp 0xf3ee
movq 0x65c60(%rip), %rax     # 0x74fd8
movq (%rax), %rcx
leaq 0x415d0(%rip), %rdi     # 0x50952
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0xba80
movq (%rbp), %rdi
leaq 0x41471(%rip), %rsi     # 0x50809
leaq 0x41531(%rip), %rdx     # 0x508d0
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rdi
movl 0xb20(%rbx), %edx
leaq 0x415b4(%rip), %rsi     # 0x5096b
xorl %eax, %eax
callq 0xb7c0
movq (%rbp), %rsi
pushq $0xa
popq %rdi
callq 0xb6b0
movq %rbx, %rdi
callq 0xee11
movq 0xb08(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
andq $0x0, 0x20(%rax)
movq 0x10(%rsp), %rax
movups %xmm0, 0x38(%rax)
pushq $0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq