// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
movq %r9, -0x68(%rbp)
movq %r8, %r14
movq %rdx, -0x98(%rbp)
movq %rsi, -0x60(%rbp)
incl %ecx
cmpl $0x40, %ecx
movl $0x40, %r12d
movq %rcx, -0x38(%rbp)
cmovbl %ecx, %r12d
imull $0x38, %r12d, %eax
addl $0xf, %eax
andl $0x3ff0, %eax           # imm = 0x3FF0
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
leal 0xf(,%r12,8), %eax
andl $0x7f0, %eax            # imm = 0x7F0
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
leaq -0xb0(%rbp), %rcx
movzwl 0x8(%rdi), %eax
cmpq $0x1, (%rdi)
adcw $0x0, %ax
movq $-0x5, (%rcx)
movw %ax, -0x2a(%rbp)
movw %ax, 0x8(%rcx)
movq 0x10(%rdi), %rax
movq %rax, 0x10(%rcx)
leaq 0x30(%r15), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x30(%rbp)
movq %r13, -0x48(%rbp)
movq %r15, -0x58(%rbp)
movq $0x0, 0x10(%r14)
cmpl $0x0, -0x30(%rbp)
movq %rbx, -0x80(%rbp)
je 0x4b79
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rbx
movq 0x18(%rax), %r13
movq %r14, %rdi
movq %rbx, %rsi
callq *0x20(%r14)
testl %eax, %eax
jne 0x4ec2
movq 0x18(%r14), %rdi
addq 0x10(%r14), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x1140
addq 0x10(%r14), %rbx
movq %rbx, 0x10(%r14)
movzwl -0x2a(%rbp), %edi
jmp 0x4c37
movl $0x30, %esi
movq %r14, %rdi
callq *0x20(%r14)
testl %eax, %eax
jne 0x4ec2
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 0x4ec2
movq -0x60(%rbp), %rax
movl (%rax), %ebx
movq %r14, %rdi
xorl %esi, %esi
leaq -0xb0(%rbp), %rdx
movl %ebx, %ecx
callq 0x5444
testq %rbx, %rbx
je 0x4bfd
movq -0x60(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
xorl %edi, %edi
movq (%rcx,%rdi,8), %r8
movq %r8, (%rdx,%rsi)
movq 0x10(%r14), %rsi
addq $0x8, %rsi
movq %rsi, 0x10(%r14)
incq %rdi
cmpq %rdi, %rbx
jne 0x4be1
testq %rax, %rax
je 0x4ec2
movq 0x10(%r14), %rbx
movq %r13, %rax
movq 0x18(%r14), %r13
movq %rbx, 0x18(%r13)
movl $0x1, 0x20(%r13)
movzwl -0x2a(%rbp), %edi
movw %di, 0x2c(%r13)
movq $0x0, (%rax)
movq -0x38(%rbp), %rax
decl %eax
movq %rax, -0x38(%rbp)
movl %r12d, %r12d
cmpl $0x2, %r12d
jb 0x4d86
movq 0x8(%r13), %rax
movq %rax, -0x90(%rbp)
movq -0x38(%rbp), %rax
subl %r12d, %eax
incl %eax
movl %eax, -0x4c(%rbp)
leaq -0x1(%r12), %rax
movq %rax, -0x88(%rbp)
movl -0x30(%rbp), %eax
movq %rax, -0x70(%rbp)
movb $0x1, %r15b
xorl %r13d, %r13d
movq -0x70(%rbp), %rax
addl %r13d, %eax
movq -0x48(%rbp), %rcx
movq %rbx, 0x8(%rcx,%r13,8)
leaq (%rax,%rax,2), %rax
movq -0x98(%rbp), %rcx
movzwl 0x8(%rcx,%rax,8), %edx
cmpq $0x1, (%rcx,%rax,8)
adcw $0x0, %dx
movq $-0x4, -0xb0(%rbp)
movw %dx, -0x2a(%rbp)
movw %dx, -0xa8(%rbp)
movq 0x10(%rcx,%rax,8), %rax
movq %rax, -0xa0(%rbp)
movl $0x30, %esi
movq %r14, %rdi
callq *0x20(%r14)
testl %eax, %eax
jne 0x4ec2
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 0x4ec2
movq %r14, %rdi
movq %rbx, %rsi
leaq -0xb0(%rbp), %rdx
movl $0x1, %ecx
callq 0x5444
movq 0x10(%r14), %rcx
movq 0x18(%r14), %rdx
movq -0x90(%rbp), %rsi
movq %rsi, (%rdx,%rcx)
movq 0x10(%r14), %rcx
addq $0x8, %rcx
movq %rcx, 0x10(%r14)
testq %rax, %rax
je 0x4e97
movq %rcx, %rax
subq %rbx, %rax
movq %rax, 0x18(%rdx,%rbx)
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x24(%rdx,%rbx)
movzwl -0x2a(%rbp), %edi
movw %di, 0x2c(%rdx,%rbx)
leaq 0x2(%r13), %rax
cmpq %r12, %rax
setb %r15b
incq %r13
movq %rcx, %rbx
cmpq %r13, -0x88(%rbp)
jne 0x4c74
addl %r13d, -0x30(%rbp)
movl -0x4c(%rbp), %eax
movq %rax, -0x38(%rbp)
movq -0x58(%rbp), %r15
movw %di, -0x2a(%rbp)
testq %r12, %r12
movq -0x48(%rbp), %r13
je 0x4e5a
movq 0x18(%r14), %rax
movq -0x78(%rbp), %rcx
xorl %edx, %edx
movq (%r13,%rdx,8), %r11
addq %rax, %r11
movw $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
testq %rax, %rax
je 0x4dd3
movq (%r11), %rdi
movq %rdi, %r8
shrq $0x3e, %r8
jne 0x4e1d
movq $-0x3, %r10
xorl %r8d, %r8d
jmp 0x4ddd
xorl %r8d, %r8d
movq $-0x2, %r10
xorl %edi, %edi
xorl %r9d, %r9d
movq %r11, -0x30(%rcx)
movq %r11, -0x28(%rcx)
movq %r8, -0x20(%rcx)
movw %di, -0x18(%rcx)
movl -0x40(%rbp), %edi
movl %edi, -0x16(%rcx)
movzwl -0x3c(%rbp), %edi
movw %di, -0x12(%rcx)
movq %r9, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movq %r10, (%rcx)
incq %rdx
addq $0x38, %rcx
cmpq %rdx, %r12
jne 0x4da1
jmp 0x4e5a
btq $0x3d, %rdi
jb 0x4e3b
leaq 0x8(%r11), %r9
shrq $0x30, %rdi
andl $0xfff, %edi            # imm = 0xFFF
movzbl (%r9), %r10d
xorl %r8d, %r8d
jmp 0x4de2
movzbl 0x8(%r11), %r8d
orq $-0x100, %r8
leaq 0x9(%r11), %r9
shrq $0x30, %rdi
andl $0xfff, %edi            # imm = 0xFFF
movq %r8, %r10
jmp 0x4de2
movq %r15, %rdi
movq %r12, %rsi
movq -0x68(%rbp), %rdx
movl $0x4, %ecx
callq 0x4149
movq %rax, %rbx
movq -0x38(%rbp), %rax
leal 0x1(%rax), %r12d
cmpl $0x40, %r12d
movl $0x40, %eax
cmovael %eax, %r12d
testq %rbx, %rbx
je 0x4ec4
cmpl $0x0, -0x38(%rbp)
jne 0x4b25
jmp 0x4ec4
testb $0x1, %r15b
jne 0x4ec2
movq -0x38(%rbp), %rax
movl %eax, %eax
subq %r13, %rax
movq %rax, -0x38(%rbp)
movq -0x70(%rbp), %rax
addq %r13, %rax
movl %eax, -0x30(%rbp)
movq -0x58(%rbp), %r15
movq -0x48(%rbp), %r13
movq -0x80(%rbp), %rbx
jmp 0x4e86
xorl %ebx, %ebx
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq