// File: /workspace/github_cpp_makefile_star2_O2/mh0fm4[P]SCDC/src/components/compcoup/compcoup_transport.cc
// Function: scdc_compcoup_transport::on_dataset_cmd(scdc_transport_connection_t*)
void scdc_compcoup_transport::on_dataset_cmd(scdc_transport_connection_t *conn)
{
  SCDC_TRACE("on_dataset_cmd:");

  /* read request: DATASET_CMD <output-info> (STATE <state>|NOSTATE) <cmd> (<input-info> <input-data> )+ */

  bool output_next = false;
  scdc_dataset_transport::read_output_info(conn, 0, output_next);

  scdc_dataset_output_t output = *transport->acquire_outgoing_dataset_output(conn);

  string s;
  scdc_dataset_transport::read_delim(conn, &s, default_delim);

  /* send answer: DATASET_CMD (<output-info> <output-data> )+(OK|FAILED) (STATE <state>|<NOSTATE) RESULT <string> (<output-info> <output-data> )+ */

  scdc_dataset_transport::write_delim(conn, "DATASET_CMD", -1, default_delim);

  bool stateless = true;
  scdc_dataset *dataset = 0;

  scdc_result result;

  if (s == "STATE")
  {
    stateless = false;

    scdc_dataset_transport::read_state_begin(conn);
    dataset = dataprovs->dataset_open_read_state(conn->get_incoming(), result);
    scdc_dataset_transport::read_state_end(conn);

  } else
  {
    SCDC_ASSERT(s == "NOSTATE");
  }

  /* read cmd */
  scdc_dataset_transport::read_string(conn, &s);

  /* prepare input */
  scdc_dataset_input_t input = *transport->acquire_incoming_dataset_input(conn);

  input.next = 0;
  input.data = 0;

  bool input_next;
  dataset_input_incoming_consume(conn, &input, &input_next);

  if (input_next)
  {
    input.next = read_input_next;
    input.data = conn;

  } else
  {
    if (conn->current_incoming_input_intern)
    {
      input.next = read_input_next;
      input.data = conn;

      conn->current_incoming_input_intern = false;

    } else
    {
      input.next = 0;
      input.data = 0;
    }
  }

  /* prepare output */
  if (output_next)
  {
    output.next = write_output_next;
    output.data = conn;

  } else
  {
    output.next = 0;
    output.data = 0;
  }

  bool ret = false;

  if (stateless)
  {
    ret = scdc_compcoup::dataset_cmd(s, &input, &output, result);

  } else if (dataset)
  {
    ret = dataset->do_cmd(s, &input, &output, result);

  } else
  {
    /* error: not stateless but also no dataset handle available */
    SCDC_ERROR("no dataset available");
  }

  if (input.next == read_input_next)
  {
    /* consume remaining input */
    input.next = read_input_next_dummy;
    input.data = 0;

    dataset_input_incoming_consume(conn, &input, &input_next);
    SCDC_ASSERT(!input_next);
  }

  transport->release_incoming_dataset_input(conn);

  /* finalize immediate output */
  dataset_output_outgoing_produce(conn, 0);

  if (output.next == write_output_next)
  {
    output.next = 0;
    output.data = 0;
  }

  if (ret)
  {
    scdc_dataset_transport::write_delim(conn, "OK", -1, default_delim);

  } else
  {
    SCDC_FAIL("on_dataset_cmd: dataset_cmd failed");
    scdc_dataset_transport::write_delim(conn, "FAILED", -1, default_delim);
  }

  if (stateless)
  {
    scdc_dataset_transport::write_delim(conn, "NOSTATE", -1, default_delim);

  } else if (dataset)
  {
    scdc_dataset_transport::write_delim(conn, "STATE", -1, default_delim);
    scdc_dataset_transport::write_state_begin(conn);
    dataprovs->dataset_close_write_state(dataset, conn->get_outgoing(), result);
    scdc_dataset_transport::write_state_end(conn);
  }

  scdc_dataset_transport::write_delim(conn, "RESULT", -1, default_delim);
  scdc_dataset_transport::write_string(conn, result.c_str(), result.size());

  dataset_output_outgoing_produce(conn, &output);

  transport->release_outgoing_dataset_output(conn);

  transport->send_outgoing(conn);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
leaq 0x7(%rsp), %rdx
movb %r15b, (%rdx)
movq %rsi, %rdi
xorl %esi, %esi
callq 0x4f8ac
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x98(%rax)
pushq $0xb
popq %rcx
leaq 0xa0(%rsp), %rdi
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %r15b, (%rax)
leaq 0x28(%rsp), %rsi
pushq $0x20
popq %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x4ee36
leaq 0x6f72(%rip), %rsi      # 0x54f55
pushq $-0x1
popq %rdx
pushq $0x20
popq %rcx
movq %rbx, %rdi
callq 0x4ed78
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x6e84(%rip), %rsi      # 0x54e8d
leaq 0x28(%rsp), %rdi
callq 0x19be0
movl %eax, %ebp
testb %al, %al
je 0x4e043
movq %rbx, %rdi
callq 0x4f370
movq 0x8(%r14), %rdi
leaq 0x30(%rbx), %rsi
leaq 0x8(%rsp), %rdx
callq 0x1c46e
movq %rax, %r15
movq %rbx, %rdi
callq 0x4f422
jmp 0x4e0e9
leaq 0x6e41(%rip), %rsi      # 0x54e8b
leaq 0x28(%rsp), %rdi
callq 0x19be0
testb %al, %al
jne 0x4e0e6
leaq 0x2751d(%rip), %r15     # 0x75580
movq (%r15), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4e0e6
addq $0x20, %rdi
callq 0xb800
movq (%r15), %rax
movq 0x18(%rax), %rdi
leaq 0x34c5(%rip), %rsi      # 0x51549
callq 0xb520
leaq 0x6dad(%rip), %rsi      # 0x54e3d
movq %rax, %rdi
callq 0xb520
leaq 0x32a5(%rip), %rsi      # 0x51344
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
movl $0x531, %esi            # imm = 0x531
callq 0xb990
leaq 0x6dd8(%rip), %rsi      # 0x54e93
movq %rax, %rdi
callq 0xb520
leaq 0x4dc6(%rip), %rsi      # 0x52e90
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%r15), %rdi
addq $0x20, %rdi
callq 0xb3e0
xorl %r15d, %r15d
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x4f064
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x88(%rax)
pushq $0xb
popq %rcx
leaq 0x48(%rsp), %r8
movq %r8, %rdi
movq %rax, %rsi
rep  movsq (%rsi), %es:(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r8)
leaq 0x6(%rsp), %rdx
movq %rbx, %rdi
movq %r8, %rsi
callq 0x4eb24
cmpb $0x1, 0x6(%rsp)
leaq 0xb89(%rip), %r13       # 0x4ecc4
jne 0x4e14f
movq %r13, 0x80(%rsp)
movq %rbx, 0x88(%rsp)
jmp 0x4e17f
cmpb $0x1, 0x2d2(%rbx)
jne 0x4e171
movq %r13, 0x80(%rsp)
movq %rbx, 0x88(%rsp)
movb $0x0, 0x2d2(%rbx)
jmp 0x4e17f
leaq 0x80(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
leaq 0xbb2(%rip), %rdx       # 0x4ed38
xorl %eax, %eax
cmpb $0x0, 0x7(%rsp)
movl $0x0, %ecx
cmovneq %rdx, %rcx
cmovneq %rbx, %rax
movq %rcx, 0xd8(%rsp)
movq %rax, 0xe0(%rsp)
testb %bpl, %bpl
je 0x4e1da
testq %r15, %r15
je 0x4e45d
movq (%r15), %rax
leaq 0x28(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r15, %rdi
callq *0x10(%rax)
jmp 0x4e1f9
leaq 0x28(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
leaq 0x8(%rsp), %r8
movq %r14, %rdi
callq 0x4faa0
movl %eax, %r12d
cmpq %r13, 0x80(%rsp)
jne 0x4e2c4
leaq 0xb62(%rip), %rax       # 0x4ed73
leaq 0x48(%rsp), %rsi
movq %rax, 0x38(%rsi)
andq $0x0, 0x40(%rsi)
leaq 0x6(%rsp), %rdx
movq %rbx, %rdi
callq 0x4eb24
cmpb $0x1, 0x6(%rsp)
jne 0x4e2c4
leaq 0x27342(%rip), %r13     # 0x75580
movq (%r13), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4e2c4
addq $0x20, %rdi
callq 0xb800
movq (%r13), %rax
movq 0x18(%rax), %rdi
leaq 0x32e8(%rip), %rsi      # 0x51549
callq 0xb520
leaq 0x6bd0(%rip), %rsi      # 0x54e3d
movq %rax, %rdi
callq 0xb520
leaq 0x30c8(%rip), %rsi      # 0x51344
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
movl $0x578, %esi            # imm = 0x578
callq 0xb990
leaq 0x716c(%rip), %rsi      # 0x55404
movq %rax, %rdi
callq 0xb520
leaq 0x4be9(%rip), %rsi      # 0x52e90
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%r13), %rdi
addq $0x20, %rdi
callq 0xb3e0
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x90(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4ec2a
leaq 0xa53(%rip), %rax       # 0x4ed38
cmpq %rax, 0xd8(%rsp)
jne 0x4e2fd
leaq 0xd8(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
testb %r12b, %r12b
je 0x4e30b
leaq 0x222b(%rip), %r12      # 0x50534
jmp 0x4e374
leaq 0x2726e(%rip), %r13     # 0x75580
movq (%r13), %rdi
leaq 0x6b56(%rip), %r12      # 0x54e73
cmpq $0x0, 0x8(%rdi)
je 0x4e374
addq $0x20, %rdi
callq 0xb800
movq (%r13), %rax
movq 0x8(%rax), %rdi
leaq 0x2e4c(%rip), %rsi      # 0x51188
callq 0xb520
leaq 0x6ab7(%rip), %rsi      # 0x54dff
movq %rax, %rdi
callq 0xb520
leaq 0x70bc(%rip), %rsi      # 0x55413
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%r13), %rdi
addq $0x20, %rdi
callq 0xb3e0
pushq $-0x1
popq %rdx
pushq $0x20
popq %rcx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4ed78
testb %bpl, %bpl
je 0x4e3cb
testq %r15, %r15
je 0x4e3e0
leaq 0x6af7(%rip), %rsi      # 0x54e8d
pushq $-0x1
popq %rdx
pushq $0x20
popq %rcx
movq %rbx, %rdi
callq 0x4ed78
movq %rbx, %rdi
callq 0x4f290
movq 0x8(%r14), %rdi
leaq 0x70(%rbx), %rdx
leaq 0x8(%rsp), %rcx
movq %r15, %rsi
callq 0x1c5f2
movq %rbx, %rdi
callq 0x4f2a0
jmp 0x4e3e0
leaq 0x6ab9(%rip), %rsi      # 0x54e8b
pushq $-0x1
popq %rdx
pushq $0x20
popq %rcx
movq %rbx, %rdi
callq 0x4ed78
leaq 0x6abe(%rip), %rsi      # 0x54ea5
pushq $-0x1
popq %rdx
pushq $0x20
popq %rcx
movq %rbx, %rdi
callq 0x4ed78
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x4f2ce
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
callq 0x4ec2a
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0xa0(%rax)
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0xd0(%rax)
leaq 0x8(%rsp), %rdi
callq 0xb230
leaq 0x28(%rsp), %rdi
callq 0xb230
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2711c(%rip), %r12     # 0x75580
movq (%r12), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4e4bf
addq $0x20, %rdi
callq 0xb800
movq (%r12), %rax
movq 0x18(%rax), %rdi
leaq 0x3001(%rip), %rsi      # 0x51488
callq 0xb520
leaq 0x696c(%rip), %rsi      # 0x54dff
movq %rax, %rdi
callq 0xb520
leaq 0x6f4d(%rip), %rsi      # 0x553ef
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%r12), %rdi
addq $0x20, %rdi
callq 0xb3e0
xorl %r12d, %r12d
jmp 0x4e1fc
jmp 0x4e4d2
jmp 0x4e4d2
movq %rax, %rbx
jmp 0x4e4df
jmp 0x4e4d2
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xb230
leaq 0x28(%rsp), %rdi
callq 0xb230
movq %rbx, %rdi
callq 0xb9a0
nop