// File: /workspace/github_c_makefile_star2_O1/AlxHnr[P]nano-backup/src/restore.c
// Function: finishRestoreRecursively
static bool finishRestoreRecursively(const PathNode *node, const size_t id,
                                     StringView repo_path)
{
  bool affects_parent_timestamp = false;

  const PathState *state = searchExistingPathState(node, id);
  if(state == NULL)
  {
    return affects_parent_timestamp;
  }

  if(backupHintNoPol(node->hint) == BH_added)
  {
    restorePath(node, state, repo_path);
    affects_parent_timestamp = true;
  }
  else if(backupHintNoPol(node->hint) >= BH_regular_to_symlink &&
          backupHintNoPol(node->hint) <= BH_other_to_directory)
  {
    if(backupHintNoPol(node->hint) == BH_directory_to_regular ||
       backupHintNoPol(node->hint) == BH_directory_to_symlink)
    {
      sRemoveRecursively(node->path);
    }
    else
    {
      sRemove(node->path);
    }

    restorePath(node, state, repo_path);
    affects_parent_timestamp = true;
  }
  else if(node->policy != BPOL_none)
  {
    if(node->hint & BH_owner_changed)
    {
      if(state->type == PST_symlink)
      {
        sLChown(node->path, state->uid, state->gid);
      }
      else
      {
        sChown(node->path, state->uid, state->gid);
      }
    }
    if(node->hint & BH_permissions_changed)
    {
      if(state->type == PST_regular_file)
      {
        sChmod(node->path, state->metadata.file_info.permission_bits);
      }
      else if(state->type == PST_directory)
      {
        sChmod(node->path, state->metadata.directory_info.permission_bits);
      }
    }

    if(node->hint & BH_content_changed)
    {
      if(state->type == PST_regular_file)
      {
        restoreFile(node->path, &state->metadata.file_info, repo_path);
        sUtime(node->path, state->metadata.file_info.modification_time);
      }
      else if(state->type == PST_symlink)
      {
        sRemove(node->path);
        restorePath(node, state, repo_path);
        affects_parent_timestamp = true;
      }
    }
    else if(node->hint & BH_timestamp_changed)
    {
      if(state->type == PST_regular_file)
      {
        sUtime(node->path, state->metadata.file_info.modification_time);
      }
      else if(state->type == PST_directory)
      {
        sUtime(node->path,
               state->metadata.directory_info.modification_time);
      }
    }
  }

  if(state->type == PST_directory)
  {
    bool subnode_changes_timestamp = false;

    for(const PathNode *subnode = node->subnodes; subnode != NULL;
        subnode = subnode->next)
    {
      subnode_changes_timestamp |=
        finishRestoreRecursively(subnode, id, repo_path);
    }

    if(subnode_changes_timestamp && node->policy != BPOL_none)
    {
      sUtime(node->path, state->metadata.directory_info.modification_time);
    }
  }

  return affects_parent_timestamp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x80d9
testq %rax, %rax
je 0x84b4
movq %rax, %r14
leaq 0x70(%rsp), %r13
movl 0x18(%rbx), %eax
movl %eax, %ecx
andl $0x1ff, %ecx            # imm = 0x1FF
cmpl $0x2, %ecx
je 0x85b5
leal -0x5(%rcx), %edx
cmpl $0x8, %edx
ja 0x84bb
addl $-0x9, %ecx
cmpl $0x1, %ecx
ja 0x85a0
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x9747
jmp 0x85b5
xorl %ebp, %ebp
jmp 0x8640
cmpl $0x0, 0x1c(%rbx)
je 0x859c
testb $0x10, %al
je 0x8503
movl 0x4(%r14), %edi
cmpl $0x2, (%r14)
movl 0x8(%r14), %esi
jne 0x84ee
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x95eb
jmp 0x8503
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x957b
testb $0x20, 0x18(%rbx)
je 0x852d
movl (%r14), %eax
orl $0x2, %eax
cmpl $0x3, %eax
jne 0x852d
movl 0x10(%r14), %edi
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x9511
movl 0x18(%rbx), %eax
testb %al, %al
js 0x8547
testb $0x40, %al
je 0x859c
movl (%r14), %eax
cmpl $0x3, %eax
je 0x8583
cmpl $0x1, %eax
je 0x8583
jmp 0x859c
movl (%r14), %eax
cmpl $0x2, %eax
je 0x85a0
cmpl $0x1, %eax
jne 0x859c
movq %r14, %rdi
addq $0x10, %rdi
movq 0x10(%r13), %rax
movq %rax, 0x28(%rsp)
movups (%r13), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x82e6
movq 0x18(%r14), %rdi
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x965b
xorl %ebp, %ebp
jmp 0x85d5
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x96d0
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8819
movb $0x1, %bpl
cmpl $0x3, (%r14)
jne 0x8640
movq 0x28(%rbx), %r12
testq %r12, %r12
je 0x8640
movq %r14, 0x30(%rsp)
xorl %r14d, %r14d
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x844c
orb %al, %r14b
movq 0x30(%r12), %r12
testq %r12, %r12
jne 0x85ec
testb $0x1, %r14b
je 0x8640
cmpl $0x0, 0x1c(%rbx)
je 0x8640
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x965b
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq