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

  if (!hook_arg.hook.dataset_open_read_state)
  {
    SCDC_TRACE("dataset_open_read_state: using fallback");
    return scdc_dataprov::dataset_open_read_state(incoming, result);
  }

  char *buf;
  scdcint_t buf_size;
  const char *end;

  while (1)
  {
    buf = incoming->get_read_pos_buf();
    buf_size = incoming->get_read_pos_buf_size();
    end = memchr(buf, '|', buf_size);

    if (end) break;

    incoming->do_next();
  }

  buf_size = end - buf;

  scdc_result_t res = SCDC_RESULT_INIT_EMPTY;
  void *dataset = hook_arg.hook.dataset_open_read_state(dataprov, buf, buf_size, &res);
  result = SCDC_RESULT_STR(&res);

  if (!dataset)
  {
    SCDC_FAIL(__func__ << ": opening dataset by reading state with hook failed: '" << result << "'");
    return 0;
  }

  incoming->inc_read_pos(end - buf + 1);

  scdc_dataset_hook *dataset_hook = new scdc_dataset_hook(this, dataset);

  SCDC_TRACE("dataset_open_read_state: dataset_hook: '" << dataset_hook << "'");

  return dataset_hook;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x268(%rbp)
jmp 0x78eb4
movq -0x268(%rbp), %rax
cmpq $0x0, 0x98(%rax)
jne 0x78ee6
jmp 0x78ec7
jmp 0x78ec9
movq -0x268(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x5e760
movq %rax, -0x8(%rbp)
jmp 0x790ea
jmp 0x78ee8
movq -0x18(%rbp), %rdi
callq 0x2ebe0
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2ec00
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rdx
movl $0x7c, %esi
callq 0x79110
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x78f21
jmp 0x78f2c
movq -0x18(%rbp), %rdi
callq 0x2ec20
jmp 0x78ee8
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
leaq -0x240(%rbp), %rdi
xorl %esi, %esi
movl $0x208, %edx            # imm = 0x208
callq 0xc350
movq -0x268(%rbp), %rcx
movq $0x200, -0x240(%rbp) # imm = 0x200
movq 0x98(%rcx), %rax
movq 0xb8(%rcx), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x240(%rbp), %rcx
callq *%rax
movq %rax, -0x248(%rbp)
leaq -0x240(%rbp), %rsi
addq $0x8, %rsi
movq -0x20(%rbp), %rdi
callq 0xc920
cmpq $0x0, -0x248(%rbp)
jne 0x79065
jmp 0x78faa
leaq 0x5b6f7(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
cmpq $0x0, %rax
je 0x79056
leaq 0x5b6de(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25800
leaq 0x5b6cf(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x257e0
movq %rax, %rdi
leaq 0x2d1c5(%rip), %rsi     # 0xa61b0
callq 0xc670
movq %rax, %rdi
leaq 0x2f898(%rip), %rsi     # 0xa8892
callq 0xc670
movq %rax, %rdi
leaq 0x2d544(%rip), %rsi     # 0xa654d
callq 0xc670
movq %rax, %rdi
leaq 0x2f947(%rip), %rsi     # 0xa895f
callq 0xc670
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0xc5b0
movq %rax, %rdi
leaq 0x2f3a0(%rip), %rsi     # 0xa83d3
callq 0xc670
movq %rax, %rdi
movq 0x5af7e(%rip), %rsi     # 0xd3fc0
callq 0xc6d0
leaq 0x5b65a(%rip), %rax     # 0xd46a8
movq (%rax), %rdi
callq 0x25820
jmp 0x79058
movq $0x0, -0x8(%rbp)
jmp 0x790ea
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x28(%rbp), %rax
subq %rax, %rsi
incq %rsi
callq 0x2ec60
movl $0x40, %edi
callq 0xc690
movq -0x268(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x270(%rbp)
movq -0x248(%rbp), %rdx
callq 0x79b50
jmp 0x790a8
movq -0x270(%rbp), %rax
movq %rax, -0x250(%rbp)
jmp 0x790b8
movq -0x250(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x790ea
movq -0x270(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x258(%rbp)
movl %eax, -0x25c(%rbp)
movl $0x40, %esi
callq 0xc6a0
jmp 0x790f7
movq -0x8(%rbp), %rax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x258(%rbp), %rdi
callq 0xcba0
nopw %cs:(%rax,%rax)