// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movq 0x1b0(%rsp), %r14
movq 0x1b8(%rsp), %r15
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x2200
testq %rax, %rax
jne 0xa155
movq %rbx, 0x50(%rsp)
movq %rbx, %rdi
callq 0x2828
movq %rax, %rbp
movl $0x68, %esi
movq %rax, %rdi
callq 0x27ac
movq %rax, %r12
leaq 0x4817(%rip), %rsi      # 0xe448
leaq 0x160(%rsp), %rbx
movq %rbx, %rdi
callq 0xab5c
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0xac25
xorl %r13d, %r13d
movq %r13, 0x60(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%r12)
movups %xmm0, 0x21(%r12)
movups %xmm0, 0x38(%r12)
movb $0x0, 0x48(%r12)
movl $0x8, %esi
movq %rbp, %rdi
callq 0x27ac
movq %rax, 0x50(%r12)
movq %r13, (%rax)
movl $0x8, %esi
movq %rbp, 0x48(%rsp)
movq %rbp, %rdi
callq 0x27ac
movq %rax, 0x58(%r12)
movq %r13, (%rax)
callq 0xd89c
movq %rax, 0x80(%rsp)
movq %rax, %rdi
callq 0xaf98
movq %rax, %rbp
leaq 0x4ad5(%rip), %rsi      # 0xe79f
leaq 0x148(%rsp), %rbx
movq %rbx, %rdi
callq 0xab5c
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
movups (%rbx), %xmm0
movups %xmm0, (%rsp)
movq %rbp, %rdi
movq %r12, 0x58(%rsp)
movq %r12, %rsi
callq 0xb043
cmpq $0x3, %r15
jb 0x9d20
cmpb $-0x11, (%r14)
jne 0x9d1d
cmpb $-0x45, 0x1(%r14)
jne 0x9d1d
xorl %eax, %eax
cmpb $-0x41, 0x2(%r14)
sete %al
leaq (%rax,%rax,2), %r13
jmp 0x9d20
xorl %r13d, %r13d
movq %rbp, 0x78(%rsp)
leaq 0x51ab(%rip), %rsi      # 0xeed7
leaq 0x130(%rsp), %rdi
callq 0xab5c
leaq 0x519e(%rip), %rsi      # 0xeede
leaq 0x118(%rsp), %rdi
callq 0xab5c
leaq 0x5193(%rip), %rsi      # 0xeee7
leaq 0x100(%rsp), %rdi
callq 0xab5c
leaq 0x5187(%rip), %rsi      # 0xeeef
leaq 0xe8(%rsp), %rdi
callq 0xab5c
leaq 0x517c(%rip), %rsi      # 0xeef8
leaq 0xd0(%rsp), %rdi
callq 0xab5c
cmpq %r15, %r13
jae 0xa131
movq 0x58(%rsp), %rax
leaq 0x50(%rax), %rcx
movq %rcx, 0x70(%rsp)
addq $0x58, %rax
movq %rax, 0x68(%rsp)
xorl %r12d, %r12d
movl $0x1, %ebx
movq %r13, %rdx
cmpb $0xa, (%r14,%rdx)
je 0x9dc6
incq %rdx
cmpq %rdx, %r15
jne 0x9db4
movq %r15, %rdx
leaq (%r14,%r13), %rsi
subq %r13, %rdx
leaq 0x30(%rsp), %rdi
callq 0xab78
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xad83
testb %al, %al
jne 0x9dfd
movq 0x30(%rsp), %rax
cmpb $0x23, (%rax)
jne 0x9e1f
movl %r12d, %ebp
movq 0x38(%rsp), %rax
leaq (%rax,%r13), %rcx
cmpq %r15, %rcx
adcq %rax, %r13
incq %rbx
movl %ebp, %r12d
cmpq %r15, %r13
jb 0x9db1
jmp 0xa131
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, %ebp
callq 0xad56
testb %al, %al
jne 0x9e00
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, %ebp
callq 0xad56
testb %al, %al
jne 0x9e00
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, %ebp
callq 0xad56
testb %al, %al
jne 0x9e00
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, %ebp
callq 0xad56
testb %al, %al
jne 0x9e00
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, %ebp
callq 0xad56
testb %al, %al
jne 0x9e00
movq 0x30(%rsp), %rcx
movb (%rcx), %al
cmpb $0x5b, %al
jne 0x9f71
movq 0x38(%rsp), %rdx
cmpb $0x5d, -0x1(%rcx,%rdx)
je 0xa18f
testl %r12d, %r12d
je 0xa163
movl %r12d, %edx
andl $-0x2, %edx
cmpl $0x4, %edx
jne 0xa065
movl $0x38, %esi
movq 0x48(%rsp), %rdi
callq 0x27ac
movq %rax, %rbp
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 0xac37
movq 0xc8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xb8(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x60(%rsp), %rdi
callq 0xac25
movq %rbx, 0x20(%rbp)
leaq 0xa0(%rsp), %rdi
leaq 0x41e3(%rip), %rsi      # 0xe1e2
callq 0xab5c
movq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0xa0(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x18(%rbp), %rax
movq %rax, 0x10(%rsp)
movups 0x8(%rbp), %xmm0
movups %xmm0, (%rsp)
movq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x9a9e
cmpl $0x5, %r12d
movq %rax, (%rbp)
movb $0x0, 0x28(%rbp)
movq 0x70(%rsp), %rax
cmoveq 0x68(%rsp), %rax
movq (%rax), %rax
movq (%rax), %rcx
movq %rcx, 0x30(%rbp)
movq %rbp, (%rax)
jmp 0x9dfd
cmpb $0x2f, %al
jne 0xa170
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0xae00
testb %al, %al
jne 0xa17d
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x88(%rsp), %rdi
callq 0xac98
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x78(%rsp), %rbp
movq %rbp, %rdi
callq 0xb15e
testq %rax, %rax
je 0xa0ea
movl 0x2c(%rax), %ecx
testl %ecx, %ecx
je 0xa118
cmpb $0x0, 0x30(%rax)
jne 0xa118
jmp 0xa1c1
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xa1f5
movl %r12d, 0x2c(%rax)
movb $0x0, 0x30(%rax)
movq %rbx, 0x38(%rax)
movq %rax, %rdi
callq 0xa426
jmp 0x9dfd
movq 0x80(%rsp), %rdi
callq 0xda8a
movq 0x58(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4d5f(%rip), %rdi      # 0xeebb
xorl %eax, %eax
callq 0x3ca8
movl 0x38(%rsp), %edx
leaq 0x4dbf(%rip), %rdi      # 0xef2d
jmp 0xa1b7
movl 0x38(%rsp), %edx
leaq 0x4e52(%rip), %rdi      # 0xefcd
jmp 0xa1b7
movl 0x38(%rsp), %edx
movq 0x30(%rsp), %rcx
leaq 0x4dd1(%rip), %rdi      # 0xef5e
jmp 0xa1b7
incq %rcx
addq $-0x2, %rdx
leaq 0x88(%rsp), %r14
movq %r14, %rdi
movq %rcx, %rsi
callq 0xab78
movl 0x8(%r14), %edx
movq (%r14), %rcx
leaq 0x4d4d(%rip), %rdi      # 0xef04
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3ca8
cmpl %r12d, %ecx
leaq 0x4df7(%rip), %rdx      # 0xefc2
leaq 0x45cd(%rip), %rcx      # 0xe79f
cmoveq %rcx, %rdx
movq 0x38(%rax), %rcx
movl 0x38(%rsp), %r8d
movq 0x30(%rsp), %r9
leaq 0x4da7(%rip), %rdi      # 0xef92
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3ca8