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

  bool finish = true;

#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 (rc->params[i].type == REDIRECT_PARAM_TYPE_DENSE)
    {
      finish = false;

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

      ++rc->params_state[0];

    } else if (rc->params[i].type == REDIRECT_PARAM_TYPE_BLOCKS)
    {
      TRACE_F("blocks state %" rdint_fmt " of %" rdint_fmt, 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->output) = 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->output) = SCDC_DATASET_INOUT_BUF_CURRENT(rc->output) = rc->params[i].p.blocks.size;

        ++rc->params_state[1];
      }

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

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

    rdint_t i = rc->output_state;

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

    ++rc->output_state;
  }
#endif

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

    redirect_call_free_bufs(rc);

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

    output->next = NULL;
    output->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)
movq 0xc1479(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x92cd0(%rip), %rsi     # 0xa5811
leaq 0x92e3e(%rip), %rdx     # 0xa5986
movb $0x0, %al
callq 0xc9a0
movq 0xc145a(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x870(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x868(%rax), %rcx
leaq 0x92d70(%rip), %rsi     # 0xa58e6
movb $0x0, %al
callq 0xc9a0
movq 0xc142c(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x92d1a(%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 0x12dbf
movq -0x18(%rbp), %rax
movq 0x870(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x12c4f
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 0xb10(%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 0xb10(%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0xb10(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x870(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x870(%rax)
jmp 0x12dbd
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
cmpl $0x1, (%rax)
jne 0x12d9f
jmp 0x12c6c
movq 0xc133d(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x92b94(%rip), %rsi     # 0xa5811
leaq 0x92d02(%rip), %rdx     # 0xa5986
movb $0x0, %al
callq 0xc9a0
movq 0xc131e(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x878(%rax), %rdx
movq -0x18(%rbp), %rax
addq $0x880, %rax            # imm = 0x880
imulq $0x28, -0x28(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
leaq 0x92ce2(%rip), %rsi     # 0xa599f
movb $0x0, %al
callq 0xc9a0
movq 0xc12e5(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x92bd3(%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 0x12d9d
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 0xb10(%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 0xb10(%rax), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0xb10(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x878(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x878(%rax)
jmp 0x12dbb
jmp 0x12da1
movq 0xc1230(%rip), %rax     # 0xd3fd8
movq (%rax), %rdi
leaq 0x92ba8(%rip), %rsi     # 0xa595a
movb $0x0, %al
callq 0xc9a0
jmp 0x12dbb
jmp 0x12dbd
jmp 0x12dbf
testb $0x1, -0x19(%rbp)
je 0x12e7e
jmp 0x12dcb
movq 0xc11de(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x92a35(%rip), %rsi     # 0xa5811
leaq 0x92ba3(%rip), %rdx     # 0xa5986
movb $0x0, %al
callq 0xc9a0
movq 0xc11bf(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0xb20(%rax), %edx
leaq 0x92b6e(%rip), %rsi     # 0xa5973
movb $0x0, %al
callq 0xc9a0
movq 0xc119d(%rip), %rax     # 0xd3fb0
movq (%rax), %rdi
leaq 0x92a8b(%rip), %rsi     # 0xa58a8
movb $0x0, %al
callq 0xc9a0
movq -0x18(%rbp), %rdi
callq 0x11ab0
movq -0x18(%rbp), %rax
movq 0xb10(%rax), %rax
movq $0x0, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0xb10(%rax), %rax
movq $0x0, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0xb10(%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
nopl (%rax)