// File: mh0fm4[P]SCDC/src/components/dataset/dataset_inout.cc
// Function: scdc_dataset_inout_redirect_to(_scdc_dataset_inout_t*, char const*, _scdc_args_t*)
static scdcint_t scdc_dataset_inout_redirect_to(scdc_dataset_inout_t *inout, const char *conf, scdc_args_t *args)
{
  if (stringlist(':', conf).front() == "output")
  {
    scdc_args xargs(args);

    scdc_dataset_output_t output;
    scdc_arg_ref_t output_arg_ref = xargs.get<scdc_dataset_output_t>(SCDC_ARGS_TYPE_DATASET_OUTPUT, &output);

    if (output_arg_ref == SCDC_ARG_REF_NULL)
    {
      SCDC_FAIL("scdc_dataset_inout_redirect_to: getting output parameter failed!");
      return SCDC_FAILURE;
    }

    /* assign inout to output */
    inout2inout(inout, &output, false);

    output.next = inout->next; inout->next = 0;
    output.data = inout->data; inout->data = 0;

    output.intern = inout->intern;

    xargs.set<scdc_dataset_output_t>(SCDC_ARGS_TYPE_DATASET_OUTPUT, &output, output_arg_ref);

    return SCDC_SUCCESS;
  }

  scdc_dataset_output_t _output, *output = &_output;

  scdc_args_data_ior_t args_ior_data = { inout, args };
  scdc_args_t args_ior = { &args_ior_data, scdc_args_get_ior, args->set, args->free };

  output = scdc_dataset_output_create_intern(output, conf, &args_ior);

  if (!output)
  {
    SCDC_FAIL("scdc_dataset_inout_redirect_to: creating output for redirection failed!");
    return SCDC_FAILURE;
  }

  scdcint_t ret = SCDC_SUCCESS;

  if (output->next)
  {
    /* feed inout to the output */
    while (1)
    {
      /* update target output */
      inout2inout(inout, output, false);

      /* process output (just continue if output has no more next) */
      if (output->next && !output->next(output, 0))
      {
        ret = SCDC_FAILURE;
        break;
      }

#if 0
      scdcint_t size = SCDC_DATASET_INOUT_BUF_CURRENT(inout) - SCDC_DATASET_INOUT_BUF_CURRENT(output);
#endif

      /* update given inout */
      inout2inout(output, inout, false);

#if 0
      SCDC_DATASET_INOUT_BUF_CURRENT(inout) = size;
#endif

      if (!inout->next) break;

      /* get next inout */
      if (!inout->next(inout, 0))
      {
        ret = SCDC_FAILURE;
        break;
      }
    }

  } else {

    /* copy inout to the output */
    inout2inout(inout, output, true);

    /* set current_size of source to the size of the processed data */
    SCDC_DATASET_INOUT_BUF_CURRENT(inout) = SCDC_DATASET_INOUT_BUF_CURRENT(output);
  }

  scdc_dataset_output_destroy(output);

  return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rdx
leaq -0x68(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
movl $0x3a, %esi
movq $-0x1, %rcx
callq 0x25a70
movq -0x1b8(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x267a0
jmp 0x4cb79
leaq 0x5c2cb(%rip), %rsi     # 0xa8e4b
leaq -0x40(%rbp), %rdi
callq 0x25b80
movb %al, -0x1b9(%rbp)
jmp 0x4cb91
leaq -0x40(%rbp), %rdi
callq 0xc3e0
leaq -0x68(%rbp), %rdi
callq 0x25c90
movb -0x1b9(%rbp), %al
testb $0x1, %al
jne 0x4cbb2
jmp 0x4cdc9
movq -0x20(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x25660
movq -0x1d0(%rbp), %rdi
movl $0xa, %esi
leaq -0x108(%rbp), %rdx
xorl %ecx, %ecx
callq 0x4d750
movq %rax, -0x1c8(%rbp)
jmp 0x4cbec
movq -0x1c8(%rbp), %rax
movq %rax, -0x110(%rbp)
cmpq $0x0, -0x110(%rbp)
jne 0x4cd27
jmp 0x4cc0a
leaq 0x87a97(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
cmpq $0x0, %rax
je 0x4cd0c
leaq 0x87a7e(%rip), %rax     # 0xd46a8
movq %rax, -0x1e0(%rbp)
movq (%rax), %rdi
callq 0x25800
movq -0x1e0(%rbp), %rax
movq (%rax), %rdi
callq 0x257e0
movq %rax, %rdi
leaq 0x5955e(%rip), %rsi     # 0xa61b0
callq 0xc670
movq %rax, -0x1d8(%rbp)
jmp 0x4cc60
movq -0x1d8(%rbp), %rdi
leaq 0x5a40e(%rip), %rsi     # 0xa707c
callq 0xc670
movq %rax, -0x1e8(%rbp)
jmp 0x4cc7c
movq -0x1e8(%rbp), %rdi
leaq 0x5aadd(%rip), %rsi     # 0xa7767
callq 0xc670
movq %rax, -0x1f0(%rbp)
jmp 0x4cc98
movq -0x1f0(%rbp), %rdi
movq 0x8731a(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
jmp 0x4ccad
leaq 0x879f4(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25820
jmp 0x4cd0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x4cce1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xc3e0
leaq -0x68(%rbp), %rdi
callq 0x25c90
jmp 0x4cfe3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x256b0
jmp 0x4cfe3
jmp 0x4cd0e
jmp 0x4cd10
movq $0x0, -0x8(%rbp)
movl $0x1, -0x114(%rbp)
jmp 0x4cdb8
movq -0x10(%rbp), %rdi
leaq -0x108(%rbp), %rsi
movq %rsi, -0x1f8(%rbp)
xorl %edx, %edx
callq 0x4cff0
movq -0x1f8(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x110(%rbp), %rcx
leaq -0xb0(%rbp), %rdi
movl $0xa, %esi
callq 0x4d7e0
jmp 0x4cda6
movq $0x1, -0x8(%rbp)
movl $0x1, -0x114(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x256b0
jmp 0x4cfd6
leaq -0x170(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x180(%rbp)
leaq -0x188(%rbp), %rax
movq %rax, -0x1a8(%rbp)
leaq 0x2ae(%rip), %rax       # 0x4d0b0
movq %rax, -0x1a0(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x198(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x190(%rbp)
movq -0x178(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x1a8(%rbp), %rdx
callq 0x45750
movq %rax, -0x178(%rbp)
cmpq $0x0, -0x178(%rbp)
jne 0x4cee2
jmp 0x4ce55
leaq 0x8784c(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
cmpq $0x0, %rax
je 0x4ced3
leaq 0x87837(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25800
leaq 0x87828(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
movq %rax, %rdi
leaq 0x5931e(%rip), %rsi     # 0xa61b0
callq 0xc670
movq %rax, %rdi
leaq 0x5a1db(%rip), %rsi     # 0xa707c
callq 0xc670
movq %rax, %rdi
leaq 0x5a8f8(%rip), %rsi     # 0xa77a8
callq 0xc670
movq %rax, %rdi
movq 0x87101(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x877dd(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25820
jmp 0x4ced5
movq $0x0, -0x8(%rbp)
jmp 0x4cfd6
movq $0x1, -0x1b0(%rbp)
movq -0x178(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x4cf97
jmp 0x4cf01
movq -0x10(%rbp), %rdi
movq -0x178(%rbp), %rsi
xorl %edx, %edx
callq 0x4cff0
movq -0x178(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x4cf4c
movq -0x178(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x178(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
callq *%rax
cmpq $0x0, %rax
jne 0x4cf4c
movq $0x0, -0x1b0(%rbp)
jmp 0x4cf95
movq -0x178(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x4cff0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x4cf6b
jmp 0x4cf95
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
callq *%rax
cmpq $0x0, %rax
jne 0x4cf90
movq $0x0, -0x1b0(%rbp)
jmp 0x4cf95
jmp 0x4cf01
jmp 0x4cfbf
movq -0x10(%rbp), %rdi
movq -0x178(%rbp), %rsi
movl $0x1, %edx
callq 0x4cff0
movq -0x178(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x178(%rbp), %rdi
callq 0x46bc0
movq -0x1b0(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0xcba0
nopl (%rax)