// File: /workspace/github_cpp_makefile_star2_O3/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 0x4bb9d
movq 0x10(%rdx), %rbp
movq 0x20(%rdx), %rax
movq %rcx, 0x10(%rsp)
movq %rsi, %r14
movq %rdx, 0x8(%rsp)
movq 0x8(%rdx), %rbx
addq %rax, %rbx
subq %rax, %rbp
leaq 0x28(%rsp), %r13
movl $0x200, %edx            # imm = 0x200
movq %r13, %rdi
xorl %esi, %esi
callq 0xb2d0
movq $0x200, -0x8(%r13)      # imm = 0x200
movq 0xb8(%r15), %rdi
movq %r14, 0x18(%rsp)
movq 0x38(%r14), %rsi
movq 0x10(%rsp), %r14
leaq 0x20(%rsp), %r8
movq %rbx, %rdx
movq %rbp, %rcx
callq *%r12
movq %rax, %r15
movq 0x8(%r14), %rbx
movq %r13, %rdi
callq 0xb200
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0xb870
testq %r15, %r15
js 0x4bbb6
movq 0x8(%rsp), %r14
addq %r15, 0x20(%r14)
jmp 0x4bc91
movq %r15, %rdi
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x36638
leaq 0x409b3(%rip), %rbp     # 0x8c570
movq (%rbp), %rdi
cmpq $0x0, 0x8(%rdi)
movq 0x8(%rsp), %r14
je 0x4bc91
addq $0x20, %rdi
callq 0xb7d0
movq (%rbp), %rax
movq 0x8(%rax), %r13
leaq 0x1e5bf(%rip), %rsi     # 0x6a1a8
movl $0xb, %edx
movq %r13, %rdi
callq 0xb5f0
leaq 0x20c95(%rip), %rsi     # 0x6c892
movl $0xf, %edx
movq %r13, %rdi
callq 0xb5f0
leaq 0x20d85(%rip), %rsi     # 0x6c996
movl $0x19, %edx
movq %r13, %rdi
callq 0xb5f0
leaq 0x20d8b(%rip), %rsi     # 0x6c9b0
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 0x20783(%rip), %rsi     # 0x6c3d3
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 0x4bd77
leaq 0x408c6(%rip), %rbx     # 0x8c570
movq (%rbx), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x4bd77
addq $0x20, %rdi
callq 0xb7d0
movq (%rbx), %rax
movq 0x18(%rax), %rbx
leaq 0x1e89a(%rip), %rsi     # 0x6a569
movl $0xd, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0x20d04(%rip), %rsi     # 0x6c9e7
movl $0x19, %edx
movq %rbx, %rdi
callq 0xb5f0
leaq 0x1e66d(%rip), %rsi     # 0x6a364
movl $0x1, %edx
movq %rbx, %rdi
callq 0xb5f0
movq %rbx, %rdi
movl $0x129, %esi            # imm = 0x129
callq 0xb9a0
movq %rax, %r12
leaq 0x20ce6(%rip), %rsi     # 0x6ca01
movl $0xf, %edx
movq %rax, %rdi
callq 0xb5f0
leaq 0x201d1(%rip), %rsi     # 0x6bf00
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 0x40805(%rip), %rax     # 0x8c570
movq (%rax), %rdi
addq $0x20, %rdi
callq 0xb3b0
testq %r15, %r15
setns %bl
movb $0x7c, (%r13,%rbp)
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