// File: /workspace/github_c_makefile_star2_O2/AlxHnr[P]nano-backup/src/metadata.c
// Function: writePathHistoryList
static void writePathHistoryList(const PathHistory *starting_point,
                                 RepoWriter *writer)
{
  size_t history_length = 0;
  for(const PathHistory *point = starting_point; point != NULL;
      point = point->next)
  {
    history_length = sSizeAdd(history_length, 1);
  }

  write64(history_length, writer);
  for(const PathHistory *point = starting_point; point != NULL;
      point = point->next)
  {
    write64(point->backup->id, writer);
    write8(point->state.type, writer);

    if(point->state.type != PST_non_existing)
    {
      write32(point->state.uid, writer);
      write32(point->state.gid, writer);
    }

    if(point->state.type == PST_regular_file)
    {
      write32(point->state.metadata.file_info.permission_bits, writer);
      write64(point->state.metadata.file_info.modification_time, writer);
      write64(point->state.metadata.file_info.size, writer);

      if(point->state.metadata.file_info.size > FILE_HASH_SIZE)
      {
        repoWriterWrite(point->state.metadata.file_info.hash,
                        FILE_HASH_SIZE, writer);
        write8(point->state.metadata.file_info.slot, writer);
      }
      else if(point->state.metadata.file_info.size > 0)
      {
        repoWriterWrite(point->state.metadata.file_info.hash,
                        point->state.metadata.file_info.size, writer);
      }
    }
    else if(point->state.type == PST_symlink)
    {
      StringView target_path = point->state.metadata.symlink_target;
      write64(target_path.length, writer);
      repoWriterWrite(target_path.content, target_path.length, writer);
    }
    else if(point->state.type == PST_directory)
    {
      write32(point->state.metadata.directory_info.permission_bits,
              writer);
      write64(point->state.metadata.directory_info.modification_time,
              writer);
    }
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
xorl %edi, %edi
pushq $0x1
popq %r15
movq %r14, %r12
testq %r12, %r12
je 0x595f
movq %r15, %rsi
callq 0x8188
movq %rax, %rdi
movq 0x48(%r12), %r12
jmp 0x5948
movq %rbx, %rsi
callq 0x5919
pushq $0x14
popq %r15
testq %r14, %r14
je 0x5a64
movq (%r14), %rax
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x5919
movzbl 0x8(%r14), %edi
movq %rbx, %rsi
callq 0x5fd3
cmpl $0x0, 0x8(%r14)
je 0x5a5b
movl 0xc(%r14), %edi
movq %rbx, %rsi
callq 0x5fec
movl 0x10(%r14), %edi
movq %rbx, %rsi
callq 0x5fec
movl 0x8(%r14), %eax
cmpl $0x3, %eax
je 0x5a30
cmpl $0x2, %eax
je 0x5a15
cmpl $0x1, %eax
jne 0x5a5b
movl 0x18(%r14), %edi
movq %rbx, %rsi
callq 0x5fec
movq 0x20(%r14), %rdi
movq %rbx, %rsi
callq 0x5919
movq 0x28(%r14), %rdi
movq %rbx, %rsi
callq 0x5919
movq 0x28(%r14), %rsi
cmpq $0x15, %rsi
jb 0x5a4a
leaq 0x30(%r14), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x7436
movzbl 0x44(%r14), %edi
movq %rbx, %rsi
callq 0x5fd3
jmp 0x5a5b
movq 0x18(%r14), %r12
movq 0x20(%r14), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x5919
movq %r12, %rdi
movq %r13, %rsi
jmp 0x5a53
movl 0x18(%r14), %edi
movq %rbx, %rsi
callq 0x5fec
movq 0x20(%r14), %rdi
movq %rbx, %rsi
callq 0x5919
jmp 0x5a5b
testq %rsi, %rsi
je 0x5a5b
leaq 0x30(%r14), %rdi
movq %rbx, %rdx
callq 0x7436
movq 0x48(%r14), %r14
jmp 0x596b
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq