// File: /workspace/github_c_makefile_star2_O1/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
callq 0xdc7c
movq %rax, %rdi
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rdi, 0x30(%rsp)
callq 0x9d2c
movq %rax, %r14
movq %rdx, %rbx
movl $0x50, %esi
movq %r13, %rdi
callq 0xdd40
movq %rax, %r15
movq %r13, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
xorl %ebp, %ebp
movq %rbp, 0x18(%rax)
leaq 0x20(%rsp), %rdx
movq %rbp, (%rdx)
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x70(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r14, 0x28(%rsp)
movq %r14, %rdi
movq %rbx, %r12
movq %rbx, %rsi
callq 0x6181
movq %rax, 0x20(%r15)
testq %rax, %rax
je 0x5772
movq (%r15), %r13
movl $0x18, %edi
movq %rax, %rsi
callq 0x893c
movq %r13, %rdi
movq %rax, %rsi
callq 0xdd40
movq %rax, %rbp
leaq 0x70(%rsp), %r13
movq %rbp, 0x28(%r15)
cmpq $0x0, 0x20(%r15)
movq 0x28(%rsp), %rbx
je 0x57d5
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x28(%r15), %rax
movq %r14, (%rax,%rbp)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x20(%rsp), %rdx
callq 0x6181
movq 0x28(%r15), %rcx
movq %rax, 0x8(%rcx,%rbp)
movq $0x0, 0x10(%rcx,%rbp)
incq %r14
addq $0x18, %rbp
cmpq 0x20(%r15), %r14
jb 0x578c
movq (%r15), %rdi
callq 0x28cc
movq %rax, %rbp
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
leaq 0x20(%rsp), %r14
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x58a3
movq %rax, 0x30(%r15)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x6181
movq %rax, 0x38(%r15)
movq (%r15), %rdi
callq 0xb374
movq %rax, 0x40(%r15)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
movq %r15, %r9
callq 0x5986
movq %rax, 0x48(%r15)
movq 0x30(%rsp), %rdi
callq 0xde6a
cmpq %r12, (%r14)
jne 0x588d
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x8(%r13), %esi
movq (%r13), %rdx
leaq 0x8c0c(%rip), %rdi      # 0xe4a8
xorl %eax, %eax
callq 0x3dc4