// File: /workspace/github_cpp_makefile_star2_O3/lemire[P]fastscancount/benchmark/counters.cpp
// Function: main
int main(int argc, char *argv[]) {
  // A very naive way to process arguments, 
  // but it's ok unless we need to extend it substantially.
  if (argc != 1) {
    if (argc != 7) {
      usage("");
      return EXIT_FAILURE; 
    }
    std::string postings_file, queries_file;
    int threshold = -1;
    for (int i = 1; i < argc; ++i) {
      if (std::string(argv[i]) == "--postings") {
        postings_file = argv[++i];
      } else if (std::string(argv[i]) == "--queries") {
        queries_file = argv[++i];
      } else if (std::string(argv[i]) == "--threshold") {
        threshold = std::atoi(argv[++i]);
      }
    }
    if (postings_file.empty() || queries_file.empty() || threshold < 0) {
      usage("Specify queries, postings, and the threshold!");
      return EXIT_FAILURE; 
    }
    std::vector<uint32_t> tmp; 
    std::vector<std::vector<uint32_t>> data;
    {
      MaropuGapReader drdr(postings_file);
      if (!drdr.open()) {
        usage("Cannot open: " + postings_file);
        return EXIT_FAILURE; 
      }
      while (drdr.loadIntegers(tmp)) {
        data.push_back(tmp);
      }
    }
    std::vector<std::vector<uint32_t>> queries;
    {
      MaropuGapReader qrdr(queries_file);
      if (!qrdr.open()) {
        usage("Cannot open: " + queries_file);
        return EXIT_FAILURE; 
      }
      while (qrdr.loadIntegers(tmp)) {
        queries.push_back(tmp);
      }
    }
              
    try { 
      demo_data(data, queries, threshold);
    } catch (const std::exception& e) {
      std::cerr << "Exception: " << e.what() << std::endl;
      return EXIT_FAILURE;
    }
  } else {
    try {
      // Previous demo with threshold 3
      //demo_random(20000000, 50000, 100, 3);
      for (unsigned k = 1; k < 10; ++k) {
        std::cout << "Demo threshold:" << k << std::endl;
        demo_random(20000000, 50000, 100, k);
        std::cout << "=======================" << std::endl;
      }
    } catch (const std::exception& e) {
      std::cerr << "Exception: " << e.what() << std::endl;
      return EXIT_FAILURE;
    }
  }
  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
cmpl $0x7, %edi
je 0x51fd
cmpl $0x1, %edi
jne 0x5422
movl $0x1, %ebx
movq 0x6e7e(%rip), %r14      # 0xbfc8
leaq 0x3085(%rip), %r15      # 0x81d6
leaq 0x308e(%rip), %r12      # 0x81e6
movl $0xf, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2260
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2160
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
movl $0x1312d00, %edi        # imm = 0x1312D00
movl $0xc350, %esi           # imm = 0xC350
movl $0x64, %edx
movq %rbx, %rcx
callq 0x3e78
movl $0x17, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2260
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2170
incq %rbx
cmpq $0xa, %rbx
jne 0x5158
jmp 0x566f
movq %rsi, %r14
leaq 0x80(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
movl $0x1, %r13d
movq %rsp, %r15
leaq 0x30(%rsp), %r12
movslq %r13d, %rbx
movq (%r14,%rbx,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x5c86
movq %r15, %rdi
leaq 0x2f18(%rip), %rsi      # 0x816d
callq 0x20a0
movl %eax, %ebp
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x5277
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2230
testl %ebp, %ebp
je 0x5311
movq (%r14,%rbx,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x5c86
movq %r15, %rdi
leaq 0x2ee0(%rip), %rsi      # 0x8178
callq 0x20a0
movl %eax, %ebp
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x52ba
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2230
testl %ebp, %ebp
je 0x533a
movq (%r14,%rbx,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x5c86
movq %r15, %rdi
leaq 0x2eab(%rip), %rsi      # 0x8182
callq 0x20a0
movl %eax, %ebp
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x52f9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2230
testl %ebp, %ebp
jne 0x5364
leal 0x1(%rbx), %r13d
movq 0x8(%r14,%rbx,8), %rdi
callq 0x2300
movl %eax, 0x2c(%rsp)
jmp 0x5364
movq 0x8(%r14,%rbx,8), %rbp
movq 0x78(%rsp), %rbx
movq %rbp, %rdi
callq 0x2110
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %rbp, %rcx
movq %rax, %r8
callq 0x22f0
jmp 0x5361
movq 0x8(%r14,%rbx,8), %rbx
movq 0x58(%rsp), %rbp
movq %rbx, %rdi
callq 0x2110
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x22f0
incl %r13d
leal 0x1(%r13), %eax
cmpl $0x6, %r13d
movl %eax, %r13d
jl 0x5239
movq 0x78(%rsp), %rdx
testq %rdx, %rdx
je 0x5465
cmpq $0x0, 0x58(%rsp)
je 0x5465
cmpl $0x0, 0x2c(%rsp)
js 0x5465
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
xorl %eax, %eax
movq %rax, 0xa0(%rsp)
movq %rax, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
movq 0x70(%rsp), %rsi
addq %rsi, %rdx
callq 0x6624
movq %rsp, %rdi
movq $0x0, 0x20(%rdi)
callq 0x5d96
testb %al, %al
je 0x54b2
movq %rsp, %rbx
leaq 0x90(%rsp), %r14
leaq 0xd0(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5e76
testb %al, %al
je 0x5501
movq %r15, %rdi
movq %r14, %rsi
callq 0x600e
jmp 0x5402
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2c84(%rip), %rdx      # 0x80b6
movq %rsp, %rdi
movq %rdx, %rsi
callq 0x72ac
movq %rsp, %rdi
callq 0x5095
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x545b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2230
movl $0x1, %ebx
jmp 0x5671
movq %rsp, %rdi
leaq 0x10(%rsp), %rax
movq %rax, (%rdi)
leaq 0x2d17(%rip), %rsi      # 0x818e
leaq 0x2d3d(%rip), %rdx      # 0x81bb
callq 0x72ac
movq %rsp, %rdi
callq 0x5095
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x54a6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2230
movl $0x1, %ebx
xorl %ebp, %ebp
jmp 0x562c
leaq 0x2d03(%rip), %rsi      # 0x81bc
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x5ded
leaq 0x30(%rsp), %rdi
callq 0x5095
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x54ed
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2230
movq %rsp, %rdi
callq 0x603a
movl $0x1, %ebx
xorl %ebp, %ebp
jmp 0x5602
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x603a
xorps %xmm0, %xmm0
movaps %xmm0, 0xb0(%rsp)
movq $0x0, 0xc0(%rsp)
leaq 0x10(%rsp), %rax
movq %rax, (%rbx)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0x6624
movq %rsp, %rdi
movq $0x0, 0x20(%rdi)
callq 0x5d96
testb %al, %al
je 0x5583
movq %rsp, %rbx
leaq 0x90(%rsp), %r14
leaq 0xb0(%rsp), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5e76
testb %al, %al
je 0x55cf
movq %r15, %rdi
movq %r14, %rsi
callq 0x600e
jmp 0x5567
leaq 0x2c32(%rip), %rsi      # 0x81bc
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x5ded
leaq 0x30(%rsp), %rdi
callq 0x5095
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x55be
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2230
movq %rsp, %rdi
callq 0x603a
movl $0x1, %ebx
xorl %ebp, %ebp
jmp 0x55f5
movq %rsp, %rdi
callq 0x603a
movl 0x2c(%rsp), %edx
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x2b0f
xorl %ebx, %ebx
movb $0x1, %bpl
leaq 0xb0(%rsp), %rdi
callq 0x5cc4
leaq 0xd0(%rsp), %rdi
callq 0x5cc4
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x562c
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x5648
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x566a
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2230
testb %bpl, %bpl
je 0x5671
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x5791
movq %rbx, %rdi
callq 0x2100
movq %rax, %rbx
movq 0x6945(%rip), %rdi      # 0xbfe8
leaq 0x2b20(%rip), %rsi      # 0x81ca
movl $0xb, %edx
callq 0x2260
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x6924(%rip), %rdi      # 0xbfe8
movq %rax, %rsi
callq 0x2200
movq %rax, %rdi
callq 0x2120
callq 0x2370
jmp 0x55c6
jmp 0x5715
movq %rax, %rbx
callq 0x2370
jmp 0x5791
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5789
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x5789
jmp 0x5786
jmp 0x5786
movq %rax, %rbx
jmp 0x5791
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x57a3
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x57a3
jmp 0x57a0
jmp 0x57a0
movq %rax, %rbx
jmp 0x57ab
movq %rax, %rbx
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x57e0
movq 0x10(%rsp), %rsi
incq %rsi
jmp 0x57d0
jmp 0x57dd
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x581e
movq 0x10(%rsp), %rsi
jmp 0x5816
movq %rax, %rbx
jmp 0x581e
movq %rax, %rbx
movq %rsp, %rdi
callq 0x603a
leaq 0xb0(%rsp), %rdi
callq 0x5cc4
jmp 0x57ab
movq %rax, %rbx
movq %rsp, %rdi
callq 0x603a
leaq 0xd0(%rsp), %rdi
callq 0x5cc4
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x57e0
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
jmp 0x57e0
jmp 0x57dd
jmp 0x57dd
jmp 0x57dd
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x57fc
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x581e
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x2390
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x581e
movq %rbx, %rdi
callq 0x2100
movq %rax, %rbx
movq 0x67a8(%rip), %rdi      # 0xbfe8
leaq 0x2983(%rip), %rsi      # 0x81ca
movl $0xb, %edx
callq 0x2260
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x6787(%rip), %rdi      # 0xbfe8
movq %rax, %rsi
callq 0x2200
movq %rax, %rdi
callq 0x2120
callq 0x2370
jmp 0x545b
movq %rax, %rbx
callq 0x2370
jmp 0x581e
movq %rax, %rdi
callq 0x606e
nop