// File: /workspace/github_cpp_makefile_star2_O3/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 $0x228, %rsp            # imm = 0x228
movq %rsi, %r15
movq 0x98(%rdi), %rax
testq %rax, %rax
je 0x4b9e8
movq %rax, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movq %rdx, 0x18(%rsp)
movq 0x8(%r15), %rbx
movq 0x20(%r15), %rbp
movq 0x28(%r15), %r14
leaq (%rbx,%r14), %r13
movq %rbp, %rdx
subq %r14, %rdx
movq %r13, %rdi
movl $0x7c, %esi
callq 0xb5b0
movq %rax, %r12
testq %rax, %rax
jne 0x4b936
movq 0x38(%r15), %rax
testq %rax, %rax
je 0x4b906
movq %r15, %rdi
callq *%rax
movq 0x8(%r15), %rbx
movq 0x20(%r15), %rbp
movq 0x28(%r15), %r14
leaq (%rbx,%r14), %r13
movq %rbp, %rdx
subq %r14, %rdx
movq %r13, %rdi
movl $0x7c, %esi
callq 0xb5b0
testq %rax, %rax
je 0x4b8ec
movq %rax, %r12
movq 0x8(%rsp), %rax
movq 0x98(%rax), %rax
movq %rax, 0x10(%rsp)
subq %r13, %r12
leaq 0x28(%rsp), %rbp
movl $0x200, %edx            # imm = 0x200
movq %rbp, %rdi
xorl %esi, %esi
callq 0xb2d0
movq $0x200, -0x8(%rbp)      # imm = 0x200
movq 0x8(%rsp), %rax
movq 0xb8(%rax), %rdi
leaq 0x20(%rsp), %rcx
movq %r13, %rsi
movq %r12, %rdx
callq *0x10(%rsp)
movq %rax, %r13
movq 0x18(%rsp), %r14
movq 0x8(%r14), %rbx
movq %rbp, %rdi
callq 0xb200
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %rbp, %rcx
movq %rax, %r8
callq 0xb870
testq %r13, %r13
je 0x4ba01
movq 0x28(%r15), %rax
addq %r12, %rax
incq %rax
movq %rax, 0x28(%r15)
movl $0x40, %edi
callq 0xb500
movq 0x8(%rsp), %rcx
movq %rcx, 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 0x3f4ec(%rip), %rcx     # 0x8aec8
movq %rcx, (%rax)
movq %r13, 0x38(%rax)
jmp 0x4bad4
movq %r15, %rsi
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3646c
leaq 0x40b68(%rip), %r15     # 0x8c570
movq (%r15), %rdi
cmpq $0x0, 0x8(%rdi)
je 0x4bad2
addq $0x20, %rdi
callq 0xb7d0
movq (%r15), %rax
movq %r14, %rbx
movq 0x8(%rax), %r14
leaq 0x1e778(%rip), %rsi     # 0x6a1a8
movl $0xb, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0x20e4e(%rip), %rsi     # 0x6c892
movl $0xf, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0x1eaf5(%rip), %rsi     # 0x6a54d
movl $0x17, %edx
movq %r14, %rdi
callq 0xb5f0
leaq 0x20ef3(%rip), %rsi     # 0x6c95f
movl $0x36, %edx
movq %r14, %rdi
callq 0xb5f0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0xb5f0
movq %rax, %rbx
leaq 0x20941(%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 (%r15), %rdi
addq $0x20, %rdi
callq 0xb3b0
xorl %eax, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq