// File: /workspace/github_c_makefile_star2_O0/jflatow[P]jfdb/test/trie.c
// Function: main
int main(int argc, char **argv) {
  size_t O = argc > 1 ? atoi(argv[1]) : 0;
  size_t B = argc > 2 ? atoi(argv[2]) : 1;
  JFT_Buffer
    *scratch = JFT_membuf(),
    *outputW = JFT_membuf(),
    *outputX = JFT_membuf(),
    *outputY = JFT_membuf();
  if (scratch == NULL || outputX == NULL || outputY == NULL)
    return ENoMem;

  JFT_Word *b = malloc(B * sizeof(JFT_Word));
  JFT_Leaf v = ((JFT_Leaf) {.size = B, .data = b});
  if (B > 0)
    b[0] = 42;
  const JFT_Stem k[] = {
    JFTK("hello world"),
    JFTK("i1"),
    JFTK("i2"),
    JFTK("index3"),
    JFTK("index3"),
    JFTK("aliens"),
    JFTK("attack!!"),
    JFTK("keyhole")
  };
  JFT *w = JFT_atom(k + 0, &v, k + 1, 7, scratch, outputW);
  JFT *x = JFT_atom(k + 1, &v, k + 1, 7, scratch, outputX);
  JFT *y = JFT_atom(k + 2, &v, k + 2, 6, scratch, outputY);

  JFT_Cursor cursors[] = {
    JFT_cursor(w),
    JFT_cursor(x),
    JFT_cursor(y)
  };
  JFT *z = JFT_cursor_merge_new(cursors, 3, scratch, 0);
  if (z) {
    printf("scratch: %zu\n", scratch->size);
    print_node(z + O);
    print_trie(z + O);

    JFT_Cursor c = JFT_cursor(z + O);
    JFT_Stem q = (JFT_Stem) {.data = malloc(JFT_KEY_LIMIT)};
    JFT_Keys ks = JFT_keys(&c, &q, Reverse);
    uint8_t keyData[JFT_KEY_LIMIT];
    print_stem("", JFT_key(c.node, keyData));
    while (JFT_keys_next(&ks))
      print_stem(" -> ", *ks.stem);
    free(q.data);
  } else {
    printf("Failed to splice atom\n");
  }

  free(b);
  JFT_membuf_free(scratch);
  JFT_membuf_free(outputW);
  JFT_membuf_free(outputX);
  JFT_membuf_free(outputY);
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x6a0, %rsp            # imm = 0x6A0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
jle 0x1314
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x11b0
movl %eax, -0x67c(%rbp)
jmp 0x131e
xorl %eax, %eax
movl %eax, -0x67c(%rbp)
jmp 0x131e
movl -0x67c(%rbp), %eax
cltq
movq %rax, -0x18(%rbp)
cmpl $0x2, -0x8(%rbp)
jle 0x1345
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x11b0
movl %eax, -0x680(%rbp)
jmp 0x1352
movl $0x1, %eax
movl %eax, -0x680(%rbp)
jmp 0x1352
movl -0x680(%rbp), %eax
cltq
movq %rax, -0x20(%rbp)
movb $0x0, %al
callq 0x7890
movq %rax, -0x28(%rbp)
movb $0x0, %al
callq 0x7890
movq %rax, -0x30(%rbp)
movb $0x0, %al
callq 0x7890
movq %rax, -0x38(%rbp)
movb $0x0, %al
callq 0x7890
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x139f
cmpq $0x0, -0x38(%rbp)
je 0x139f
cmpq $0x0, -0x40(%rbp)
jne 0x13ab
movl $0x5, -0x4(%rbp)
jmp 0x165e
movq -0x20(%rbp), %rdi
shlq $0x3, %rdi
callq 0x1140
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movl %eax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x20(%rbp)
jbe 0x13dd
movq -0x48(%rbp), %rax
movq $0x2a, (%rax)
leaq -0x120(%rbp), %rdi
leaq 0xb945(%rip), %rsi      # 0xcd30
movl $0xc0, %edx
callq 0x1130
leaq -0x120(%rbp), %rdi
leaq -0x120(%rbp), %rdx
addq $0x18, %rdx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
leaq -0x58(%rbp), %rsi
movl $0x7, %ecx
callq 0x6790
movq %rax, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
addq $0x18, %rdi
leaq -0x120(%rbp), %rdx
addq $0x18, %rdx
movq -0x28(%rbp), %r8
movq -0x38(%rbp), %r9
leaq -0x58(%rbp), %rsi
movl $0x7, %ecx
callq 0x6790
movq %rax, -0x130(%rbp)
leaq -0x120(%rbp), %rdi
addq $0x30, %rdi
leaq -0x120(%rbp), %rdx
addq $0x30, %rdx
movq -0x28(%rbp), %r8
movq -0x40(%rbp), %r9
leaq -0x58(%rbp), %rsi
movl $0x6, %ecx
callq 0x6790
movq %rax, -0x138(%rbp)
movq -0x128(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x1670
leaq -0x1e0(%rbp), %rdi
addq $0x38, %rdi
movq -0x130(%rbp), %rsi
callq 0x1670
leaq -0x1e0(%rbp), %rdi
addq $0x70, %rdi
movq -0x138(%rbp), %rsi
callq 0x1670
leaq -0x1e0(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x3, %esi
xorl %ecx, %ecx
callq 0x5e10
movq %rax, -0x1e8(%rbp)
cmpq $0x0, -0x1e8(%rbp)
je 0x161c
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x7c2b(%rip), %rdi      # 0x9131
movb $0x0, %al
callq 0x10c0
movq -0x1e8(%rbp), %rdi
addq -0x18(%rbp), %rdi
callq 0x16c0
movq -0x1e8(%rbp), %rdi
addq -0x18(%rbp), %rdi
callq 0x17f0
movq -0x1e8(%rbp), %rsi
addq -0x18(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x1670
movq $0x0, -0x238(%rbp)
movw $0x0, -0x230(%rbp)
movl $0x400, %edi            # imm = 0x400
callq 0x1140
movq %rax, -0x228(%rbp)
leaq -0x258(%rbp), %rdi
leaq -0x220(%rbp), %rsi
leaq -0x238(%rbp), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1910
movq -0x218(%rbp), %rsi
leaq -0x660(%rbp), %rdx
leaq -0x678(%rbp), %rdi
callq 0x1a00
leaq 0x7bb8(%rip), %rdi      # 0x9161
leaq -0x678(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x1970
leaq -0x258(%rbp), %rdi
callq 0x1af0
cmpq $0x0, %rax
je 0x160e
movq -0x250(%rbp), %rax
leaq 0x7b51(%rip), %rdi      # 0x913f
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x1970
jmp 0x15ce
movq -0x228(%rbp), %rdi
callq 0x1030
jmp 0x162a
leaq 0x7b21(%rip), %rdi      # 0x9144
movb $0x0, %al
callq 0x10c0
movq -0x48(%rbp), %rdi
callq 0x1030
movq -0x28(%rbp), %rdi
callq 0x78f0
movq -0x30(%rbp), %rdi
callq 0x78f0
movq -0x38(%rbp), %rdi
callq 0x78f0
movq -0x40(%rbp), %rdi
callq 0x78f0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x6a0, %rsp            # imm = 0x6A0
popq %rbp
retq
nopw (%rax,%rax)