// File: /workspace/github_c_makefile_star2_O0/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
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpq $0x40, %rax
jae 0x6207
movl -0x44(%rbp), %eax
movq %rax, -0xf8(%rbp)
jmp 0x6215
movl $0x40, %eax
movq %rax, -0xf8(%rbp)
jmp 0x6215
movq -0xf8(%rbp), %rax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x58(%rbp)
imulq $0x38, %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x108(%rbp)
movq %rcx, %rsp
movq %rax, -0x60(%rbp)
movl -0x4c(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x100(%rbp)
movq %rcx, %rsp
movq %rax, -0x68(%rbp)
movq $-0x5, -0x88(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpq $0x0, (%rcx)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
movw %ax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rdi
callq 0x5940
cmpq $0x0, %rax
jne 0x62cb
movq $0x0, -0x8(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x6670
cmpl $0x0, -0x48(%rbp)
jne 0x637c
movq -0x30(%rbp), %rdi
callq 0x6680
cmpq $0x0, %rax
jne 0x62fb
movq $0x0, -0x8(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x6670
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0x88(%rbp), %rdx
callq 0x6720
cmpq $0x0, %rax
jne 0x6330
movq $0x0, -0x8(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x6670
movq -0x100(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq %rcx, -0x70(%rbp)
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq -0x70(%rbp), %rcx
movq %rdx, 0x18(%rcx)
movq -0x70(%rbp), %rcx
movl $0x1, 0x20(%rcx)
movw -0x80(%rbp), %dx
movq -0x70(%rbp), %rcx
movw %dx, 0x2c(%rcx)
movq $0x0, (%rax)
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x63c0
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x67b0
cmpq $0x0, %rax
jne 0x63be
movq $0x0, -0x8(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x6670
jmp 0x63c0
movl $0x1, -0xa0(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x1, -0xac(%rbp)
movl -0xac(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x655a
movq -0x100(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rdx
movl -0xac(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq $-0x4, -0x88(%rbp)
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movzwl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq $0x0, (%rcx)
setne %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
movw %ax, -0x80(%rbp)
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6680
cmpq $0x0, %rax
jne 0x6496
movq $0x0, -0x8(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x6670
movq -0x100(%rbp), %rax
movq -0x30(%rbp), %rdi
movl -0xac(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq -0x88(%rbp), %rdx
leaq -0xa0(%rbp), %rcx
callq 0x6720
cmpq $0x0, %rax
jne 0x64db
movq $0x0, -0x8(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x6670
movq -0x100(%rbp), %rax
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rcx
movl -0xac(%rbp), %edx
addq (%rax,%rdx,8), %rcx
movq %rcx, -0x70(%rbp)
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0xac(%rbp), %edx
subq (%rax,%rdx,8), %rcx
movq -0x70(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x70(%rbp), %rax
movl $0x1, 0x24(%rax)
movq -0x70(%rbp), %rax
movl $0x1, 0x28(%rax)
movw -0x80(%rbp), %cx
movq -0x70(%rbp), %rax
movw %cx, 0x2c(%rax)
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x63f1
movq $0x0, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x65df
movq -0x100(%rbp), %rax
movq -0x108(%rbp), %rcx
imulq $0x38, -0xb8(%rbp), %rdx
addq %rdx, %rcx
movq %rcx, -0x110(%rbp)
movq -0x30(%rbp), %rcx
movq 0x18(%rcx), %rsi
movq -0xb8(%rbp), %rcx
addq (%rax,%rcx,8), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x6810
movq -0x110(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
movl $0x38, %edx
callq 0x1140
movq -0xb8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb8(%rbp)
jmp 0x6565
movq -0x108(%rbp), %rdi
movl -0x4c(%rbp), %eax
movl %eax, %esi
movq -0x38(%rbp), %rdx
movl $0x4, %ecx
callq 0x5840
movq %rax, -0x40(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
cmpq $0x40, %rax
jae 0x661c
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x118(%rbp)
jmp 0x662a
movl $0x40, %eax
movq %rax, -0x118(%rbp)
jmp 0x662a
movq -0x118(%rbp), %rax
movl %eax, -0x4c(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x40(%rbp)
movb %al, -0x119(%rbp)
je 0x6650
cmpl $0x0, -0x44(%rbp)
setne %al
movb %al, -0x119(%rbp)
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x62a5
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x8c(%rbp)
movq -0x58(%rbp), %rax
movq %rax, %rsp
movq -0x8(%rbp), %rax
movq %rbp, %rsp
popq %rbp
retq