// File: /workspace/github_c_makefile_star2_O3/AlxHnr[P]nano-backup/src/metadata.c
// Function: readPathHistory
static PathHistory *readPathHistory(Allocator *region_wrapper,
                                    const FileContent content,
                                    size_t *reader_position,
                                    StringView metadata_path,
                                    Metadata *metadata)
{
  PathHistory *point = allocate(region_wrapper, sizeof *point);

  const size_t id = readSize(content, reader_position, metadata_path);
  if(id >= metadata->backup_history_length)
  {
    die("backup id is out of range in \"" PRI_STR "\"",
        STR_FMT(metadata_path));
  }

  point->backup = &metadata->backup_history[id];
  point->backup->ref_count = sSizeAdd(point->backup->ref_count, 1);

  point->state.type = read8(content, reader_position, metadata_path);

  if(point->state.type != PST_non_existing)
  {
    point->state.uid = read32(content, reader_position, metadata_path);
    point->state.gid = read32(content, reader_position, metadata_path);
  }

  if(point->state.type == PST_regular_file)
  {
    point->state.metadata.file_info.permission_bits =
      read32(content, reader_position, metadata_path);

    point->state.metadata.file_info.modification_time =
      readTime(content, reader_position, metadata_path);

    point->state.metadata.file_info.size =
      read64(content, reader_position, metadata_path);

    if(point->state.metadata.file_info.size > FILE_HASH_SIZE)
    {
      readBytes(content, reader_position,
                point->state.metadata.file_info.hash, FILE_HASH_SIZE,
                metadata_path);
      point->state.metadata.file_info.slot =
        read8(content, reader_position, metadata_path);
    }
    else if(point->state.metadata.file_info.size > 0)
    {
      readBytes(content, reader_position,
                point->state.metadata.file_info.hash,
                point->state.metadata.file_info.size, metadata_path);
    }
  }
  else if(point->state.type == PST_symlink)
  {
    const size_t target_length =
      readSize(content, reader_position, metadata_path);

    char *buffer = allocate(region_wrapper, sSizeAdd(target_length, 1));

    readBytes(content, reader_position, (uint8_t *)buffer, target_length,
              metadata_path);

    buffer[target_length] = '\0';

    strSet(&point->state.metadata.symlink_target, str(buffer));
  }
  else if(point->state.type == PST_directory)
  {
    point->state.metadata.directory_info.permission_bits =
      read32(content, reader_position, metadata_path);
    point->state.metadata.directory_info.modification_time =
      readTime(content, reader_position, metadata_path);
  }
  else if(point->state.type != PST_non_existing)
  {
    die("invalid PathStateType in \"" PRI_STR "\"",
        STR_FMT(metadata_path));
  }

  point->next = NULL;
  return point;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, %r12
movq %r8, %r13
movq %rcx, %r14
movq %rdx, %rbp
movq %rsi, %r15
movl $0x50, %esi
movq %rdi, 0x20(%rsp)
callq 0x27ac
movq %rax, %rbx
movq (%r14), %rdi
movl $0x8, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rcx
movq (%r15,%rcx), %rax
addq $0x8, %rcx
movq %rcx, (%r14)
movq 0x80(%rsp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x650b
movq 0x28(%rcx), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
movq %rax, (%rbx)
movq 0x10(%rax), %rdi
movl $0x1, %esi
callq 0x8778
movq (%rbx), %rcx
movq %rax, 0x10(%rcx)
movq (%r14), %rdi
movl $0x1, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rdi
movzbl (%r15,%rdi), %eax
incq %rdi
movq %rdi, (%r14)
movl %eax, 0x8(%rbx)
testl %eax, %eax
je 0x64f1
movl $0x4, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rdi
movl (%r15,%rdi), %eax
addq $0x4, %rdi
movq %rdi, (%r14)
movl %eax, 0xc(%rbx)
movl $0x4, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rdi
movl (%r15,%rdi), %eax
addq $0x4, %rdi
movq %rdi, (%r14)
movl %eax, 0x10(%rbx)
movl 0x8(%rbx), %eax
cmpq $0x3, %rax
ja 0x651f
leaq 0x81ca(%rip), %rcx      # 0xe498
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x4, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rax
movl (%r15,%rax), %ecx
addq $0x4, %rax
movq %rax, (%r14)
movl %ecx, 0x18(%rbx)
movq (%r14), %rdi
movl $0x8, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rax
movq (%r15,%rax), %rcx
addq $0x8, %rax
movq %rax, (%r14)
movq %rcx, 0x20(%rbx)
movq (%r14), %rdi
movl $0x8, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rax
movq (%r15,%rax), %rsi
addq $0x8, %rax
movq %rax, (%r14)
movq %rsi, 0x28(%rbx)
cmpq $0x15, %rsi
jb 0x64af
movq (%r14), %rdi
movl $0x14, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rax
movl 0x10(%r15,%rax), %ecx
movl %ecx, 0x40(%rbx)
movups (%r15,%rax), %xmm0
movups %xmm0, 0x30(%rbx)
movq (%r14), %rdi
addq $0x14, %rdi
movq %rdi, (%r14)
movl $0x1, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rax
movb (%r15,%rax), %cl
incq %rax
movq %rax, (%r14)
movb %cl, 0x44(%rbx)
jmp 0x64f1
movl $0x8, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rax
movq (%r15,%rax), %rdi
movq %rdi, 0x28(%rsp)
addq $0x8, %rax
movq %rax, (%r14)
movl $0x1, %esi
callq 0x8778
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x27ac
movq %rax, 0x20(%rsp)
movq (%r14), %rdi
movq 0x28(%rsp), %rsi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
addq (%r14), %r15
movq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq 0x28(%rsp), %r15
movq %r15, %rdx
callq 0x2280
addq %r15, (%r14)
movb $0x0, (%r12,%r15)
movq %rbx, %r14
addq $0x18, %r14
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0xab5c
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0xac25
jmp 0x64f1
movl $0x4, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rax
movl (%r15,%rax), %ecx
addq $0x4, %rax
movq %rax, (%r14)
movl %ecx, 0x18(%rbx)
movq (%r14), %rdi
movl $0x8, %esi
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
movq (%r14), %rax
movq (%r15,%rax), %rcx
addq $0x8, %rax
movq %rax, (%r14)
movq %rcx, 0x20(%rbx)
jmp 0x64f1
testq %rsi, %rsi
je 0x64f1
movq %rbx, %rax
addq $0x30, %rax
movq %rax, 0x20(%rsp)
movq (%r14), %rdi
movq %rsi, 0x28(%rsp)
movq %rbp, %rdx
movq %r13, %rcx
movq %r12, %r8
callq 0x615b
addq (%r14), %r15
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq 0x28(%rsp), %r15
movq %r15, %rdx
callq 0x2280
addq %r15, (%r14)
movq $0x0, 0x48(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7ff1(%rip), %rdi      # 0xe503
movl %r12d, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3ca8
leaq 0x8001(%rip), %rdi      # 0xe527
jmp 0x6512