// File: /workspace/github_cpp_makefile_star2_O1/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), %r14
leaq 0x880(%r14), %r15
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq 0x7c20b(%rip), %r13     # 0x8bfa0
movq (%r13), %rdi
leaq 0x59a69(%rip), %rsi     # 0x69809
leaq 0x59b29(%rip), %rdx     # 0x698d0
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rdi
movq 0x868(%r14), %rcx
movq 0x870(%r14), %rdx
leaq 0x59b17(%rip), %rsi     # 0x698de
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rsi
movl $0xa, %edi
callq 0xb690
movq 0x870(%r14), %rbp
cmpq 0x868(%r14), %rbp
jge 0xff9d
movq 0xba8(%r14), %rdi
testq %rdi, %rdi
je 0xfe73
leaq (,%rbp,4), %rax
addq %rbp, %rax
cmpl $0x0, 0x4(%r15,%rax,8)
je 0xfe73
callq 0xf8c6
movq %rax, %rbx
testq %rax, %rax
js 0xfe67
movq (%r13), %rdi
leaq 0x599e2(%rip), %rsi     # 0x69809
leaq 0x59aa2(%rip), %rdx     # 0x698d0
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rdi
leaq 0x59ab6(%rip), %rsi     # 0x698f6
movq %rbp, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rsi
movl $0xa, %edi
callq 0xb690
incq 0x870(%r14)
movl $0x2, %r12d
jmp 0xfe6a
xorl %r12d, %r12d
testq %rbx, %rbx
jns 0xff8b
leaq (,%rbp,4), %rax
addq %rbp, %rax
leaq (%r15,%rax,8), %rbx
movl (%rbx), %eax
cmpl $0x1, %eax
je 0xfefc
testl %eax, %eax
jne 0xff96
movq (%r13), %rdi
movl $0x0, 0xc(%rsp)
leaq 0x59965(%rip), %rsi     # 0x69809
leaq 0x59a25(%rip), %rdx     # 0x698d0
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rdi
leaq 0x59a5f(%rip), %rsi     # 0x6991c
movq %rbp, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rsi
movl $0xa, %edi
callq 0xb690
movq 0x8(%rbx), %rax
movq 0xb08(%r14), %rcx
movq %rax, 0x10(%rcx)
movq 0x10(%rbx), %rax
movq %rax, 0x20(%rcx)
movq %rax, 0x18(%rcx)
incq 0x870(%r14)
jmp 0xff88
movq (%r13), %rdi
xorl %r12d, %r12d
leaq 0x598ff(%rip), %rsi     # 0x69809
leaq 0x599bf(%rip), %rdx     # 0x698d0
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rdi
movq 0x878(%r14), %rcx
movq 0x10(%rbx), %r8
leaq 0x599ff(%rip), %rsi     # 0x6992d
movq %rbp, %rdx
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rsi
movl $0xa, %edi
callq 0xb690
movq 0x878(%r14), %rax
cmpq 0x10(%rbx), %rax
jge 0xff8b
movq 0x20(%rbx), %rcx
imulq %rax, %rcx
addq 0x8(%rbx), %rcx
movq 0xb08(%r14), %rdx
movq %rcx, 0x10(%rdx)
movq 0x18(%rbx), %rcx
movq %rcx, 0x20(%rdx)
movq %rcx, 0x18(%rdx)
incq %rax
movq %rax, 0x878(%r14)
movl $0x0, 0xc(%rsp)
xorl %r12d, %r12d
testl %r12d, %r12d
jne 0xfd95
jmp 0xff9d
callq 0xbad0
jmp 0xff88
testb $0x1, 0xc(%rsp)
je 0x1000b
movq (%r13), %rdi
leaq 0x5985a(%rip), %rsi     # 0x69809
leaq 0x5991a(%rip), %rdx     # 0x698d0
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rdi
movl 0xb20(%r14), %edx
leaq 0x5999c(%rip), %rsi     # 0x6996b
xorl %eax, %eax
callq 0xb7a0
movq (%r13), %rsi
movl $0xa, %edi
callq 0xb690
movq %r14, %rdi
callq 0xf9e4
movq 0xb08(%r14), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq $0x0, 0x20(%rax)
movq 0x10(%rsp), %rax
movups %xmm0, 0x38(%rax)
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq