// File: /workspace/github_c_makefile_star2_O3/AlxHnr[P]nano-backup/src/metadata.c
// Function: metadataWrite
void metadataWrite(Metadata *metadata, StringView repo_path,
                   StringView repo_tmp_file_path,
                   StringView repo_metadata_path)
{
  RepoWriter *writer = repoWriterOpenRaw(
    repo_path, repo_tmp_file_path, str("metadata"), repo_metadata_path);

  /* Count referenced history points and update IDs. */
  size_t id_counter = metadata->current_backup.ref_count > 0;
  for(size_t index = 0; index < metadata->backup_history_length; index++)
  {
    if(metadata->backup_history[index].ref_count > 0)
    {
      metadata->backup_history[index].id = id_counter;
      id_counter = sSizeAdd(id_counter, 1);
    }
  }

  /* Write the backup history. */
  write64(id_counter, writer);

  if(metadata->current_backup.ref_count > 0)
  {
    write64(metadata->current_backup.completion_time, writer);
  }

  for(size_t index = 0; index < metadata->backup_history_length; index++)
  {
    Backup *backup = &metadata->backup_history[index];
    if(backup->ref_count > 0)
    {
      write64(backup->completion_time, writer);
    }
  }

  /* Write the config files history. */
  writePathHistoryList(metadata->config_history, writer);

  /* Write the path tree. */
  write64(metadata->total_path_count, writer);
  writePathList(metadata->paths, writer);

  /* Finish writing. */
  repoWriterClose(writer);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x80, %rsp
movq %rdi, %rbx
leaq 0x853b(%rip), %rsi      # 0xe1e9
leaq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0xab5c
movq 0xf0(%rsp), %rax
movq %rax, 0x58(%rsp)
movaps 0xe0(%rsp), %xmm0
movups %xmm0, 0x48(%rsp)
movq 0x10(%r14), %rax
movq %rax, 0x40(%rsp)
movups (%r14), %xmm0
movups %xmm0, 0x30(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0xc8(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0xb0(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x7957
xorl %ecx, %ecx
cmpq $0x0, 0x18(%rbx)
movq %rax, %r14
setne %cl
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x5d6e
movl $0x10, %r15d
xorl %r12d, %r12d
movq 0x28(%rbx), %rdx
cmpq $0x0, (%rdx,%r15)
je 0x5d62
movq %rcx, -0x10(%rdx,%r15)
movl $0x1, %esi
movq %rcx, %rdi
callq 0x8778
movq %rax, %rcx
movq 0x20(%rbx), %rax
incq %r12
addq $0x18, %r15
cmpq %rax, %r12
jb 0x5d3e
leaq 0x60(%rsp), %rdi
movq %rcx, (%rdi)
movl $0x8, %esi
movq %r14, %rdx
callq 0x79d8
cmpq $0x0, 0x18(%rbx)
je 0x5da3
movq 0x10(%rbx), %rax
leaq 0x60(%rsp), %rdi
movq %rax, (%rdi)
movl $0x8, %esi
movq %r14, %rdx
callq 0x79d8
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x5def
movl $0x10, %r12d
xorl %r13d, %r13d
leaq 0x60(%rsp), %r15
movq 0x28(%rbx), %rcx
cmpq $0x0, (%rcx,%r12)
je 0x5de3
movq -0x8(%rcx,%r12), %rax
movq %rax, 0x60(%rsp)
movl $0x8, %esi
movq %r15, %rdi
movq %r14, %rdx
callq 0x79d8
movq 0x20(%rbx), %rax
incq %r13
addq $0x18, %r12
cmpq %rax, %r13
jb 0x5dba
movq 0x30(%rbx), %rdi
movq %r14, %rsi
callq 0x5e39
movq 0x38(%rbx), %rax
leaq 0x60(%rsp), %rdi
movq %rax, (%rdi)
movl $0x8, %esi
movq %r14, %rdx
callq 0x79d8
movq 0x48(%rbx), %rdi
movq %r14, %rsi
callq 0x602f
movq %r14, %rdi
callq 0x7a31
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq