// File: mh0fm4[P]SCDC/test/units/dataprov_hook/hook.c
// Function: hook_dataset_cmd
scdcint_t hook_dataset_cmd(void *dataprov, void *dataset, const char *cmd, const char *params, scdc_dataset_input_t *input, scdc_dataset_output_t *output, scdc_result_t *result)
{
  ptrdiff_t x;

  printf("hook_dataset_cmd: dataprov: %p, dataset: %p, cmd: '%s', params: '%s', input: %p, output: %p, result: %p\n", dataprov, dataset, cmd, params, input, output, result);
  print_dataset_input("hook_dataset_cmd: ", input);
  print_dataset_output("hook_dataset_cmd: ", output);

  clear_output(output);

  if (strncmp(cmd, "get", 3) == 0)
  {
    if (strncmp(params, "in2out", 6) == 0)
    {
      if (input)
      {
        scdc_dataset_input_redirect(input, "to:output", output);
      }

    } else if (strncmp(params, "in4out", 6) == 0)
    {
      if (input)
      {
        scdc_dataset_output_redirect(output, "from:input", input);
      }

    } else if (strncmp(params, "in5out", 6) == 0)
    {
      /* stored */
      if (input)
      {
        scdc_dataset_input_redirect(input, "to:file", "hook_get.tmp");

        scdc_dataset_output_redirect(output, "from:file", "hook_get.tmp");
      }

    } else
    {
      consume_input("hook_dataset_cmd: ", input);

      if (strlen(params) > 0 && sscanf(params, "x%td", &x) == 1);
      else x = 2;

      strcpy(output->format, "text");

      output->total_size = x * DEFAULT_GET_SIZE;
      output->total_size_given = SCDC_DATASET_INOUT_TOTAL_SIZE_GIVEN_EXACT;

      output->data = (void *) x;

      hook_dataset_get_next(output, 0);
    }

  } else
  {
    consume_input("hook_dataset_cmd: ", input);

    strcpy(output->format, "text");

    SCDC_DATASET_INOUT_BUF_CURRENT(output) = sprintf(SCDC_DATASET_INOUT_BUF_PTR(output), "dataset: '%p', cmd: '%s', params: '%s'", dataset, cmd, params);
    output->total_size = SCDC_DATASET_INOUT_BUF_CURRENT(output);
    output->total_size_given = SCDC_DATASET_INOUT_TOTAL_SIZE_GIVEN_EXACT;
  }

  print_dataset_output("hook_dataset_cmd: ", output);

  SCDC_RESULT_SET_STR(result, "result of hook_dataset_cmd");
  printf("hook_dataset_cmd: return: %" scdcint_fmt ", result: '%s'", SCDC_SUCCESS, SCDC_RESULT_STR(result));

  return SCDC_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x30(%rbp), %r10
movq 0x10(%rbp), %rax
leaq 0x7c4a9(%rip), %rdi     # 0x8a4b0
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0xcd10
movq -0x28(%rbp), %rsi
leaq 0x7c4f7(%rip), %rdi     # 0x8a519
callq 0xde50
movq -0x30(%rbp), %rsi
leaq 0x7c4e7(%rip), %rdi     # 0x8a519
callq 0xdea0
movq -0x30(%rbp), %rdi
callq 0xe270
movq -0x18(%rbp), %rdi
leaq 0x7d05b(%rip), %rsi     # 0x8b0a6
movl $0x3, %edx
callq 0xc2d0
cmpl $0x0, %eax
jne 0xe1b6
movq -0x20(%rbp), %rdi
leaq 0x7c4c3(%rip), %rsi     # 0x8a52c
movl $0x6, %edx
callq 0xc2d0
cmpl $0x0, %eax
jne 0xe09a
cmpq $0x0, -0x28(%rbp)
je 0xe095
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x7c4a5(%rip), %rsi     # 0x8a533
movb $0x0, %al
callq 0x33750
jmp 0xe1b4
movq -0x20(%rbp), %rdi
leaq 0x7c498(%rip), %rsi     # 0x8a53d
movl $0x6, %edx
callq 0xc2d0
cmpl $0x0, %eax
jne 0xe0d6
cmpq $0x0, -0x28(%rbp)
je 0xe0d1
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x7c47a(%rip), %rsi     # 0x8a544
movb $0x0, %al
callq 0x338f0
jmp 0xe1b2
movq -0x20(%rbp), %rdi
leaq 0x7c46e(%rip), %rsi     # 0x8a54f
movl $0x6, %edx
callq 0xc2d0
cmpl $0x0, %eax
jne 0xe12e
cmpq $0x0, -0x28(%rbp)
je 0xe129
movq -0x28(%rbp), %rdi
leaq 0x7c454(%rip), %rsi     # 0x8a556
leaq 0x7c455(%rip), %rdx     # 0x8a55e
movb $0x0, %al
callq 0x33750
movq -0x30(%rbp), %rdi
leaq 0x7c450(%rip), %rsi     # 0x8a56b
leaq 0x7c43c(%rip), %rdx     # 0x8a55e
movb $0x0, %al
callq 0x338f0
jmp 0xe1b0
movq -0x28(%rbp), %rsi
leaq 0x7c3e0(%rip), %rdi     # 0x8a519
callq 0xe2c0
movq -0x20(%rbp), %rdi
callq 0xc280
cmpq $0x0, %rax
jbe 0xe16a
movq -0x20(%rbp), %rdi
leaq 0x7c41d(%rip), %rsi     # 0x8a575
leaq -0x38(%rbp), %rdx
movb $0x0, %al
callq 0xc630
cmpl $0x1, %eax
jne 0xe16a
jmp 0xe172
movq $0x2, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq 0x7c3fd(%rip), %rsi     # 0x8a57a
callq 0xc600
imulq $0xd, -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rax
movb $0x78, 0x30(%rax)
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xdef0
jmp 0xe1b2
jmp 0xe1b4
jmp 0xe21b
movq -0x28(%rbp), %rsi
leaq 0x7c358(%rip), %rdi     # 0x8a519
callq 0xe2c0
movq -0x30(%rbp), %rdi
leaq 0x7c3a9(%rip), %rsi     # 0x8a57a
callq 0xc600
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq 0x7c38e(%rip), %rsi     # 0x8a57f
movb $0x0, %al
callq 0xc0f0
movslq %eax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rax
movb $0x78, 0x30(%rax)
movq -0x30(%rbp), %rsi
leaq 0x7c2f3(%rip), %rdi     # 0x8a519
callq 0xdea0
movq 0x10(%rbp), %rdi
addq $0x8, %rdi
movq 0x10(%rbp), %rax
movq (%rax), %rdx
subq $0x1, %rdx
leaq 0x7c361(%rip), %rsi     # 0x8a5a6
callq 0xc320
movq 0x10(%rbp), %rdx
addq $0x8, %rdx
leaq 0x7c368(%rip), %rdi     # 0x8a5c1
movl $0x1, %esi
movb $0x0, %al
callq 0xcd10
movl $0x1, %eax
addq $0x50, %rsp
popq %rbp
retq