// File: /workspace/github_c_makefile_star2_O2/AlxHnr[P]nano-backup/src/search-tree.c
// Function: newNode
static SearchNode *newNode(CR_Region *r, Allocator *region_wrapper,
                           StringTable *existing_nodes, StringView path,
                           const size_t line_nr)
{
  PathSplit paths = strSplitPath(path);

  /* Ensure that a parent node exists. */
  SearchNode *parent_node = strTableGet(existing_nodes, paths.head);
  if(parent_node == NULL)
  {
    parent_node =
      newNode(r, region_wrapper, existing_nodes, paths.head, line_nr);
  }

  /* Initialize a new node. */
  SearchNode *node = allocate(region_wrapper, sizeof *node);

  /* Build regular expression. */
  if(paths.tail.length >= 2 && paths.tail.content[0] == '/')
  {
    /* Slice out the part after the first slash. */
    StringView expression =
      strUnterminated(&paths.tail.content[1], paths.tail.length - 1);

    strSet(&node->name, strCopy(expression, region_wrapper));
    node->regex = sRegexCompile(r, node->name, str("config"), line_nr);

    parent_node->subnodes_contain_regex = true;
  }
  else
  {
    strSet(&node->name, strCopy(paths.tail, region_wrapper));
    node->regex = NULL;
  }

  node->line_nr = line_nr;
  node->search_match = SRT_none;

  /* Inherit policy from parent node. */
  node->policy = parent_node->policy;
  node->policy_inherited = parent_node->policy != BPOL_none;
  node->policy_line_nr = line_nr;

  node->subnodes = NULL;
  node->subnodes_contain_regex = false;
  node->ignore_expressions = parent_node->ignore_expressions;

  /* Prepend node to the parents subnodes. */
  node->next = parent_node->subnodes;
  parent_node->subnodes = node;

  strTableMap(existing_nodes, path, node);

  return node;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r13
movq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x100(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x38(%rsp), %r15
movq %r15, %rdi
callq 0xa4e3
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0xa908
movq %rax, %r15
testq %rax, %rax
jne 0x9aff
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x9a74
movq %rax, %r15
pushq $0x68
popq %rsi
movq %rbp, %rdi
callq 0x24fc
movq %rax, %r12
movq 0x58(%rsp), %rdx
cmpq $0x2, %rdx
jb 0x9bda
movq 0x50(%rsp), %rsi
cmpb $0x2f, (%rsi)
jne 0x9bda
incq %rsi
decq %rdx
movq %r13, 0x30(%rsp)
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
callq 0xa3ec
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
leaq 0x98(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0xa466
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0xa454
leaq 0x4657(%rip), %rsi      # 0xe1e2
leaq 0x80(%rsp), %r13
movq %r13, %rdi
callq 0xa3d0
movq 0x10(%r13), %rax
movq %rax, 0x28(%rsp)
movups (%r13), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x933d
movq %rax, 0x20(%r12)
movb $0x1, 0x48(%r15)
jmp 0x9c1f
leaq 0x50(%rsp), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movups (%rax), %xmm0
movups %xmm0, (%rsp)
leaq 0x68(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0xa466
movq 0x10(%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r13), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0xa454
andq $0x0, 0x20(%r12)
movq %r14, 0x18(%r12)
andl $0x0, 0x28(%r12)
movl 0x2c(%r15), %eax
movl %eax, 0x2c(%r12)
testl %eax, %eax
setne 0x30(%r12)
movq %r14, 0x38(%r12)
andq $0x0, 0x40(%r12)
movb $0x0, 0x48(%r12)
movq 0x50(%r15), %rax
movq %rax, 0x50(%r12)
movq 0x40(%r15), %rax
movq %rax, 0x60(%r12)
movq %r12, 0x40(%r15)
leaq 0x100(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%rsp)
movups (%rcx), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa7f2
movq %r12, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq