// File: /workspace/github_c_makefile_star2_O1/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 $0x178, %rsp            # imm = 0x178
movq %rdi, %r14
movq 0x1b0(%rsp), %rbx
movq 0x1b8(%rsp), %r13
movq %rbx, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x2200
testq %rax, %rax
jne 0xa512
movq %r14, 0x50(%rsp)
movq %r14, %rdi
callq 0x28cc
movq %rax, %rbp
movl $0x68, %esi
movq %rax, %rdi
callq 0x284c
movq %rax, %r15
leaq 0x4463(%rip), %rsi      # 0xe448
leaq 0x160(%rsp), %r12
movq %r12, %rdi
callq 0xaf28
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
callq 0xaff1
xorl %r12d, %r12d
movq %r12, 0x60(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r15)
movups %xmm0, 0x21(%r15)
movups %xmm0, 0x38(%r15)
movb $0x0, 0x48(%r15)
movl $0x8, %esi
movq %rbp, %rdi
callq 0x284c
movq %rax, 0x50(%r15)
movq %r12, (%rax)
movl $0x8, %esi
movq %rbp, 0x48(%rsp)
movq %rbp, %rdi
callq 0x284c
movq %rax, 0x58(%r15)
movq %r12, (%rax)
callq 0xdc7c
movq %rax, 0x80(%rsp)
movq %rax, %rdi
callq 0xb374
movq %rax, %r14
leaq 0x4728(%rip), %rsi      # 0xe7a2
leaq 0x148(%rsp), %rbp
movq %rbp, %rdi
callq 0xaf28
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rsp)
movups (%rbp), %xmm0
movups %xmm0, (%rsp)
movq %r14, 0x78(%rsp)
movq %r14, %rdi
movq %r15, 0x58(%rsp)
movq %r15, %rsi
callq 0xb41f
cmpq $0x3, %r13
jb 0xa0d3
cmpb $-0x11, (%rbx)
jne 0xa0d0
cmpb $-0x45, 0x1(%rbx)
jne 0xa0d0
xorl %eax, %eax
cmpb $-0x41, 0x2(%rbx)
sete %al
leaq (%rax,%rax,2), %r12
jmp 0xa0d3
xorl %r12d, %r12d
leaq 0x4e00(%rip), %rsi      # 0xeeda
leaq 0x130(%rsp), %rdi
callq 0xaf28
leaq 0x4df3(%rip), %rsi      # 0xeee1
leaq 0x118(%rsp), %rdi
callq 0xaf28
leaq 0x4de8(%rip), %rsi      # 0xeeea
leaq 0x100(%rsp), %rdi
callq 0xaf28
leaq 0x4ddc(%rip), %rsi      # 0xeef2
leaq 0xe8(%rsp), %rdi
callq 0xaf28
leaq 0x4dd1(%rip), %rsi      # 0xeefb
leaq 0xd0(%rsp), %rdi
callq 0xaf28
leaq 0x1b0(%rsp), %rdx
movq 0x8(%rdx), %rbp
cmpq %rbp, %r12
jae 0xa4ee
movq 0x58(%rsp), %rax
leaq 0x50(%rax), %rcx
movq %rcx, 0x70(%rsp)
addq $0x58, %rax
movq %rax, 0x68(%rsp)
movq (%rdx), %r15
xorl %r14d, %r14d
movl $0x1, %r13d
movq %r12, %rdx
cmpb $0xa, (%r15,%rdx)
je 0xa184
incq %rdx
cmpq %rdx, %rbp
jne 0xa172
movq %rbp, %rdx
leaq (%r15,%r12), %rsi
subq %r12, %rdx
leaq 0x30(%rsp), %rdi
callq 0xaf44
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xb153
testb %al, %al
jne 0xa1bb
movq 0x30(%rsp), %rax
cmpb $0x23, (%rax)
jne 0xa1dd
movl %r14d, %ebx
movq 0x38(%rsp), %rax
leaq (%rax,%r12), %rcx
cmpq %rbp, %rcx
adcq %rax, %r12
incq %r13
movl %ebx, %r14d
cmpq %rbp, %r12
jb 0xa16f
jmp 0xa4ee
movq 0x140(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x130(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movl $0x1, %ebx
callq 0xb126
testb %al, %al
jne 0xa1be
movq 0x128(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x118(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movl $0x2, %ebx
callq 0xb126
testb %al, %al
jne 0xa1be
movq 0x110(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x100(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movl $0x3, %ebx
callq 0xb126
testb %al, %al
jne 0xa1be
movq 0xf8(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0xe8(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movl $0x4, %ebx
callq 0xb126
testb %al, %al
jne 0xa1be
movq 0xe0(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0xd0(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movl $0x5, %ebx
callq 0xb126
testb %al, %al
jne 0xa1be
movq 0x30(%rsp), %rcx
movb (%rcx), %al
cmpb $0x5b, %al
jne 0xa32f
movq 0x38(%rsp), %rdx
cmpb $0x5d, -0x1(%rcx,%rdx)
je 0xa54c
testl %r14d, %r14d
movq 0x78(%rsp), %rbx
je 0xa520
movl %r14d, %edx
andl $-0x2, %edx
cmpl $0x4, %edx
jne 0xa427
movl $0x38, %esi
movq 0x48(%rsp), %rdi
callq 0x284c
movq %rax, %rbx
addq $0x8, %rax
movq %rax, 0x60(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0xb8(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0xb003
movq 0xc8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xb8(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x60(%rsp), %rdi
callq 0xaff1
movq %r13, 0x20(%rbx)
leaq 0xa0(%rsp), %rdi
leaq 0x3e20(%rip), %rsi      # 0xe1e2
callq 0xaf28
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0xa0(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x18(%rbx), %rax
movq %rax, 0x10(%rsp)
movups 0x8(%rbx), %xmm0
movups %xmm0, (%rsp)
movq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x9e25
cmpl $0x5, %r14d
movq %rax, (%rbx)
movb $0x0, 0x28(%rbx)
movq 0x70(%rsp), %rax
cmoveq 0x68(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq %rcx, 0x30(%rbx)
movq %rbx, (%rax)
jmp 0xa1bb
cmpb $0x2f, %al
jne 0xa52d
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xb1d6
testb %al, %al
jne 0xa53a
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x88(%rsp), %rdi
callq 0xb064
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0xb53a
testq %rax, %rax
je 0xa4a7
movl 0x2c(%rax), %ecx
testl %ecx, %ecx
je 0xa4d5
cmpb $0x0, 0x30(%rax)
jne 0xa4d5
jmp 0xa57d
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %rbx, %rdx
movq %r13, %rcx
callq 0xa5b1
movl %r14d, 0x2c(%rax)
movb $0x0, 0x30(%rax)
movq %r13, 0x38(%rax)
movq %rax, %rdi
callq 0xa7e5
jmp 0xa1bb
movq 0x80(%rsp), %rdi
callq 0xde6a
movq 0x58(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x49a5(%rip), %rdi      # 0xeebe
xorl %eax, %eax
callq 0x3dc4
movl 0x38(%rsp), %edx
leaq 0x4a05(%rip), %rdi      # 0xef30
jmp 0xa573
movl 0x38(%rsp), %edx
leaq 0x4a98(%rip), %rdi      # 0xefd0
jmp 0xa573
movl 0x38(%rsp), %edx
movq 0x30(%rsp), %rcx
leaq 0x4a17(%rip), %rdi      # 0xef61
jmp 0xa573
incq %rcx
addq $-0x2, %rdx
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
movq %rcx, %rsi
callq 0xaf44
movl 0x8(%rbx), %edx
movq (%rbx), %rcx
leaq 0x4994(%rip), %rdi      # 0xef07
movq %r13, %rsi
xorl %eax, %eax
callq 0x3dc4
cmpl %r14d, %ecx
leaq 0x4a3e(%rip), %rdx      # 0xefc5
leaq 0x4214(%rip), %rcx      # 0xe7a2
cmoveq %rcx, %rdx
movq 0x38(%rax), %rcx
movl 0x38(%rsp), %r8d
movq 0x30(%rsp), %r9
leaq 0x49ee(%rip), %rdi      # 0xef95
movq %r13, %rsi
xorl %eax, %eax
callq 0x3dc4