// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, %r15
movq 0x90(%rdi), %r12
testq %r12, %r12
je 0x4c0b1
movq %rcx, 0x10(%rsp)
movq %rsi, %r14
movq 0x10(%rdx), %r13
movq 0x20(%rdx), %rax
movq 0x8(%rdx), %rbp
addq %rax, %rbp
subq %rax, %r13
leaq 0x20(%rsp), %rbx
movq %rdx, 0x8(%rsp)
movl $0x208, %edx            # imm = 0x208
movq %rbx, %rdi
xorl %esi, %esi
callq 0xb2d0
movq $0x200, (%rbx)          # imm = 0x200
movq 0xb8(%r15), %rdi
movq %r14, 0x18(%rsp)
movq 0x38(%r14), %rsi
movq 0x10(%rsp), %r14
movq %rbp, %rdx
movq %r13, %rcx
movq %rbx, %r8
callq *%r12
movq %rax, %r15
leaq 0x28(%rsp), %rbx
movq 0x8(%r14), %r13
movq %rbx, %rdi
callq 0xb200
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0xb870
testq %r15, %r15
js 0x4c0ca
movq 0x8(%rsp), %r14
addq %r15, 0x20(%r14)
jmp 0x4c1a5
movq %r15, %rdi
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36996
leaq 0x4049f(%rip), %rbp     # 0x8c570
movq (%rbp), %rdi
cmpq $0x0, 0x8(%rdi)
movq 0x8(%rsp), %r14
je 0x4c1a5
addq $0x20, %rdi
callq 0xb7d0
movq (%rbp), %rax
movq 0x8(%rax), %r13
leaq 0x1e08b(%rip), %rsi     # 0x6a188
movl $0xb, %edx
movq %r13, %rdi
callq 0xb5f0
leaq 0x20709(%rip), %rsi     # 0x6c81a
movl $0xf, %edx
movq %r13, %rdi
callq 0xb5f0
leaq 0x207f9(%rip), %rsi     # 0x6c91e
movl $0x19, %edx
movq %r13, %rdi
callq 0xb5f0
leaq 0x207ff(%rip), %rsi     # 0x6c938
movl $0x36, %edx
movq %r13, %rdi
callq 0xb5f0
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %r13, %rdi
callq 0xb5f0
movq %rax, %rbx
leaq 0x201f7(%rip), %rsi     # 0x6c35b
movl $0x1, %edx
movq %rax, %rdi
callq 0xb5f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0xb4d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0xb050
movq %rax, %rdi
callq 0xb340
movq (%rbp), %rdi
addq $0x20, %rdi
callq 0xb3b0
movq 0x8(%r14), %r13
movq 0x20(%r14), %rbp
cmpq %rbp, 0x10(%r14)
jg 0x4c28b
leaq 0x403b2(%rip), %rbx     # 0x8c570
movq (%rbx), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4c28b
addq $0x20, %rdi
callq 0xb7d0
movq (%rbx), %rax
movq 0x18(%rax), %rbx
leaq 0x1e366(%rip), %rsi     # 0x6a549
movl $0xd, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0x20778(%rip), %rsi     # 0x6c96f
movl $0x19, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0x1e139(%rip), %rsi     # 0x6a344
movl $0x1, %edx
movq %rbx, %rdi
callq 0xb5f0
movq %rbx, %rdi
movl $0x129, %esi            # imm = 0x129
callq 0xb9a0
movq %rax, %r12
leaq 0x2075a(%rip), %rsi     # 0x6c989
movl $0xf, %edx
movq %rax, %rdi
callq 0xb5f0
leaq 0x1fc45(%rip), %rsi     # 0x6be88
movl $0x8, %edx
movq %r12, %rdi
callq 0xb5f0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0xb4d0
movsbl %al, %esi
movq %r12, %rdi
callq 0xb050
movq %rax, %rdi
callq 0xb340
leaq 0x402f1(%rip), %rax     # 0x8c570
movq (%rax), %rdi
addq $0x20, %rdi
callq 0xb3b0
movb $0x7c, (%r13,%rbp)
incq 0x20(%r14)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x4c2a5
movq (%rdi), %rax
callq *0x8(%rax)
testq %r15, %r15
setns %al
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop