// File: /workspace/github_c_makefile_star2_O1/jflatow[P]jfdb/src/trie.c
// Function: JFT_atom
JFT *JFT_atom(const JFT_Stem *restrict primary,
              const JFT_Leaf *restrict value,
              const JFT_Stem *restrict indices,
              JFT_Count numIndices,
              JFT_Buffer *restrict scratch,
              JFT_Buffer *restrict output) {
  // create an atomic trie (i.e. a single operation)
  // using these atoms we can make bigger and bigger tries
  // first, manually create a trie for each individual key
  JFT *atom;
  JFT_Count num = numIndices + 1, k = 0, batch = MIN(num, JFT_MASK_CAPACITY);
  JFT_Cursor cursors[batch];
  JFT_Offset rootOffsets[batch];
  JFT_Root *root;
  JFT_Stem stem = (JFT_Stem) {
    .pre = JFT_SYMBOL_PRIMARY,
    .size = primary->size + !primary->pre,
    .data = primary->data
  };

  do {
    if (!(JFT_buffer_reset(scratch)))
      return NULL;

    if (k == 0) {
      if (!(make_root(scratch)))
        return NULL;
      if (!(make_leaf(scratch, 0, &stem, value)))
        return NULL;
      root = (JFT_Root *)(scratch->data);
      root->extent = scratch->mark;
      root->numPrimary = 1;
      root->maxKeySize = stem.size;
      rootOffsets[0] = 0;
      num--;
    } else {
      root = (JFT_Root *)(output->data);
      if (!JFT_buffer_write(scratch, output->data, output->mark))
        return NULL;
    }

    JFT_Leaf index = JFTV(root->primaryOffset);
    for (JFT_Count i = 1; i < batch; i++, k++) {
      rootOffsets[i] = scratch->mark;
      stem.pre = JFT_SYMBOL_INDICES;
      stem.size = indices[k].size + !indices[k].pre;
      stem.data = indices[k].data;
      if (!(make_root(scratch)))
        return NULL;
      if (!(make_leaf(scratch, rootOffsets[i], &stem, &index)))
        return NULL;
      root = (JFT_Root *)(scratch->data + rootOffsets[i]);
      root->extent = scratch->mark - rootOffsets[i];
      root->numIndices = 1;
      root->maxIndices = 1;
      root->maxKeySize = stem.size;
      num--;
    }

    for (JFT_Amount i = 0; i < batch; i++)
      cursors[i] = JFT_cursor((JFT *)(scratch->data + rootOffsets[i]));
    atom = JFT_cursor_merge_new(cursors, batch, output, JFT_FLAGS_ATOM);
    batch = MIN(num + 1, JFT_MASK_CAPACITY);
  } while (atom && num);
  return atom;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, -0x60(%rbp)
movl %ecx, %r13d
movq %rdx, -0xa8(%rbp)
movq %rsi, -0x58(%rbp)
incl %r13d
cmpl $0x40, %r13d
movl $0x40, %r12d
cmovbl %r13d, %r12d
imull $0x38, %r12d, %eax
addl $0xf, %eax
andl $0x3ff0, %eax           # imm = 0x3FF0
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, %rsp
leal 0xf(,%r12,8), %eax
andl $0x7f0, %eax            # imm = 0x7F0
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, %rsp
movq $-0x5, -0x78(%rbp)
cmpq $0x1, (%rdi)
movzwl 0x8(%rdi), %r15d
adcw $0x0, %r15w
movw %r15w, -0x70(%rbp)
movq 0x10(%rdi), %rax
movq %rax, -0x68(%rbp)
movq $0x0, 0x10(%r8)
testq %r8, %r8
je 0x540f
movq %r8, %r14
movq %rcx, -0x88(%rbp)
leaq 0x30(%rcx), %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x2c(%rbp)
movq %rdx, -0x48(%rbp)
cmpl $0x0, -0x2c(%rbp)
movq %rbx, -0x98(%rbp)
je 0x50ce
movq %r12, -0x40(%rbp)
movq %r13, %r12
movq -0x60(%rbp), %rax
movq 0x10(%rax), %r13
movq 0x18(%rax), %rbx
movq %r14, %rdi
movq %r13, %rsi
callq *0x20(%r14)
testl %eax, %eax
jne 0x540f
movq 0x18(%r14), %rdi
addq 0x10(%r14), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x1140
addq %r13, 0x10(%r14)
movq %r12, %r13
movq -0x40(%rbp), %r12
jmp 0x5177
movl $0x30, %esi
movq %r14, %rdi
callq *0x20(%r14)
testl %eax, %eax
jne 0x540f
movq 0x10(%r14), %rax
movq 0x18(%r14), %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rcx,%rax)
movups %xmm0, 0x10(%rcx,%rax)
movups %xmm0, (%rcx,%rax)
addq $0x30, 0x10(%r14)
je 0x540f
movq -0x58(%rbp), %rax
movl (%rax), %ebx
movq %r14, %rdi
xorl %esi, %esi
leaq -0x78(%rbp), %rdx
movl %ebx, %ecx
callq 0x5adc
testq %rbx, %rbx
je 0x5148
movq -0x58(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x18(%r14), %rdx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
movq 0x10(%r14), %r8
movq %rdi, (%rdx,%r8)
addq $0x8, 0x10(%r14)
incq %rsi
cmpq %rsi, %rbx
jne 0x512f
testq %rax, %rax
je 0x540f
movq 0x10(%r14), %rax
movq 0x18(%r14), %rbx
movq %rax, 0x18(%rbx)
movl $0x1, 0x20(%rbx)
movw %r15w, 0x2c(%rbx)
movq -0x48(%rbp), %rax
movq $0x0, (%rax)
decl %r13d
movl %r12d, %r12d
cmpl $0x2, %r12d
setae %al
jb 0x52be
movq 0x8(%rbx), %rcx
movq %rcx, -0xb0(%rbp)
movq %r13, -0x90(%rbp)
movl %r13d, %ecx
subl %r12d, %ecx
incl %ecx
movl %ecx, -0x4c(%rbp)
leaq -0x1(%r12), %rcx
movq %rcx, -0xa0(%rbp)
movl -0x2c(%rbp), %ecx
movq %rcx, -0xb8(%rbp)
xorl %r13d, %r13d
movb %al, -0x40(%rbp)
movq -0xb8(%rbp), %rax
addl %r13d, %eax
movq 0x10(%r14), %rbx
movq -0x48(%rbp), %rcx
movq %rbx, 0x8(%rcx,%r13,8)
leaq (%rax,%rax,2), %rax
movq -0xa8(%rbp), %rcx
movzwl 0x8(%rcx,%rax,8), %r15d
cmpq $0x1, (%rcx,%rax,8)
adcw $0x0, %r15w
movq $-0x4, -0x78(%rbp)
movw %r15w, -0x70(%rbp)
movq 0x10(%rcx,%rax,8), %rax
movq %rax, -0x68(%rbp)
movl $0x30, %esi
movq %r14, %rdi
callq *0x20(%r14)
testl %eax, %eax
jne 0x53d6
movq 0x10(%r14), %rax
movq 0x18(%r14), %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rcx,%rax)
movups %xmm0, 0x10(%rcx,%rax)
movups %xmm0, (%rcx,%rax)
addq $0x30, 0x10(%r14)
je 0x53d6
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x78(%rbp), %rdx
movl $0x1, %ecx
callq 0x5adc
movq 0x10(%r14), %rcx
movq 0x18(%r14), %rdx
movq -0xb0(%rbp), %rsi
movq %rsi, (%rdx,%rcx)
addq $0x8, 0x10(%r14)
testq %rax, %rax
je 0x53d6
movq 0x10(%r14), %rax
movq 0x18(%r14), %rcx
subq %rbx, %rax
movq %rax, 0x18(%rcx,%rbx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x24(%rcx,%rbx)
movw %r15w, 0x2c(%rcx,%rbx)
leaq 0x2(%r13), %rax
cmpq %r12, %rax
setb %al
incq %r13
cmpq %r13, -0xa0(%rbp)
jne 0x51bd
addl %r13d, -0x2c(%rbp)
movl -0x4c(%rbp), %ecx
movl %ecx, %r13d
movb %al, -0x40(%rbp)
testq %r12, %r12
movq -0x48(%rbp), %rbx
je 0x53a8
movq 0x18(%r14), %rax
movq -0x80(%rbp), %rcx
xorl %edx, %edx
movq (%rbx,%rdx,8), %rsi
addq %rax, %rsi
movw $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
testq %rax, %rax
je 0x5319
movq (%rsi), %rdi
movq %rdi, %r8
shrq $0x3e, %r8
jne 0x532d
movw $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movq $-0x3, %r10
xorl %r8d, %r8d
movq %rsi, %r11
jmp 0x5326
xorl %r11d, %r11d
movq $-0x2, %r10
xorl %r8d, %r8d
xorl %edi, %edi
xorl %r9d, %r9d
jmp 0x536b
btq $0x3d, %rdi
jb 0x533d
leaq 0x8(%rsi), %r9
xorl %r8d, %r8d
jmp 0x534d
movzbl 0x8(%rsi), %r8d
orq $-0x100, %r8
leaq 0x9(%rsi), %r9
shrq $0x30, %rdi
andl $0xfff, %edi            # imm = 0xFFF
testq %r8, %r8
je 0x5364
movq %rsi, %r11
movq %r8, %r10
jmp 0x536b
movzbl (%r9), %r10d
movq %rsi, %r11
movq %rsi, -0x30(%rcx)
movq %r11, -0x28(%rcx)
movq %r8, -0x20(%rcx)
movw %di, -0x18(%rcx)
movl -0x34(%rbp), %esi
movl %esi, -0x16(%rcx)
movzwl -0x30(%rbp), %esi
movw %si, -0x12(%rcx)
movq %r9, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movq %r10, (%rcx)
incq %rdx
addq $0x38, %rcx
cmpq %rdx, %r12
jne 0x52d8
movq -0x88(%rbp), %rdi
movq %r12, %rsi
movq -0x60(%rbp), %rdx
movl $0x4, %ecx
callq 0x45bf
movq %rax, %rbx
leal 0x1(%r13), %r12d
cmpl $0x40, %r12d
movl $0x40, %eax
cmovael %eax, %r12d
jmp 0x53ee
movq -0x90(%rbp), %rax
subl %r13d, %eax
addl %r13d, -0x2c(%rbp)
movq %rax, %r13
movq -0x98(%rbp), %rbx
testb $0x1, -0x40(%rbp)
jne 0x540f
testq %rbx, %rbx
je 0x5411
testl %r13d, %r13d
je 0x5411
movq $0x0, 0x10(%r14)
testq %r14, %r14
jne 0x5079
xorl %ebx, %ebx
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq