// File: /workspace/github_cpp_makefile_star2_O2/UBOdin[P]jitd-cpp/src/cog_tester.cpp
// Function: cog_test(std::istream&)
void cog_test(istream &input)
{
  stack<CogHandle<Record> > stack;
  string line;
  
  while(getline(input, line)){
    istringstream toks(line);
    string op;
    
    toks >> op;
    
    ///////////////// COG LOADERS /////////////////
    if(string("array") == op){
      string fill;
      toks >> fill;
      
      if(string("random") == fill) {
        int len, max;
        toks >> len >> max;
        stack.push(build_random_array(len,max));        
      } else if(string("explicit") == fill) {
        stack.push(array_for_buffer(load_buffer(toks)));
      } else {
        cerr << "Invalid ArrayCog Fill Mode: " << fill << endl;
        exit(-1);
      }
      
    } else if(string("concat") == op) {
      CogHandle<Record> a = stack.top(); stack.pop();
      CogHandle<Record> b = stack.top(); stack.pop();
      
      stack.push(CogHandle<Record>(new CogHandleBase<Record>(CogPtr<Record>(
                    new ConcatCog<Record>(a, b)))));
      
    } else if(string("btree") == op) {
      Record sep;
      toks >> sep.key;
      sep.value = NULL;
      
      CogHandle<Record> b = stack.top(); stack.pop();
      CogHandle<Record> a = stack.top(); stack.pop();

      stack.push(CogHandle<Record>(new CogHandleBase<Record>(CogPtr<Record>(
                    new BTreeCog<Record>(a, b, sep)))));
    
    ///////////////// SIMPLE QUERIES /////////////////
    } else if(string("size") == op) {
      cout << "Size: " << stack.top()->size() << " records" << endl; 
    } else if(string("dump") == op) {
      cout << "gROOT" << endl;
      stack.top()->printDebug(1);
    } else if(string("scan") == op) {
      CogHandle<Record> root = stack.top();
      Iterator<Record> iter = root->iterator();
      int row = 1;
      cout << "---------------" << endl;
      while(!iter->atEnd()){
        cout << row << " -> " << iter->get()->key << endl;
        iter->next();
        row++;
      }
      cout << "---------------" << endl;
    } else if(string("time_scan") == op) {
      CogHandle<Record> root = stack.top();
      timeval start, end;
      gettimeofday(&start, NULL);
      Iterator<Record> iter = root->iterator();
      int row = 1;
      while(!iter->atEnd()){ iter->next(); row++; }
      gettimeofday(&end, NULL);
      float totalTime = 
        (end.tv_sec - start.tv_sec) * 1000000.0 +
        (end.tv_usec - start.tv_usec);
      cout << "---------------" << endl;
      cout << "Records Scanned: " << (row-1) << endl;
      cout << "Time Taken: " << totalTime << " us" << endl;
      if(row > 1){
        cout << "Time/Record: " << totalTime/(row-1) << " us" << endl;
      }
      cout << "---------------" << endl;
      
    ///////////////// OOOPS /////////////////
    } else {
      cerr << "Invalid Test Operation: " << op << endl;
      exit(-1);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
movq %rdi, -0x108(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x5830
leaq -0x188(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x318(%rbp), %r14
leaq -0x90(%rbp), %r13
movq -0x108(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x4050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x54fe
movq %r14, %rdi
leaq -0x198(%rbp), %rsi
pushq $0x8
popq %rdx
callq 0x43a0
leaq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
andq $0x0, -0xa8(%rbp)
movb $0x0, -0xa0(%rbp)
movq %r14, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x42e0
movq %r13, %rdi
leaq 0x9384(%rip), %rsi      # 0xe020
leaq -0x50(%rbp), %rdx
callq 0x40d0
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5850
movl %eax, %ebx
movq %r13, %rdi
callq 0x4110
testb %bl, %bl
je 0x4d5e
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
andq $0x0, -0x88(%rbp)
movb $0x0, -0x80(%rbp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x42e0
leaq -0x50(%rbp), %r15
movq %r15, %rdi
leaq 0x9330(%rip), %rsi      # 0xe026
leaq -0x60(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r13, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x5082
movq %r14, %rdi
leaq -0x60(%rbp), %rsi
callq 0x4160
movq %rax, %rdi
leaq -0x70(%rbp), %rsi
callq 0x4160
movl -0x60(%rbp), %esi
movl -0x70(%rbp), %edx
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x4a90
leaq -0x100(%rbp), %rdi
movq %rbx, %rsi
callq 0x6f50
leaq -0x48(%rbp), %rdi
jmp 0x50ee
movq %r13, %rdi
leaq 0x92eb(%rip), %rsi      # 0xe053
leaq -0x50(%rbp), %rdx
callq 0x40d0
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5850
movl %eax, %ebx
movq %r13, %rdi
callq 0x4110
testb %bl, %bl
je 0x4edf
movq -0xd0(%rbp), %rsi
cmpq -0xc8(%rbp), %rsi
jne 0x4db5
movq -0xb8(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x10, %rsi
movq %r13, %rdi
callq 0x5aa2
leaq -0x100(%rbp), %rbx
movq %rbx, %rdi
callq 0x71d8
movq -0xd0(%rbp), %rsi
cmpq -0xc8(%rbp), %rsi
jne 0x4df3
movq -0xb8(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x10, %rsi
leaq -0x50(%rbp), %rdi
callq 0x5aa2
movq %rbx, %rdi
callq 0x71d8
pushq $0x10
popq %rdi
callq 0x4270
movq %rax, -0x30(%rbp)
movq %r14, %r15
pushq $0x30
popq %rdi
callq 0x4270
movq %rax, %rbx
leaq -0x158(%rbp), %r14
movq %r14, %rdi
movq %r13, %r12
movq %r13, %rsi
callq 0x5aa2
leaq -0x148(%rbp), %r13
movq %r13, %rdi
leaq -0x50(%rbp), %rsi
callq 0x5aa2
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x5874
leaq -0x168(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7768
movq -0x30(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x6510
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x6528
movq %r15, %r14
leaq -0x100(%rbp), %rdi
movq %rbx, %rsi
callq 0x6f50
movq %r12, %r13
leaq -0x58(%rbp), %rdi
callq 0x59d4
leaq -0x160(%rbp), %rdi
callq 0x59d4
leaq -0x140(%rbp), %rdi
callq 0x59d4
leaq -0x150(%rbp), %rdi
callq 0x59d4
leaq -0x48(%rbp), %rdi
callq 0x59d4
leaq -0x88(%rbp), %rdi
jmp 0x507b
movq %r13, %rdi
leaq 0x9171(%rip), %rsi      # 0xe05a
leaq -0x50(%rbp), %rdx
callq 0x40d0
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5850
movl %eax, %ebx
movq %r13, %rdi
callq 0x4110
testb %bl, %bl
je 0x5114
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x4290
andq $0x0, -0x88(%rbp)
movq -0xd0(%rbp), %rsi
cmpq -0xc8(%rbp), %rsi
jne 0x4f55
movq -0xb8(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x10, %rsi
leaq -0x50(%rbp), %rdi
callq 0x5aa2
leaq -0x100(%rbp), %rbx
movq %rbx, %rdi
callq 0x71d8
movq -0xd0(%rbp), %rsi
cmpq -0xc8(%rbp), %rsi
jne 0x4f94
movq -0xb8(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x10, %rsi
leaq -0x60(%rbp), %rdi
callq 0x5aa2
movq %rbx, %rdi
callq 0x71d8
pushq $0x10
popq %rdi
callq 0x4270
movq %rax, -0x30(%rbp)
pushq $0x40
popq %rdi
callq 0x4270
movq %rax, %rbx
leaq -0x128(%rbp), %r15
movq %r15, %rdi
leaq -0x60(%rbp), %rsi
callq 0x5aa2
leaq -0x118(%rbp), %r12
movq %r12, %rdi
leaq -0x50(%rbp), %rsi
callq 0x5aa2
movq -0x90(%rbp), %rcx
movq -0x88(%rbp), %r8
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x58ac
leaq -0x138(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7db8
movq -0x30(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x6510
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6528
leaq -0x100(%rbp), %rdi
movq %rbx, %rsi
callq 0x6f50
leaq -0x68(%rbp), %rdi
callq 0x59d4
leaq -0x130(%rbp), %rdi
callq 0x59d4
leaq -0x110(%rbp), %rdi
callq 0x59d4
leaq -0x120(%rbp), %rdi
callq 0x59d4
leaq -0x58(%rbp), %rdi
callq 0x59d4
leaq -0x48(%rbp), %rdi
callq 0x59d4
jmp 0x50fb
movq %r15, %rdi
leaq 0x8fa1(%rip), %rsi      # 0xe02d
leaq -0x60(%rbp), %rdx
callq 0x40d0
movq %r15, %rdi
movq %r13, %rsi
callq 0x5850
movl %eax, %ebx
movq %r15, %rdi
callq 0x4110
testb %bl, %bl
je 0x5528
leaq -0x178(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x490c
movq %r15, %rdi
movq %rbx, %rsi
callq 0x499a
leaq -0x100(%rbp), %rdi
movq %r15, %rsi
callq 0x6f50
leaq -0x48(%rbp), %rdi
callq 0x59d4
leaq -0x170(%rbp), %rdi
callq 0x59d4
movq %r13, %rdi
callq 0x4110
leaq -0xb0(%rbp), %rdi
callq 0x4110
movq %r14, %rdi
callq 0x4130
jmp 0x4c2f
movq %r13, %rdi
leaq 0x8f42(%rip), %rsi      # 0xe060
leaq -0x50(%rbp), %rdx
callq 0x40d0
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5850
movl %eax, %ebx
movq %r13, %rdi
callq 0x4110
testb %bl, %bl
je 0x51ac
movq 0x10e7d(%rip), %rdi     # 0x15fc8
leaq 0x8f13(%rip), %rsi      # 0xe065
callq 0x4260
movq %rax, %r12
movq -0xd0(%rbp), %rax
cmpq -0xc8(%rbp), %rax
jne 0x517d
movq -0xb8(%rbp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x10(%rax), %rdi
callq 0x58ee
movq %r12, %rdi
movl %eax, %esi
callq 0x43d0
movq %rax, %rdi
leaq 0x8ed2(%rip), %rsi      # 0xe06c
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x50fb
movq %r13, %rdi
leaq 0x8ebf(%rip), %rsi      # 0xe075
leaq -0x50(%rbp), %rdx
callq 0x40d0
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5850
movl %eax, %ebx
movq %r13, %rdi
callq 0x4110
testb %bl, %bl
je 0x522b
movq 0x10de5(%rip), %rdi     # 0x15fc8
leaq 0x8e90(%rip), %rsi      # 0xe07a
callq 0x4260
movq %rax, %rdi
callq 0x4140
movq -0xd0(%rbp), %rax
cmpq -0xc8(%rbp), %rax
jne 0x521a
movq -0xb8(%rbp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x10(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x5938
jmp 0x50fb
movq %r13, %rdi
leaq 0x8e60(%rip), %rsi      # 0xe095
leaq -0x50(%rbp), %rdx
callq 0x40d0
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5850
movl %eax, %ebx
movq %r13, %rdi
callq 0x4110
testb %bl, %bl
je 0x531b
movq -0xd0(%rbp), %rsi
cmpq -0xc8(%rbp), %rsi
jne 0x5282
movq -0xb8(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x10, %rsi
movq %r13, %rdi
callq 0x5aa2
movq -0x90(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x5986
movq 0x10d23(%rip), %rdi     # 0x15fc8
leaq 0x8dd4(%rip), %rsi      # 0xe080
callq 0x4260
movq %rax, %rdi
callq 0x4140
pushq $0x1
popq %r12
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb %al, %al
jne 0x54de
movq 0x10cf2(%rip), %rdi     # 0x15fc8
movl %r12d, %esi
callq 0x43d0
movq %rax, %rdi
leaq 0x9455(%rip), %rsi      # 0xe73d
callq 0x4260
movq %rax, %rbx
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq (%rax), %rsi
movq %rbx, %rdi
callq 0x4240
movq %rax, %rdi
callq 0x4140
movq -0x50(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
incl %r12d
jmp 0x52bd
movq %r13, %rdi
leaq 0x8d6b(%rip), %rsi      # 0xe090
leaq -0x50(%rbp), %rdx
callq 0x40d0
movq %r13, %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5850
movl %eax, %ebx
movq %r13, %rdi
callq 0x4110
testb %bl, %bl
je 0x555a
movq -0xd0(%rbp), %rsi
cmpq -0xc8(%rbp), %rsi
jne 0x5372
movq -0xb8(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x10, %rsi
movq %r13, %rdi
callq 0x5aa2
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq -0x90(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x5986
pushq $0x1
popq %rax
movl %eax, %ebx
movq -0x70(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb %al, %al
jne 0x53ba
movq -0x70(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebx
jmp 0x539e
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
callq 0x4370
movq -0x60(%rbp), %rax
subq -0x50(%rbp), %rax
cvtsi2sd %rax, %xmm0
movq -0x58(%rbp), %r12
subq -0x48(%rbp), %r12
mulsd 0x8c26(%rip), %xmm0     # 0xe008
movsd %xmm0, -0x30(%rbp)
movq 0x10bda(%rip), %rdi     # 0x15fc8
leaq 0x8c8b(%rip), %rsi      # 0xe080
callq 0x4260
movq %rax, %rdi
callq 0x4140
movq 0x10bbf(%rip), %rdi     # 0x15fc8
leaq 0x8c8a(%rip), %rsi      # 0xe09a
callq 0x4260
leal -0x1(%rbx), %r15d
movq %rax, %rdi
movl %r15d, %esi
callq 0x43d0
movq %rax, %rdi
callq 0x4140
movq 0x10b95(%rip), %rdi     # 0x15fc8
leaq 0x8c72(%rip), %rsi      # 0xe0ac
callq 0x4260
cvtsi2sd %r12, %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movq %rax, %rdi
movss %xmm0, -0x30(%rbp)
callq 0x41b0
movq %rax, %rdi
leaq 0x8c51(%rip), %rsi      # 0xe0b9
callq 0x4260
movq %rax, %rdi
callq 0x4140
cmpl $0x2, %ebx
jb 0x54ba
movq 0x10b47(%rip), %rdi     # 0x15fc8
leaq 0x8c35(%rip), %rsi      # 0xe0bd
callq 0x4260
cvtsi2ss %r15d, %xmm1
movss -0x30(%rbp), %xmm0
divss %xmm1, %xmm0
movq %rax, %rdi
callq 0x41b0
movq %rax, %rdi
leaq 0x8c0c(%rip), %rsi      # 0xe0b9
callq 0x4260
movq %rax, %rdi
callq 0x4140
movq 0x10b07(%rip), %rdi     # 0x15fc8
leaq 0x8bb8(%rip), %rsi      # 0xe080
callq 0x4260
movq %rax, %rdi
callq 0x4140
leaq -0x68(%rbp), %rdi
jmp 0x4ece
movq 0x10ae3(%rip), %rdi     # 0x15fc8
leaq 0x8b94(%rip), %rsi      # 0xe080
callq 0x4260
movq %rax, %rdi
callq 0x4140
jmp 0x4eca
leaq -0x198(%rbp), %rdi
callq 0x4110
leaq -0x100(%rbp), %rdi
callq 0x5aba
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10ac1(%rip), %rdi     # 0x15ff0
leaq 0x8b00(%rip), %rsi      # 0xe036
callq 0x4260
leaq -0x90(%rbp), %rsi
movq %rax, %rdi
callq 0x4210
movq %rax, %rdi
callq 0x4140
pushq $-0x1
popq %rdi
callq 0x42d0
movq 0x10a8f(%rip), %rdi     # 0x15ff0
leaq 0x8b63(%rip), %rsi      # 0xe0cb
callq 0x4260
leaq -0xb0(%rbp), %rsi
movq %rax, %rdi
callq 0x4210
movq %rax, %rdi
callq 0x4140
jmp 0x5552
jmp 0x56e3
jmp 0x56e3
jmp 0x5592
movq %rax, %rbx
jmp 0x56f6
jmp 0x56e3
jmp 0x56ea
jmp 0x56e3
jmp 0x56e3
movq %rax, %rbx
movb $0x1, %r14b
jmp 0x55e5
movq %rax, %rbx
jmp 0x5602
jmp 0x56e3
movq %rax, %rbx
jmp 0x560e
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x59d4
jmp 0x55d6
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x59d4
xorl %r14d, %r14d
leaq -0x110(%rbp), %rdi
callq 0x59d4
leaq -0x120(%rbp), %rdi
callq 0x59d4
testb %r14b, %r14b
je 0x560e
pushq $0x10
popq %rsi
movq -0x30(%rbp), %rdi
callq 0x4280
leaq -0x58(%rbp), %rdi
callq 0x59d4
leaq -0x48(%rbp), %rdi
jmp 0x56fd
jmp 0x56d1
jmp 0x56be
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x59d4
jmp 0x5679
jmp 0x56be
jmp 0x56be
movq %rax, %rbx
jmp 0x5668
jmp 0x56ea
movq %rax, %rbx
movb $0x1, %r14b
jmp 0x5688
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
jmp 0x566f
jmp 0x56be
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x59d4
leaq -0x170(%rbp), %rdi
callq 0x59d4
jmp 0x56c1
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
callq 0x59d4
xorl %r14d, %r14d
leaq -0x140(%rbp), %rdi
callq 0x59d4
leaq -0x150(%rbp), %rdi
callq 0x59d4
testb %r14b, %r14b
jne 0x56aa
jmp 0x56ed
movq %rax, %rbx
pushq $0x10
popq %rsi
movq -0x30(%rbp), %rdi
callq 0x4280
jmp 0x56ed
jmp 0x56e3
jmp 0x56be
jmp 0x56be
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x4110
jmp 0x5702
jmp 0x56e3
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x56f1
jmp 0x56de
jmp 0x56e3
movq %rax, %rbx
jmp 0x571a
movq %rax, %rbx
jmp 0x5702
jmp 0x56ea
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x59d4
leaq -0x88(%rbp), %rdi
callq 0x59d4
leaq -0xb0(%rbp), %rdi
callq 0x4110
leaq -0x318(%rbp), %rdi
callq 0x4130
leaq -0x198(%rbp), %rdi
callq 0x4110
leaq -0x100(%rbp), %rdi
callq 0x5aba
movq %rbx, %rdi
callq 0x43e0