// File: /workspace/github_c_makefile_star2_O2/AlxHnr[P]nano-backup/src/search-tree.c
// Function: searchTreeParse
SearchNode *searchTreeParse(CR_Region *r, StringView config)
{
  if(memchr(config.content, '\0', config.length) != NULL)
  {
    die("config: contains null-bytes");
  }

  Allocator *region_wrapper = allocatorWrapRegion(r);

  /* Initialize the root node of this tree. */
  SearchNode *root_node = allocate(region_wrapper, sizeof *root_node);
  strSet(&root_node->name, str("/"));

  root_node->line_nr = 0;
  root_node->regex = NULL;
  root_node->search_match = SRT_none;
  root_node->policy = BPOL_none;
  root_node->policy_inherited = false;
  root_node->policy_line_nr = 0;
  root_node->subnodes = NULL;
  root_node->subnodes_contain_regex = false;
  root_node->next = NULL;

  /* Initialize expression lists, which are shared across all nodes of the
     tree. */
  root_node->ignore_expressions =
    allocate(region_wrapper, sizeof *root_node->ignore_expressions);
  *root_node->ignore_expressions = NULL;
  root_node->summarize_expressions =
    allocate(region_wrapper, sizeof *root_node->summarize_expressions);
  *root_node->summarize_expressions = NULL;

  /* This table maps paths to existing nodes, without a trailing slash. */
  CR_Region *existing_nodes_region = CR_RegionNew();
  StringTable *existing_nodes = strTableNew(existing_nodes_region);

  /* Associate an empty string with the root node. */
  strTableMap(existing_nodes, str(""), root_node);

  /* Parse the specified config file. */
  size_t line_nr = 1;
  size_t parser_position = 0;
  BackupPolicy current_policy = BPOL_none;

  /* Skip UTF-8 BOM. */
  if(config.length >= 3 && config.content[0] == (char)0xEF &&
     config.content[1] == (char)0xBB && config.content[2] == (char)0xBF)
  {
    parser_position = 3;
  }

  StringView copy_token = str("[copy]");
  StringView mirror_token = str("[mirror]");
  StringView track_token = str("[track]");
  StringView ignore_token = str("[ignore]");
  StringView summarize_token = str("[summarize]");
  while(parser_position < config.length)
  {
    StringView line = getLine(config, parser_position);

    if(strIsWhitespaceOnly(line) || line.content[0] == '#')
    {
      /* Ignore. */
    }
    else if(strIsEqual(line, copy_token))
    {
      current_policy = BPOL_copy;
    }
    else if(strIsEqual(line, mirror_token))
    {
      current_policy = BPOL_mirror;
    }
    else if(strIsEqual(line, track_token))
    {
      current_policy = BPOL_track;
    }
    else if(strIsEqual(line, ignore_token))
    {
      current_policy = BPOL_ignore;
    }
    else if(strIsEqual(line, summarize_token))
    {
      current_policy = BPOL_summarize;
    }
    else if(line.content[0] == '[' && line.content[line.length - 1] == ']')
    {
      StringView policy =
        strUnterminated(&line.content[1], line.length - 2);
      die("config: line %zu: invalid policy: \"" PRI_STR "\"", line_nr,
          STR_FMT(policy));
    }
    else if(current_policy == BPOL_none)
    {
      die("config: line %zu: pattern without policy: \"" PRI_STR "\"",
          line_nr, STR_FMT(line));
    }
    else if(current_policy == BPOL_ignore ||
            current_policy == BPOL_summarize)
    {
      RegexList *expression = allocate(region_wrapper, sizeof *expression);

      strSet(&expression->expression, strCopy(line, region_wrapper));
      expression->line_nr = line_nr;
      expression->regex =
        sRegexCompile(r, expression->expression, str("config"), line_nr);
      expression->has_matched = false;

      RegexList **shared_expression_list = current_policy == BPOL_summarize
        ? root_node->summarize_expressions
        : root_node->ignore_expressions;

      /* Prepend new expression to the shared expression list. */
      expression->next = *shared_expression_list;
      *shared_expression_list = expression;
    }
    else if(line.content[0] == '/')
    {
      if(strPathContainsDotElements(line))
      {
        die("config: line %zu: path contains \".\" or \"..\": \"" PRI_STR
            "\"",
            line_nr, STR_FMT(line));
      }

      StringView path = strStripTrailingSlashes(line);
      SearchNode *previous_definition = strTableGet(existing_nodes, path);

      /* Terminate with an error if the path was already defined. */
      if(previous_definition != NULL &&
         previous_definition->policy != BPOL_none &&
         !previous_definition->policy_inherited)
      {
        die("config: line %zu: redefining %sline %zu: \"" PRI_STR "\"",
            line_nr,
            previous_definition->policy != current_policy ? "policy of "
                                                          : "",
            previous_definition->policy_line_nr, STR_FMT(line));
      }

      /* Use either the existing node or create a new one. */
      SearchNode *node = previous_definition != NULL
        ? previous_definition
        : newNode(r, region_wrapper, existing_nodes, path, line_nr);

      node->policy = current_policy;
      node->policy_inherited = false;
      node->policy_line_nr = line_nr;
      inheritPolicyToSubnodes(node);
    }
    else
    {
      die("config: line %zu: invalid path: \"" PRI_STR "\"", line_nr,
          STR_FMT(line));
    }

    parser_position += line.length;
    parser_position += parser_position < config.length;
    line_nr++;
  }

  CR_RegionRelease(existing_nodes_region);

  return root_node;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rdi, %r13
movq 0x1c0(%rsp), %r14
movq 0x1c8(%rsp), %r15
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x2200
testq %rax, %rax
jne 0x99d4
movq %r13, %rdi
callq 0x2578
movq %rax, %r12
pushq $0x68
popq %rsi
movq %rax, %rdi
callq 0x24fc
movq %rax, %rbp
leaq 0x4f96(%rip), %rsi      # 0xe448
leaq 0x170(%rsp), %rbx
movq %rbx, %rdi
callq 0xa3d0
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
movq %rbp, %rdi
callq 0xa454
andq $0x0, 0x60(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbp)
movups %xmm0, 0x21(%rbp)
movups %xmm0, 0x38(%rbp)
movb $0x0, 0x48(%rbp)
pushq $0x8
popq %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x24fc
movq %rax, 0x50(%rbp)
andq $0x0, (%rax)
movq %r12, 0x58(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0x24fc
movq %rax, 0x58(%rbp)
andq $0x0, (%rax)
callq 0xd040
movq %rax, 0x88(%rsp)
movq %rax, %rdi
callq 0xa764
movq %rax, %r12
leaq 0x5260(%rip), %rsi      # 0xe79f
leaq 0x158(%rsp), %rbx
movq %rbx, %rdi
callq 0xa3d0
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movq %r12, 0x60(%rsp)
movups %xmm0, (%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0xa7f2
xorl %r12d, %r12d
cmpq $0x3, %r15
movq %r13, 0x68(%rsp)
jb 0x959a
cmpb $-0x11, (%r14)
jne 0x959a
cmpb $-0x45, 0x1(%r14)
jne 0x959a
xorl %eax, %eax
cmpb $-0x41, 0x2(%r14)
sete %al
leaq (%rax,%rax,2), %r13
jmp 0x959d
xorl %r13d, %r13d
leaq 0x50(%rbp), %rax
movq %rax, 0x80(%rsp)
movq %rbp, 0x90(%rsp)
addq $0x58, %rbp
movq %rbp, 0x78(%rsp)
leaq 0x5916(%rip), %rsi      # 0xeed7
leaq 0x140(%rsp), %rdi
callq 0xa3d0
leaq 0x5909(%rip), %rsi      # 0xeede
leaq 0x128(%rsp), %rdi
callq 0xa3d0
leaq 0x58fe(%rip), %rsi      # 0xeee7
leaq 0x110(%rsp), %rdi
callq 0xa3d0
leaq 0x58f2(%rip), %rsi      # 0xeeef
leaq 0xf8(%rsp), %rdi
callq 0xa3d0
leaq 0x58e7(%rip), %rsi      # 0xeef8
leaq 0xe0(%rsp), %rdi
callq 0xa3d0
pushq $0x1
popq %rbx
leaq 0x38(%rsp), %rbp
cmpq %r15, %r13
jae 0x99ad
movq %r13, %rdx
cmpq %r15, %rdx
jae 0x9643
cmpb $0xa, (%r14,%rdx)
je 0x9646
incq %rdx
jmp 0x9632
movq %r15, %rdx
leaq (%r14,%r13), %rsi
subq %r13, %rdx
movq %rbp, %rdi
callq 0xa3ec
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xa591
testb %al, %al
jne 0x967b
movq 0x38(%rsp), %rax
cmpb $0x23, (%rax)
jne 0x9695
movl %r12d, %ecx
movq 0x40(%rsp), %rax
leaq (%rax,%r13), %rdx
cmpq %r15, %rdx
adcq %rax, %r13
incq %rbx
movl %ecx, %r12d
jmp 0x9626
movq 0x150(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x140(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xa564
pushq $0x1
popq %rcx
testb %al, %al
jne 0x967e
movq 0x138(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x128(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xa564
pushq $0x2
popq %rcx
testb %al, %al
jne 0x967e
movq 0x120(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x110(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xa564
pushq $0x3
popq %rcx
testb %al, %al
jne 0x967e
movq 0x108(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0xf8(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xa564
pushq $0x4
popq %rcx
testb %al, %al
jne 0x967e
movq 0xf0(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0xe0(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xa564
pushq $0x5
popq %rcx
testb %al, %al
jne 0x967e
movq 0x38(%rsp), %rcx
movb (%rcx), %al
cmpb $0x5b, %al
jne 0x97dd
movq 0x40(%rsp), %rdx
cmpb $0x5d, -0x1(%rcx,%rdx)
je 0x99ef
testl %r12d, %r12d
je 0x99e2
movl %r12d, %edx
andl $-0x2, %edx
cmpl $0x4, %edx
jne 0x98e2
movq 0x58(%rsp), %rdi
pushq $0x38
popq %rsi
callq 0x24fc
movq %rax, 0x50(%rsp)
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xc8(%rsp), %rdi
movq 0x58(%rsp), %rsi
callq 0xa466
movq 0xd8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xc8(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x70(%rsp), %rdi
callq 0xa454
movq 0x50(%rsp), %rax
movq %rbx, 0x20(%rax)
leaq 0xb0(%rsp), %rdi
leaq 0x4972(%rip), %rsi      # 0xe1e2
callq 0xa3d0
movq 0xc0(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0xb0(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x50(%rsp), %rcx
movq 0x18(%rcx), %rax
movq %rax, 0x10(%rsp)
movups 0x8(%rcx), %xmm0
movups %xmm0, (%rsp)
movq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x933d
cmpl $0x5, %r12d
movq 0x50(%rsp), %rdx
movq %rax, (%rdx)
movb $0x0, 0x28(%rdx)
movq 0x80(%rsp), %rax
cmoveq 0x78(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq %rcx, 0x30(%rdx)
movq %rdx, (%rax)
jmp 0x967b
cmpb $0x2f, %al
jne 0x9a19
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xa5eb
testb %al, %al
jne 0x9a26
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x98(%rsp), %rdi
callq 0xa4a2
movq 0xa8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x98(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x60(%rsp), %rdi
callq 0xa908
testq %rax, %rax
je 0x9964
movl 0x2c(%rax), %ecx
testl %ecx, %ecx
je 0x9994
cmpb $0x0, 0x30(%rax)
jne 0x9994
jmp 0x9a40
movq 0xa8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x98(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x68(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq %rbx, %rcx
callq 0x9a74
movl %r12d, 0x2c(%rax)
movb $0x0, 0x30(%rax)
movq %rbx, 0x38(%rax)
movq %rax, %rdi
callq 0x9c9a
jmp 0x967b
movq 0x88(%rsp), %rdi
callq 0xd21a
movq 0x90(%rsp), %rax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x54e0(%rip), %rdi      # 0xeebb
xorl %eax, %eax
callq 0x3918
movl 0x40(%rsp), %edx
leaq 0x5540(%rip), %rdi      # 0xef2d
jmp 0x9a36
incq %rcx
addq $-0x2, %rdx
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %rcx, %rsi
callq 0xa3ec
movl 0x8(%r14), %edx
movq (%r14), %rcx
leaq 0x54ed(%rip), %rdi      # 0xef04
jmp 0x9a36
movl 0x40(%rsp), %edx
leaq 0x55a9(%rip), %rdi      # 0xefcd
jmp 0x9a36
movl 0x40(%rsp), %edx
movq 0x38(%rsp), %rcx
leaq 0x5528(%rip), %rdi      # 0xef5e
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3918
cmpl %r12d, %ecx
leaq 0x5578(%rip), %rdx      # 0xefc2
leaq 0x4d4e(%rip), %rcx      # 0xe79f
cmoveq %rcx, %rdx
movq 0x38(%rax), %rcx
movl 0x40(%rsp), %r8d
movq 0x38(%rsp), %r9
leaq 0x5528(%rip), %rdi      # 0xef92
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3918