// File: 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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x18(%rbp)
movb $0x1, -0x19(%rbp)
jmp 0x12012
movq 0xc1f97(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x937ee(%rip), %rsi     # 0xa5811
leaq 0x938ae(%rip), %rdx     # 0xa58d8
movb $0x0, %al
callq 0xc9a0
movq 0xc1f78(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x870(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x868(%rax), %rcx
leaq 0x9388e(%rip), %rsi     # 0xa58e6
movb $0x0, %al
callq 0xc9a0
movq 0xc1f4a(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x93838(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x18(%rbp), %rax
movq 0x870(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x868(%rcx), %rax
jge 0x123b9
movq -0x18(%rbp), %rax
movq 0x870(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0xba8(%rax)
je 0x1215d
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
je 0x1215d
movq -0x18(%rbp), %rax
movq 0xba8(%rax), %rdi
callq 0x11880
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jl 0x1215b
jmp 0x120ed
movq 0xc1ebc(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x93713(%rip), %rsi     # 0xa5811
leaq 0x937d3(%rip), %rdx     # 0xa58d8
movb $0x0, %al
callq 0xc9a0
movq 0xc1e9d(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x937dd(%rip), %rsi     # 0xa58fe
movb $0x0, %al
callq 0xc9a0
movq 0xc1e81(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x9376f(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x18(%rbp), %rax
movq 0x870(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x870(%rax)
jmp 0x12010
jmp 0x1215d
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x12245
jmp 0x1217a
movq 0xc1e2f(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x93686(%rip), %rsi     # 0xa5811
leaq 0x93746(%rip), %rdx     # 0xa58d8
movb $0x0, %al
callq 0xc9a0
movq 0xc1e10(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x93776(%rip), %rsi     # 0xa5924
movb $0x0, %al
callq 0xc9a0
movq 0xc1df4(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x936e2(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movb $0x0, -0x19(%rbp)
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0xb08(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0xb08(%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0xb08(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x870(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x870(%rax)
jmp 0x123b7
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
jne 0x12399
jmp 0x12262
movq 0xc1d47(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x9359e(%rip), %rsi     # 0xa5811
leaq 0x9365e(%rip), %rdx     # 0xa58d8
movb $0x0, %al
callq 0xc9a0
movq 0xc1d28(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x878(%rax), %rcx
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rsi
addq %rsi, %rax
movq 0x10(%rax), %r8
leaq 0x9367e(%rip), %rsi     # 0xa5935
movb $0x0, %al
callq 0xc9a0
movq 0xc1ceb(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x935d9(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x18(%rbp), %rax
movq 0x878(%rax), %rax
movq -0x18(%rbp), %rcx
addq $0x880, %rcx            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpq 0x10(%rcx), %rax
jge 0x12397
movb $0x0, -0x19(%rbp)
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x878(%rax), %rax
movq -0x18(%rbp), %rdx
addq $0x880, %rdx            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rsi
addq %rsi, %rdx
imulq 0x20(%rdx), %rax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq 0xb08(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq 0xb08(%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0xb08(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x878(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x878(%rax)
jmp 0x123b5
jmp 0x1239b
movq 0xc1c36(%rip), %rax     # 0xd3fd8
movq (%rax), %rdi
leaq 0x935ae(%rip), %rsi     # 0xa595a
movb $0x0, %al
callq 0xc9a0
jmp 0x123b5
jmp 0x123b7
jmp 0x123b9
testb $0x1, -0x19(%rbp)
je 0x12478
jmp 0x123c5
movq 0xc1be4(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x9343b(%rip), %rsi     # 0xa5811
leaq 0x934fb(%rip), %rdx     # 0xa58d8
movb $0x0, %al
callq 0xc9a0
movq 0xc1bc5(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0xb20(%rax), %edx
leaq 0x93574(%rip), %rsi     # 0xa5973
movb $0x0, %al
callq 0xc9a0
movq 0xc1ba3(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x93491(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x18(%rbp), %rdi
callq 0x11ab0
movq -0x18(%rbp), %rax
movq 0xb08(%rax), %rax
movq $0x0, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0xb08(%rax), %rax
movq $0x0, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0xb08(%rax), %rax
movq $0x0, 0x20(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x40(%rax)
movl $0x1, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)