// File: /workspace/github_cpp_makefile_star2_O2/mh0fm4[P]SCDC/src/lib/scdc/scdc.cc
// Function: scdc_dataset_cmd_intern
scdcint_t scdc_dataset_cmd_intern(scdc_dataset_t dataset, const char *cmd, scdc_dataset_input_t *input, scdc_dataset_output_t *output, scdc_args_t *args)
{
  SCDC_TRACE(__func__ << ": dataset: '" << dataset << "', cmd = '" << string(cmd) << "'" << ", input = " << static_cast<void *>(input) << ", output = " << static_cast<void *>(output));

  scdcint_t cmd_size = strlen(cmd);

  string adhoc_cmd;

  if (dataset == SCDC_DATASET_NULL)
  {
    dataset = new _scdc_dataset_t;
    dataset->dataset = 0;

    cmd_size = strlen(cmd);

    string suri, scmd, sparams;
    split_cmdline(cmd, cmd_size, &scmd, &suri, &sparams);

    if (suri.size() <= 0)
    {
      SCDC_RESULT_SET_STR(scdc_main_context.data->result, "no URI given");
      SCDC_FAIL(__func__ << ": " << SCDC_RESULT_STR(scdc_main_context.data->result));
      delete dataset;
      return SCDC_FAILURE;
    }

    string sscheme, sauthority, spath;
    split_uri(suri.c_str(), suri.size(), &sscheme, &sauthority, &spath);

    scdc_args xargs(args);

    dataset->nodeconn = scdc_main_context.data->nodeconns.open(sscheme.c_str(), sauthority.c_str(), &xargs);

    if (!dataset->nodeconn)
    {
      SCDC_RESULT_SET_STR(scdc_main_context.data->result, "open connection failed");
      SCDC_FAIL(__func__ << ": " << SCDC_RESULT_STR(scdc_main_context.data->result));
      delete dataset;
      return SCDC_FAILURE;
    }

    join_uri(0, 0, spath.c_str(), suri);
    suri = ":" + suri;

    join_cmdline(scmd.c_str(), suri.c_str(), sparams.c_str(), adhoc_cmd);

    cmd = adhoc_cmd.c_str();
    cmd_size = adhoc_cmd.size();
  }

  SCDC_TRACE(__func__ << ": adhoc command: '" << adhoc_cmd << "'");

  scdc_dataset_input_t input_null = *SCDC_DATASET_INPUT_NONE;
  if (!input) input = &input_null;

  scdc_dataset_output_t output_null = *SCDC_DATASET_OUTPUT_ENDL;
  if (!output) output = &output_null;

  /* backup original output */
  scdc_dataset_output_t output_given = *output;
  scdc_dataset_inout_intern_t output_intern_given = (output->intern)?*output->intern:SCDC_DATASET_OUTPUT_INTERN_NULL;

  SCDC_TRACE_DATASET_INPUT(input, "scdc_dataset_cmd_intern: IN input: ");
  SCDC_TRACE_DATASET_OUTPUT(output, "scdc_dataset_cmd_intern: IN output: ");

  scdcint_t output_next_hash_in = scdc_dataset_inout_next_hash(output);

  bool ret;
  scdc_result result;

  double cmd_timing = z_time_wtime();

  if (dataset->dataset) ret = dataset->dataset->do_cmd(string(cmd, cmd_size), input, output, result);
  else ret = dataset->nodeconn->dataset_cmd(string(cmd, cmd_size), input, output, result);

  cmd_timing = z_time_wtime() - cmd_timing;
  SCDC_TRACE(__func__ << ": timing: " << cmd_timing);

  SCDC_TRACE(__func__ << ": result: '" << result << "'");

  SCDC_RESULT_SET_STR(scdc_main_context.data->result, result.c_str());

  scdcint_t output_next_hash_out = scdc_dataset_inout_next_hash(output);

  SCDC_TRACE_DATASET_INPUT(input, "scdc_dataset_cmd_intern: OUT input: ");
  SCDC_TRACE_DATASET_OUTPUT(output, "scdc_dataset_cmd_intern: OUT output: ");

  /* if there was an output next given, but the resulting cmd output is different */
  if (output_given.next && output_next_hash_in != output_next_hash_out)
  {
    SCDC_TRACE(__func__ << ": redirecting cmd output to given output");
    scdc_dataset_output_redirect(output, "to:outputsink", &output_given);

    /* restore original output */
    *output = output_given;

    if (output->intern) *output->intern = output_intern_given;
  }

  if (ret)
  {
    SCDC_TRACE(__func__ << ": successful");

/*    SCDC_INFO("scdc_dataset_cmd: timing: " << cmd_timing << ", input: " << ((input)?input->total_size:0) / cmd_timing * 1e-6 << " MB/s, output: " << ((output)?output->total_size:0) / cmd_timing * 1e-6 << " MB/s");*/

  } else SCDC_TRACE(__func__ << ": failed: '" << SCDC_DATASET_OUTPUT_STR(output) << "'");

  if (!dataset->dataset)
  {
    scdc_main_context.data->nodeconns.close(dataset->nodeconn);

    delete dataset;
    dataset = SCDC_DATASET_NULL;
  }

/*  if (ret) SCDC_INFO("using dataset " << dataset << " to execute command '" << cmd << "'");*/

  return (ret)?SCDC_SUCCESS:SCDC_FAILURE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %r8, %rbp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, %rdi
callq 0xb210
leaq 0x90(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
testq %rbx, %rbx
je 0x18a28
movq %rax, %r13
jmp 0x18dc4
pushq $0x20
popq %rdi
callq 0xb540
movq %rax, %rbx
movq %rax, %rdi
callq 0x19ab2
andq $0x0, 0x8(%rbx)
movq %r12, %rdi
callq 0xb210
leaq 0xd0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movq %rax, %r13
xorl %eax, %eax
leaq 0x128(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %al, (%rcx)
movb %al, (%rdx)
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x118(%rsp), %rdx
leaq 0xc0(%rsp), %rcx
leaq 0x50(%rsp), %r8
movq %r12, %rdi
movq %r13, %rsi
callq 0x1a97b
movq 0xc8(%rsp), %rsi
testq %rsi, %rsi
je 0x18bea
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq 0x18(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
leaq 0xb0(%rsp), %rdi
movq %rdi, -0x10(%rdi)
andq $0x0, -0x8(%rdi)
movb %cl, (%rax)
movb %cl, (%rdx)
movb %cl, (%rdi)
movq 0xc0(%rsp), %rdi
leaq 0x30(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0xa0(%rsp), %r8
callq 0x1ac7a
leaq 0x1b0(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movaps %xmm0, -0x20(%rax)
movaps %xmm1, -0x10(%rax)
movl $0x98, %edi
addq 0x5cac8(%rip), %rdi     # 0x75600
movq 0x30(%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x190(%rsp), %rcx
callq 0x2aff2
movq %rax, (%rbx)
testq %rax, %rax
setne %bpl
je 0x18cad
movq 0xa0(%rsp), %rdx
leaq 0xc0(%rsp), %rcx
xorl %edi, %edi
xorl %esi, %esi
callq 0x1aeac
leaq 0x387c5(%rip), %rsi     # 0x51344
leaq 0x170(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x19ae2
leaq 0xc0(%rsp), %r12
leaq 0x170(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xb690
movq %r13, %rdi
callq 0xb230
movq 0x118(%rsp), %rdi
movq (%r12), %rsi
movq 0x50(%rsp), %rdx
leaq 0x80(%rsp), %rcx
callq 0x1abbc
movq 0x80(%rsp), %r12
movq 0x88(%rsp), %r13
jmp 0x18d69
movq 0x5ca0f(%rip), %rax     # 0x75600
movq (%rax), %rdi
movq (%rdi), %rdx
addq $0x8, %rdi
decq %rdx
leaq 0x385e5(%rip), %rsi     # 0x511ea
callq 0xb2c0
movq 0x5c96f(%rip), %rdi     # 0x75580
cmpq $0x0, 0x8(%rdi)
je 0x18c93
addq $0x20, %rdi
callq 0xb800
movq 0x5c958(%rip), %rax     # 0x75580
movq 0x8(%rax), %rdi
leaq 0x38555(%rip), %rsi     # 0x51188
callq 0xb520
leaq 0x38555(%rip), %rsi     # 0x51194
movq %rax, %rdi
callq 0xb520
leaq 0x385a9(%rip), %rsi     # 0x511f7
movq %rax, %rdi
callq 0xb520
leaq 0x3be46(%rip), %rsi     # 0x54aa3
movq %rax, %rdi
callq 0xb520
movq 0x5c994(%rip), %rcx     # 0x75600
movq (%rcx), %rsi
addq $0x8, %rsi
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq 0x5c8f6(%rip), %rdi     # 0x75580
addq $0x20, %rdi
callq 0xb3e0
movq %rbx, %rdi
callq 0x19ad4
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0xb550
xorl %ebp, %ebp
jmp 0x18d97
movq 0x5c94c(%rip), %rax     # 0x75600
movq (%rax), %rdi
movq (%rdi), %rdx
addq $0x8, %rdi
decq %rdx
leaq 0x38547(%rip), %rsi     # 0x5120f
callq 0xb2c0
movq 0x5c8ac(%rip), %rdi     # 0x75580
cmpq $0x0, 0x8(%rdi)
je 0x18d56
addq $0x20, %rdi
callq 0xb800
movq 0x5c895(%rip), %rax     # 0x75580
movq 0x8(%rax), %rdi
leaq 0x38492(%rip), %rsi     # 0x51188
callq 0xb520
leaq 0x38492(%rip), %rsi     # 0x51194
movq %rax, %rdi
callq 0xb520
leaq 0x384e6(%rip), %rsi     # 0x511f7
movq %rax, %rdi
callq 0xb520
leaq 0x3bd83(%rip), %rsi     # 0x54aa3
movq %rax, %rdi
callq 0xb520
movq 0x5c8d1(%rip), %rcx     # 0x75600
movq (%rcx), %rsi
addq $0x8, %rsi
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq 0x5c833(%rip), %rdi     # 0x75580
addq $0x20, %rdi
callq 0xb3e0
movq %rbx, %rdi
callq 0x19ad4
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0xb550
leaq 0x190(%rsp), %rdi
callq 0x19a94
leaq 0xa0(%rsp), %rdi
callq 0xb230
leaq 0x8(%rsp), %rdi
callq 0xb230
leaq 0x30(%rsp), %rdi
callq 0xb230
leaq 0x50(%rsp), %rdi
callq 0xb230
leaq 0x118(%rsp), %rdi
callq 0xb230
leaq 0xc0(%rsp), %rdi
callq 0xb230
testb %bpl, %bpl
je 0x18fd8
leaq 0x391d5(%rip), %rsi     # 0x51fa0
pushq $0xb
popq %rax
leaq 0x190(%rsp), %rdx
movq %rax, %rcx
movq %rdx, %rdi
rep  movsq (%rsi), %es:(%rdi)
testq %r15, %r15
cmoveq %rdx, %r15
movq %r15, 0x28(%rsp)
leaq 0xc0(%rsp), %rdi
testq %r14, %r14
cmoveq %rdi, %r14
leaq 0x5a497(%rip), %rsi     # 0x73298
movq %rax, %rcx
rep  movsq (%rsi), %es:(%rdi)
leaq 0x118(%rsp), %rdi
movq %rax, %rcx
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x48(%r14), %rax
testq %rax, %rax
jne 0x18e28
leaq 0x39150(%rip), %rax     # 0x51f78
movq 0x20(%rax), %rcx
movq %rcx, 0x70(%rsp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq 0x40(%r14), %r15
xorq 0x38(%r14), %r15
xorq 0x50(%r14), %r15
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
callq 0x19086
movq 0x8(%rbx), %rbp
testq %rbp, %rbp
je 0x18ea7
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
addq %r12, %r13
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1a1f2
movq (%rbp), %rax
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %r8
movq %rbp, %rdi
movq 0x28(%rsp), %rdx
movq %r14, %rcx
callq *0x10(%rax)
jmp 0x18ee2
movq (%rbx), %rbp
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
addq %r12, %r13
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1a1f2
movq 0x60(%rbp), %rdi
movq (%rdi), %rax
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %r8
movq 0x28(%rsp), %rdx
movq %r14, %rcx
callq *0x20(%rax)
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0xb230
callq 0x19086
movq 0x5c706(%rip), %rax     # 0x75600
movq (%rax), %rdi
movq 0x30(%rsp), %rsi
movq (%rdi), %rdx
addq $0x8, %rdi
decq %rdx
callq 0xb2c0
cmpq $0x0, 0x150(%rsp)
je 0x18f7a
movq 0x40(%r14), %rax
xorq 0x38(%r14), %rax
xorq 0x50(%r14), %rax
cmpq %rax, %r15
je 0x18f7a
leaq 0x382f2(%rip), %rsi     # 0x51226
leaq 0x118(%rsp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x274da
pushq $0xb
popq %rcx
leaq 0x118(%rsp), %rsi
movq %r14, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x48(%r14), %rax
testq %rax, %rax
je 0x18f7a
movq 0x70(%rsp), %rcx
movq %rcx, 0x20(%rax)
movaps 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
cmpq $0x0, 0x8(%rbx)
jne 0x18fa8
movl $0x98, %edi
addq 0x5c673(%rip), %rdi     # 0x75600
movq (%rbx), %rsi
callq 0x2b2da
movq %rbx, %rdi
callq 0x19ad4
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0xb550
movzbl %bpl, %ebx
leaq 0x30(%rsp), %rdi
callq 0xb230
leaq 0x80(%rsp), %rdi
callq 0xb230
movq %rbx, %rax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
jmp 0x18fb6
jmp 0x19017
movq %rax, %r14
jmp 0x19027
jmp 0x18ffc
jmp 0x1900d
movq %rax, %r14
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0xb550
jmp 0x19071
movq %rax, %r14
jmp 0x19071
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0xb230
jmp 0x19010
jmp 0x1900d
movq %rax, %r14
leaq 0x30(%rsp), %rdi
jmp 0x1906c
movq %rax, %r14
leaq 0x190(%rsp), %rdi
callq 0x19a94
leaq 0xa0(%rsp), %rdi
callq 0xb230
leaq 0x8(%rsp), %rdi
callq 0xb230
leaq 0x30(%rsp), %rdi
callq 0xb230
jmp 0x1904d
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0xb230
leaq 0x118(%rsp), %rdi
callq 0xb230
leaq 0xc0(%rsp), %rdi
callq 0xb230
leaq 0x80(%rsp), %rdi
callq 0xb230
movq %r14, %rdi
callq 0xb9a0