// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rdi, %rbx
movl 0x1c(%rdi), %eax
movq 0x20(%rdi), %r12
cmpl $0x3, %eax
jne 0x8291
testq %r12, %r12
je 0x8375
movq (%r12), %rcx
cmpq %r14, (%rcx)
jae 0x8291
movq 0x48(%r12), %r12
jmp 0x8278
movl 0x8(%r12), %ecx
testl %ecx, %ecx
je 0x8375
leaq 0x70(%rsp), %r13
leaq 0x8(%r12), %r15
movl 0x18(%rbx), %edx
movl %edx, %esi
andl $0x1ff, %esi            # imm = 0x1FF
cmpl $0x2, %esi
je 0x83ed
leal -0x5(%rsi), %edi
cmpl $0x8, %edi
ja 0x82ea
addl $-0x9, %esi
cmpl $0x1, %esi
ja 0x83d8
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x945a
jmp 0x83ed
testl %eax, %eax
je 0x83d4
testb $0x10, %dl
je 0x8332
movl 0xc(%r12), %edi
movl 0x10(%r12), %esi
cmpl $0x2, %ecx
jne 0x831d
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x933a
jmp 0x8332
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x92de
testb $0x20, 0x18(%rbx)
je 0x835d
movl (%r15), %eax
orl $0x2, %eax
cmpl $0x3, %eax
jne 0x835d
movl 0x18(%r12), %edi
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x9288
movl 0x18(%rbx), %eax
testb %al, %al
js 0x837c
testb $0x40, %al
je 0x83d4
movl (%r15), %eax
cmpl $0x3, %eax
je 0x83ba
cmpl $0x1, %eax
je 0x83ba
xorl %ebp, %ebp
jmp 0x8477
movl (%r15), %eax
cmpl $0x2, %eax
je 0x83d8
cmpl $0x1, %eax
jne 0x8488
leaq 0x18(%r12), %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 0x80f2
movq 0x20(%r12), %rdi
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x9396
xorl %ebp, %ebp
jmp 0x840d
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
callq 0x93f7
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x866e
movb $0x1, %bpl
movl (%r15), %eax
cmpl $0x3, %eax
jne 0x8477
movq 0x28(%rbx), %r15
testq %r15, %r15
je 0x8477
movq %rbx, 0x30(%rsp)
xorl %ebx, %ebx
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x8258
orb %al, %bl
movq 0x30(%r15), %r15
testq %r15, %r15
jne 0x8425
testb $0x1, %bl
je 0x8477
movq 0x30(%rsp), %rcx
cmpl $0x0, 0x1c(%rcx)
je 0x8477
movq 0x20(%r12), %rdi
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
callq 0x9396
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0x8410