// File: /workspace/github_cpp_makefile_star2_O2/mh0fm4[P]SCDC/src/components/dataprov/dataprov_hook.cc
// Function: scdc_dataprov_hook::dataset_close_write_state(scdc_dataset*, scdc_data*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool scdc_dataprov_hook::dataset_close_write_state(scdc_dataset *dataset, scdc_data *outgoing, scdc_result &result)
{
  SCDC_TRACE("dataset_close_write_state: dataset: '" << dataset << "'");

  if (!hook_arg.hook.dataset_close_write_state)
  {
    SCDC_TRACE("dataset_close_write_state: using fallback");
    return scdc_dataprov::dataset_close_write_state(dataset, outgoing, result);
  }

  bool ret = true;

  scdc_dataset_hook *dataset_hook = static_cast<scdc_dataset_hook *>(dataset);

  char *buf = outgoing->get_write_pos_buf();
  scdcint_t buf_size = outgoing->get_write_pos_buf_size();

  scdc_result_t res = SCDC_RESULT_INIT_EMPTY;
  scdcint_t n = hook_arg.hook.dataset_close_write_state(dataprov, dataset_hook->dataset, buf, buf_size, &res);
  result = SCDC_RESULT_STR(&res);

  if (n < 0)
  {
    SCDC_FAIL(__func__ << ": closing dataset by writing state with hook failed: '" << result << "'");
    ret = false;

  } else
  {
    outgoing->inc_write_pos(n);
  }

  buf = outgoing->get_write_pos_buf();
  buf_size = outgoing->get_write_pos_buf_size();

  SCDC_ASSERT(buf_size > 0);

  buf[0] = '|';

  outgoing->inc_write_pos(1);

  delete dataset_hook;

  SCDC_TRACE("dataset_close_write_state: return: " << ret);

  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, %r8
movq %rdi, %r15
movq 0x90(%rdi), %r12
testq %r12, %r12
je 0x3b600
movq %rcx, 0x10(%rsp)
movq 0x10(%r8), %r13
movq 0x20(%r8), %rax
movq 0x8(%r8), %rbp
addq %rax, %rbp
subq %rax, %r13
movq %rsi, %rbx
leaq 0x28(%rsp), %r14
movl $0x200, %edx            # imm = 0x200
movq %r14, %rdi
movq %r8, 0x8(%rsp)
xorl %esi, %esi
callq 0xb2f0
movq $0x200, -0x8(%r14)      # imm = 0x200
movq 0xb8(%r15), %rdi
movq %rbx, 0x18(%rsp)
movq 0x38(%rbx), %rsi
leaq 0x20(%rsp), %r8
movq %rbp, %rdx
movq %r13, %rcx
movq 0x10(%rsp), %r13
callq *%r12
movq %rax, %r15
movq %r13, %rdi
movq %r14, %rsi
callq 0xba40
testq %r15, %r15
js 0x3b61c
movq 0x8(%rsp), %r14
addq %r15, 0x20(%r14)
jmp 0x3b6a9
movq %r15, %rdi
movq %r8, %rdx
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2e442
leaq 0x39f5d(%rip), %rbx     # 0x75580
movq (%rbx), %rdi
cmpq $0x0, 0x8(%rdi)
movq 0x8(%rsp), %r14
je 0x3b6a9
addq $0x20, %rdi
callq 0xb800
movq (%rbx), %rax
movq 0x8(%rax), %rdi
leaq 0x15b3f(%rip), %rsi     # 0x51188
callq 0xb520
leaq 0x181cd(%rip), %rsi     # 0x53822
movq %rax, %rdi
callq 0xb520
leaq 0x182c2(%rip), %rsi     # 0x53926
movq %rax, %rdi
callq 0xb520
leaq 0x182cd(%rip), %rsi     # 0x53940
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
movq %r13, %rsi
callq 0xb490
leaq 0x17cd6(%rip), %rsi     # 0x53363
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%rbx), %rdi
addq $0x20, %rdi
callq 0xb3e0
movq 0x8(%r14), %r12
movq 0x20(%r14), %r13
cmpq %r13, 0x10(%r14)
jg 0x3b745
leaq 0x39ebe(%rip), %rbx     # 0x75580
movq (%rbx), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x3b745
addq $0x20, %rdi
callq 0xb800
movq (%rbx), %rax
movq 0x18(%rax), %rdi
leaq 0x15e66(%rip), %rsi     # 0x51549
callq 0xb520
leaq 0x18288(%rip), %rsi     # 0x53977
movq %rax, %rdi
callq 0xb520
leaq 0x15c46(%rip), %rsi     # 0x51344
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
movl $0x129, %esi            # imm = 0x129
callq 0xb990
leaq 0x18277(%rip), %rsi     # 0x53991
movq %rax, %rdi
callq 0xb520
leaq 0x17767(%rip), %rsi     # 0x52e90
movq %rax, %rdi
callq 0xb520
movq %rax, %rdi
callq 0xb270
movq (%rbx), %rdi
addq $0x20, %rdi
callq 0xb3e0
testq %r15, %r15
setns %bl
movb $0x7c, (%r12,%r13)
incq 0x20(%r14)
movq 0x18(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movl %ebx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop