// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %r8, %rbp
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %r15
leaq 0x70(%rsp), %r13
pushq $0x50
popq %rsi
movq %rdi, 0x18(%rsp)
callq 0x24fc
movq %rax, %rbx
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movaps (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5b4b
cmpq 0x20(%rbp), %rax
jae 0x5f25
movq 0x28(%rbp), %rcx
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %rdx
movq %rdx, (%rbx)
movq 0x10(%rcx,%rax), %rdi
pushq $0x1
popq %rsi
callq 0x8188
movq (%rbx), %rcx
movq %rax, 0x10(%rcx)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5f4c
movzbl %al, %eax
movl %eax, 0x8(%rbx)
testb %al, %al
je 0x5f0e
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5f8f
movl %eax, 0xc(%rbx)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5f8f
movl %eax, 0x10(%rbx)
movl 0x8(%rbx), %eax
cmpq $0x3, %rax
ja 0x5f3b
leaq 0x87ae(%rip), %rcx      # 0xe498
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5f8f
movl %eax, 0x18(%rbx)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5b4b
movq %rax, 0x20(%rbx)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5b4b
movq %rax, 0x28(%rbx)
cmpq $0x15, %rax
jb 0x5ec4
movq (%r14), %rdi
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
pushq $0x14
popq %rsi
movq %r12, %rdx
callq 0x5b8f
movq (%r14), %rax
movl 0x10(%r15,%rax), %ecx
movl %ecx, 0x40(%rbx)
movups (%r15,%rax), %xmm0
movups %xmm0, 0x30(%rbx)
addq $0x14, (%r14)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5f4c
movb %al, 0x44(%rbx)
jmp 0x5f0e
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5b4b
movq %rax, %rbp
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x8188
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x24fc
movq %rax, 0x18(%rsp)
movq (%r14), %rdi
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %rbp, %rsi
movq %r12, %rdx
callq 0x5b8f
addq (%r14), %r15
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2280
addq %rbp, (%r14)
movb $0x0, (%r12,%rbp)
movq %rbx, %r14
addq $0x18, %r14
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0xa3d0
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0xa454
jmp 0x5f0e
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5f8f
movl %eax, 0x18(%rbx)
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x5b4b
movq %rax, 0x20(%rbx)
jmp 0x5f0e
movq %rax, %rbp
testq %rax, %rax
je 0x5f0e
movq %rbx, %rax
addq $0x30, %rax
movq %rax, 0x18(%rsp)
movq (%r14), %rdi
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %rbp, %rsi
movq %r12, %rdx
callq 0x5b8f
addq (%r14), %r15
movq 0x18(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2280
addq %rbp, (%r14)
andq $0x0, 0x48(%rbx)
movq %rbx, %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 0x85cf(%rip), %rdi      # 0xe503
xorl %eax, %eax
callq 0x3918
movl 0x8(%r13), %esi
movq (%r13), %rdx
leaq 0x85dd(%rip), %rdi      # 0xe527
jmp 0x5f34