// File: /workspace/github_c_makefile_star2_O2/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, %rbx
callq 0xd040
movq %rax, %rdi
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rdi, 0x30(%rsp)
callq 0x9246
movq %rax, %r12
movq %rdx, %r14
pushq $0x50
popq %rsi
movq %rbx, %rdi
callq 0xd104
movq %rax, %r15
movq %rbx, (%rax)
xorps %xmm0, %xmm0
andq $0x0, 0x18(%rax)
movups %xmm0, 0x8(%rax)
andq $0x0, 0x18(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
xorl %ebp, %ebp
pushq $0x8
popq %rsi
xorl %edi, %edi
movq %r14, 0x20(%rsp)
movq %r14, %rdx
callq 0x5b8f
movq %r12, %rbx
movq (%r12), %rsi
movq $0x8, 0x18(%rsp)
movq %rsi, 0x20(%r15)
testq %rsi, %rsi
je 0x5273
movq (%r15), %r13
pushq $0x18
popq %rdi
callq 0x81a0
movq %r13, %rdi
movq %rax, %rsi
callq 0xd104
movq %rax, %rbp
movq %rbp, 0x28(%r15)
xorl %r14d, %r14d
pushq $0x8
popq %r13
xorl %r12d, %r12d
cmpq 0x20(%r15), %r12
jae 0x52d6
movq %r12, (%rbp,%r14)
leaq 0x70(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
movq %r13, %rdi
pushq $0x8
popq %rsi
movq 0x20(%rsp), %rdx
callq 0x5b8f
movq (%rbx,%r13), %rax
addq $0x8, %r13
movq %r13, 0x18(%rsp)
movq 0x28(%r15), %rbp
movq %rax, 0x8(%rbp,%r14)
andq $0x0, 0x10(%rbp,%r14)
incq %r12
addq $0x18, %r14
jmp 0x5281
movq (%r15), %rdi
callq 0x2578
movq %rax, %rdi
movq %rax, 0x28(%rsp)
leaq 0x70(%rsp), %r12
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
leaq 0x18(%rsp), %rbp
movq %rbx, %r14
movq %rbx, %rsi
movq 0x20(%rsp), %rbx
movq %rbx, %rdx
movq %rbp, %rcx
movq %r15, %r8
callq 0x53ca
movq %rax, 0x30(%r15)
movq (%rbp), %r13
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
pushq $0x8
popq %rsi
movq %r13, %rdi
movq %rbx, %rdx
callq 0x5b8f
movq (%r14,%r13), %rax
addq $0x8, %r13
movq %r13, (%rbp)
movq %rax, 0x38(%r15)
movq (%r15), %rdi
callq 0xa764
movq %rax, 0x40(%r15)
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
movq 0x28(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x54ab
movq %rax, 0x48(%r15)
movq 0x30(%rsp), %rdi
callq 0xd21a
cmpq %rbx, (%rbp)
jne 0x53b3
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%r12), %esi
movq (%r12), %rdx
leaq 0x90e5(%rip), %rdi      # 0xe4a8
xorl %eax, %eax
callq 0x3918