// File: 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
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x260(%rbp)
jmp 0x79168
movq -0x260(%rbp), %rax
cmpq $0x0, 0x90(%rax)
jne 0x7919f
jmp 0x7917b
jmp 0x7917d
movq -0x260(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x5ea00
andb $0x1, %al
movb %al, -0x1(%rbp)
jmp 0x79419
movb $0x1, -0x29(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2ec80
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2eca0
movq %rax, -0x48(%rbp)
leaq -0x250(%rbp), %rdi
xorl %esi, %esi
movl $0x208, %edx            # imm = 0x208
callq 0xc350
movq -0x260(%rbp), %rcx
movq $0x200, -0x250(%rbp) # imm = 0x200
movq 0x90(%rcx), %rax
movq 0xb8(%rcx), %rdi
movq -0x38(%rbp), %rcx
movq 0x38(%rcx), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
leaq -0x250(%rbp), %r8
callq *%rax
movq %rax, -0x258(%rbp)
leaq -0x250(%rbp), %rsi
addq $0x8, %rsi
movq -0x28(%rbp), %rdi
callq 0xc920
cmpq $0x0, -0x258(%rbp)
jge 0x792f0
jmp 0x7923c
leaq 0x5b465(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
cmpq $0x0, %rax
je 0x792e8
leaq 0x5b44c(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25800
leaq 0x5b43d(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
movq %rax, %rdi
leaq 0x2cf33(%rip), %rsi     # 0xa61b0
callq 0xc670
movq %rax, %rdi
leaq 0x2f606(%rip), %rsi     # 0xa8892
callq 0xc670
movq %rax, %rdi
leaq 0x2f6fb(%rip), %rsi     # 0xa8996
callq 0xc670
movq %rax, %rdi
leaq 0x2f706(%rip), %rsi     # 0xa89b0
callq 0xc670
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0xc5b0
movq %rax, %rdi
leaq 0x2f10e(%rip), %rsi     # 0xa83d3
callq 0xc670
movq %rax, %rdi
movq 0x5acec(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x5b3c8(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25820
jmp 0x792ea
movb $0x0, -0x29(%rbp)
jmp 0x79300
movq -0x20(%rbp), %rdi
movq -0x258(%rbp), %rsi
callq 0x2ecc0
movq -0x20(%rbp), %rdi
callq 0x2ec80
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2eca0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jg 0x793d8
jmp 0x79327
leaq 0x5b37a(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
cmpq $0x0, %rax
je 0x793d4
leaq 0x5b361(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e900
leaq 0x5b352(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e8e0
movq %rax, %rdi
leaq 0x2d201(%rip), %rsi     # 0xa6569
callq 0xc670
movq %rax, %rdi
leaq 0x2f670(%rip), %rsi     # 0xa89e7
callq 0xc670
movq %rax, %rdi
leaq 0x2cfde(%rip), %rsi     # 0xa6364
callq 0xc670
movq %rax, %rdi
movl $0x129, %esi            # imm = 0x129
callq 0xcb80
movq %rax, %rdi
leaq 0x2f65f(%rip), %rsi     # 0xa8a01
callq 0xc670
movq %rax, %rdi
leaq 0x2eb5b(%rip), %rsi     # 0xa7f0c
callq 0xc670
movq %rax, %rdi
movq 0x5ac00(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x5b2dc(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x2e920
jmp 0x793d6
jmp 0x793d8
jmp 0x793da
movq -0x40(%rbp), %rax
movb $0x7c, (%rax)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x2ecc0
movq -0x38(%rbp), %rax
movq %rax, -0x268(%rbp)
cmpq $0x0, %rax
je 0x7940d
movq -0x268(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x7940f
jmp 0x79411
movb -0x29(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
nopw (%rax,%rax)