// File: /workspace/github_c_makefile_star2_O3/AlxHnr[P]nano-backup/src/metadata.c
// Function: metadataLoad
Metadata *metadataLoad(CR_Region *r, StringView path)
{
  CR_Region *disposable_r = CR_RegionNew();
  const FileContent content = sGetFilesContent(disposable_r, path);

  /* Allocate and initialize metadata. */
  Metadata *metadata = CR_RegionAlloc(r, sizeof *metadata);
  metadata->r = r;

  metadata->current_backup.id = 0;
  metadata->current_backup.completion_time = 0;
  metadata->current_backup.ref_count = 0;

  /* Read backup history. */
  size_t reader_position = 0;

  metadata->backup_history_length =
    readSize(content, &reader_position, path);

  if(metadata->backup_history_length == 0)
  {
    metadata->backup_history = NULL;
  }
  else
  {
    metadata->backup_history =
      CR_RegionAlloc(metadata->r,
                     sSizeMul(sizeof *metadata->backup_history,
                              metadata->backup_history_length));
  }

  for(size_t id = 0; id < metadata->backup_history_length; id++)
  {
    metadata->backup_history[id].id = id;

    metadata->backup_history[id].completion_time =
      readTime(content, &reader_position, path);

    metadata->backup_history[id].ref_count = 0;
  }

  Allocator *region_wrapper = allocatorWrapRegion(metadata->r);
  metadata->config_history = readFullPathHistory(
    region_wrapper, content, &reader_position, path, metadata);

  metadata->total_path_count = readSize(content, &reader_position, path);
  metadata->path_table = strTableNew(metadata->r);

  metadata->paths = readPathSubnodes(
    region_wrapper, content, &reader_position, path, NULL, metadata);
  CR_RegionRelease(disposable_r);

  if(reader_position != content.size)
  {
    die("unneeded trailing bytes in \"" PRI_STR "\"", STR_FMT(path));
  }

  return metadata;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r13
leaq 0x70(%rsp), %rbx
callq 0xd89c
movq %rax, %rdi
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movaps (%rbx), %xmm0
movups %xmm0, (%rsp)
movq %rdi, 0x30(%rsp)
callq 0x99a5
movq %rax, %rbp
movq %rdx, %r12
movl $0x50, %esi
movq %r13, %rdi
callq 0xd960
movq %rax, %r15
movq %r13, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
xorl %eax, %eax
movq %rax, 0x18(%r15)
movq %rax, 0x18(%rsp)
movq (%rbx), %rcx
movq %rbx, %r14
movq 0x8(%rbx), %r8
movl $0x8, %esi
xorl %edi, %edi
movq %r12, 0x20(%rsp)
movq %r12, %rdx
callq 0x615b
movq %rbp, %r12
movq (%rbp), %rsi
movq $0x8, 0x18(%rsp)
movq %rsi, 0x20(%r15)
testq %rsi, %rsi
je 0x577f
movq (%r15), %r13
movl $0x18, %edi
callq 0x8790
movq %r13, %rdi
movq %rax, %rsi
callq 0xd960
cmpq $0x0, 0x20(%r15)
movq %rax, 0x28(%r15)
je 0x5787
movl $0x10, %ebx
xorl %r13d, %r13d
xorl %ebp, %ebp
leaq -0x8(%rbx), %rdi
movq %rbp, (%rax,%r13)
movq (%r14), %rcx
movq 0x8(%r14), %r8
movl $0x8, %esi
movq 0x20(%rsp), %rdx
callq 0x615b
movq 0x8(%r12,%rbp,8), %rcx
movq %rbx, 0x18(%rsp)
movq 0x28(%r15), %rax
movq %rcx, 0x8(%rax,%r13)
movq $0x0, 0x10(%rax,%r13)
incq %rbp
addq $0x18, %r13
addq $0x8, %rbx
cmpq 0x20(%r15), %rbp
jb 0x5732
jmp 0x5787
movq $0x0, 0x28(%r15)
movq (%r15), %rdi
callq 0x2828
movq %rax, 0x28(%rsp)
movq (%r14), %r8
movq 0x8(%r14), %r9
movq %r15, (%rsp)
leaq 0x18(%rsp), %r13
movq %rax, %rdi
movq %r12, %rbp
movq %r12, %rsi
movq 0x20(%rsp), %r12
movq %r12, %rdx
movq %r13, %rcx
callq 0x585e
movq %rax, 0x30(%r15)
movq (%r14), %rcx
movq 0x8(%r14), %r8
movq (%r13), %rbx
movl $0x8, %esi
movq %rbx, %rdi
movq %r12, %rdx
callq 0x615b
movq (%rbp,%rbx), %rax
addq $0x8, %rbx
movq %rbx, (%r13)
movq %rax, 0x38(%r15)
movq (%r15), %rdi
callq 0xaf98
movq %rax, 0x40(%r15)
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x5931
movq %rax, 0x48(%r15)
movq 0x30(%rsp), %rdi
callq 0xda8a
cmpq %r12, (%r13)
jne 0x5849
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%r14), %esi
movq (%r14), %rdx
leaq 0x8c51(%rip), %rdi      # 0xe4a8
xorl %eax, %eax
callq 0x3ca8