// File: /workspace/github_c_makefile_star2_O2/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 0x7957
testq %rax, %rax
je 0x7dc3
movq %rax, %r14
leaq 0x70(%rsp), %r13
movl 0x18(%rbx), %eax
movl %eax, %ecx
andl $0x1ff, %ecx            # imm = 0x1FF
cmpl $0x2, %ecx
je 0x7e3c
leal -0x5(%rcx), %edx
cmpl $0x8, %edx
ja 0x7d39
addl $-0x9, %ecx
cmpl $0x1, %ecx
ja 0x7e27
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x8d6d
jmp 0x7e3c
cmpl $0x0, 0x1c(%rbx)
je 0x7e23
testb $0x10, %al
je 0x7d81
movl 0x4(%r14), %edi
cmpl $0x2, (%r14)
movl 0x8(%r14), %esi
jne 0x7d6c
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x8c6b
jmp 0x7d81
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x8c19
testb $0x20, 0x18(%rbx)
je 0x7dab
movl (%r14), %eax
orl $0x2, %eax
cmpl $0x3, %eax
jne 0x7dab
movl 0x10(%r14), %edi
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x8bcd
movl 0x18(%rbx), %eax
testb %al, %al
js 0x7dca
testb $0x40, %al
je 0x7e23
movl (%r14), %eax
cmpl $0x3, %eax
je 0x7e0a
cmpl $0x1, %eax
je 0x7e0a
xorl %ebp, %ebp
jmp 0x7ec9
movl (%r14), %eax
cmpl $0x2, %eax
je 0x7e27
cmpl $0x1, %eax
jne 0x7eda
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 0x7b64
movq 0x18(%r14), %rdi
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x8cbd
xorl %ebp, %ebp
jmp 0x7e5c
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x8d14
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x807e
movb $0x1, %bpl
movl (%r14), %eax
cmpl $0x3, %eax
jne 0x7ec9
movq %r14, 0x30(%rsp)
leaq 0x28(%rbx), %r12
xorl %r14d, %r14d
movq (%r12), %r12
testq %r12, %r12
je 0x7e9f
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x7ccd
orb %al, %r14b
addq $0x30, %r12
jmp 0x7e70
testb $0x1, %r14b
je 0x7ec9
cmpl $0x0, 0x1c(%rbx)
je 0x7ec9
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x8cbd
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x7e5f