// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
cmpq $0x0, 0x98(%rdi)
jne 0x4be49
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x367b4
movq 0x38(%r15), %rax
testq %rax, %rax
je 0x4be49
movq %r15, %rdi
callq *%rax
movq 0x20(%r15), %rdx
movq 0x28(%r15), %rax
movq 0x8(%r15), %r13
addq %rax, %r13
subq %rax, %rdx
movq %r13, %rdi
movl $0x7c, %esi
callq 0xb5b0
testq %rax, %rax
je 0x4be3b
movq %rax, %r12
subq %r13, %r12
movq %rsp, %rbp
movl $0x208, %edx            # imm = 0x208
movq %rbp, %rdi
xorl %esi, %esi
callq 0xb2d0
movq $0x200, (%rbp)          # imm = 0x200
movq 0xb8(%r14), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rbp, %rcx
callq *0x98(%r14)
movq %rax, %rbp
leaq 0x8(%rsp), %rdi
movq 0x8(%rbx), %r13
callq 0xb200
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
leaq 0x8(%rsp), %rcx
movq %rax, %r8
callq 0xb870
testq %rbp, %rbp
je 0x4bf16
movq 0x28(%r15), %rax
addq %r12, %rax
incq %rax
movq %rax, 0x28(%r15)
movl $0x40, %edi
callq 0xb500
movq %r14, 0x8(%rax)
xorl %ecx, %ecx
movb %cl, 0x10(%rax)
leaq 0x28(%rax), %rdx
movq %rdx, 0x18(%rax)
movq $0x0, 0x20(%rax)
movb %cl, 0x28(%rax)
leaq 0x3efbe(%rip), %rcx     # 0x8aec8
movq %rcx, (%rax)
movq %rbp, 0x38(%rax)
jmp 0x4bfe6
leaq 0x40653(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x4bfe4
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq 0x8(%rax), %r14
leaq 0x1e246(%rip), %rsi     # 0x6a188
movl $0xb, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0x208c4(%rip), %rsi     # 0x6c81a
movl $0xf, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0x1e5c3(%rip), %rsi     # 0x6a52d
movl $0x17, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0x20969(%rip), %rsi     # 0x6c8e7
movl $0x36, %edx
movq %r14, %rdi
callq 0xb5f0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0xb5f0
movq %rax, %rbx
leaq 0x203b7(%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 (%r15), %rdi
addq $0x20, %rdi
callq 0xb3b0
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq