// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
leaq 0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x8(%rbp)
leaq -0x28(%rbp), %rdi
leaq 0x1cb9c(%rip), %rsi     # 0x241be
callq 0xf100
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rax
leaq -0x28(%rbp), %rcx
movq (%rsi), %rdi
movq %rdi, (%rsp)
movq 0x8(%rsi), %rdi
movq %rdi, 0x8(%rsp)
movq 0x10(%rsi), %rsi
movq %rsi, 0x10(%rsp)
movq (%rdx), %rsi
movq %rsi, 0x18(%rsp)
movq 0x8(%rdx), %rsi
movq %rsi, 0x20(%rsp)
movq 0x10(%rdx), %rdx
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x38(%rsp)
movq 0x10(%rcx), %rcx
movq %rcx, 0x40(%rsp)
movq (%rax), %rcx
movq %rcx, 0x48(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x50(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x58(%rsp)
callq 0xa020
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
seta %al
andb $0x1, %al
movzbl %al, %eax
cltq
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x7724
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
imulq $0x18, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpq $0x0, 0x10(%rax)
jbe 0x7714
movq -0x30(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
imulq $0x18, -0x38(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0xb8f0
movq %rax, -0x30(%rbp)
jmp 0x7716
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x76c6
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x77f0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0x774d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x77f0
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x77a3
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jbe 0x7793
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x77f0
jmp 0x7795
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x7755
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x7830
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x77f0
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x7a30
movq -0x10(%rbp), %rdi
callq 0xa180
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)