// File: /workspace/github_cpp_makefile_star2_O1/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 0x51e1
cmpl $0x1, %edi
jne 0x5413
movl $0x1, %ebx
movq 0x6e9a(%rip), %r14      # 0xbfc8
leaq 0x30a1(%rip), %r15      # 0x81d6
leaq 0x30aa(%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 0x3e4b
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 0x513c
jmp 0x56c4
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, 0x4(%rsp)  # imm = 0xFFFFFFFF
movl $0x1, %r13d
leaq 0x8(%rsp), %r15
leaq 0x30(%rsp), %r12
movslq %r13d, %rbx
movq (%r14,%rbx,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x5c7e
movq %r15, %rdi
leaq 0x2f32(%rip), %rsi      # 0x816d
callq 0x20a0
movl %eax, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x525e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
testl %ebp, %ebp
je 0x52fa
movq (%r14,%rbx,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x5c7e
movq %r15, %rdi
leaq 0x2ef9(%rip), %rsi      # 0x8178
callq 0x20a0
movl %eax, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x52a2
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
testl %ebp, %ebp
je 0x5323
movq (%r14,%rbx,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x5c7e
movq %r15, %rdi
leaq 0x2ec3(%rip), %rsi      # 0x8182
callq 0x20a0
movl %eax, %ebp
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x52e2
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
testl %ebp, %ebp
jne 0x534d
leal 0x1(%rbx), %r13d
movq 0x8(%r14,%rbx,8), %rdi
callq 0x2300
movl %eax, 0x4(%rsp)
jmp 0x534d
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 0x534a
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 0x521f
movq 0x78(%rsp), %rdx
testq %rdx, %rdx
je 0x545b
cmpq $0x0, 0x58(%rsp)
je 0x545b
cmpl $0x0, 0x4(%rsp)
js 0x545b
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
xorl %eax, %eax
movq %rax, 0xa0(%rsp)
movq %rax, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
movq 0x70(%rsp), %rsi
addq %rsi, %rdx
callq 0x666c
leaq 0x8(%rsp), %rdi
movq $0x0, 0x20(%rdi)
callq 0x5d92
movl %eax, %ebx
testb %al, %al
je 0x54ad
leaq 0x8(%rsp), %r14
leaq 0x90(%rsp), %r15
leaq 0xd0(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x5e72
testb %al, %al
je 0x54ef
movq %r12, %rdi
movq %r15, %rsi
callq 0x600c
jmp 0x53f3
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2c93(%rip), %rdx      # 0x80b6
leaq 0x8(%rsp), %rdi
movq %rdx, %rsi
callq 0x733c
leaq 0x8(%rsp), %rdi
callq 0x5079
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x5451
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
movl $0x1, %ebp
jmp 0x56c6
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x2d1f(%rip), %rsi      # 0x818e
leaq 0x2d45(%rip), %rdx      # 0x81bb
callq 0x733c
leaq 0x8(%rsp), %rdi
callq 0x5079
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x54a1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2230
movl $0x1, %ebp
xorl %ebx, %ebx
jmp 0x5682
leaq 0x2d08(%rip), %rsi      # 0x81bc
leaq 0x30(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x5de9
leaq 0x30(%rsp), %rdi
callq 0x5079
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x54e8
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2230
movl $0x1, %ebp
jmp 0x54f1
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
callq 0x6038
testb %bl, %bl
je 0x557e
xorps %xmm0, %xmm0
movaps %xmm0, 0xb0(%rsp)
movq $0x0, 0xc0(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
callq 0x666c
leaq 0x8(%rsp), %rdi
movq $0x0, 0x20(%rdi)
callq 0x5d92
movl %eax, %ebx
testb %al, %al
je 0x5585
leaq 0x8(%rsp), %r14
leaq 0x90(%rsp), %r15
leaq 0xb0(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x5e72
testb %al, %al
je 0x55c5
movq %r12, %rdi
movq %r15, %rsi
callq 0x600c
jmp 0x5562
xorl %ebx, %ebx
jmp 0x5658
leaq 0x2c30(%rip), %rsi      # 0x81bc
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x5de9
leaq 0x30(%rsp), %rdi
callq 0x5079
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x55c0
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2230
movl $0x1, %ebp
leaq 0x8(%rsp), %rdi
callq 0x6038
testb %bl, %bl
je 0x5649
movl 0x4(%rsp), %edx
movb $0x1, %bl
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x2aef
jmp 0x564b
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x5791
movq %rbx, %rdi
callq 0x2100
movq %rax, %rbx
movq 0x69da(%rip), %rdi      # 0xbfe8
leaq 0x2bb5(%rip), %rsi      # 0x81ca
movl $0xb, %edx
callq 0x2260
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x69b9(%rip), %rdi      # 0xbfe8
movq %rax, %rsi
callq 0x2200
movq %rax, %rdi
callq 0x2120
callq 0x2370
movl $0x1, %ebp
xorl %ebx, %ebx
leaq 0xb0(%rsp), %rdi
callq 0x5cbc
leaq 0xd0(%rsp), %rdi
callq 0x5cbc
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x5682
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x569e
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x56c0
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2230
testb %bl, %bl
je 0x56c6
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5711
movq %rax, %rbx
callq 0x2370
jmp 0x5791
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5787
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x5787
jmp 0x5784
jmp 0x5784
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 0x57ad
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x57e2
movq 0x18(%rsp), %rsi
incq %rsi
jmp 0x57d2
jmp 0x57df
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x5820
movq 0x18(%rsp), %rsi
jmp 0x5818
movq %rax, %rbx
jmp 0x5820
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x6038
leaq 0xb0(%rsp), %rdi
callq 0x5cbc
jmp 0x57ad
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x6038
leaq 0xd0(%rsp), %rdi
callq 0x5cbc
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x57e2
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2230
jmp 0x57e2
jmp 0x57df
jmp 0x57df
jmp 0x57df
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x57fe
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x5820
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x2390
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x5820
movq %rbx, %rdi
callq 0x2100
movq %rax, %rbx
movq 0x67a6(%rip), %rdi      # 0xbfe8
leaq 0x2981(%rip), %rsi      # 0x81ca
movl $0xb, %edx
callq 0x2260
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq 0x6785(%rip), %rdi      # 0xbfe8
movq %rax, %rsi
callq 0x2200
movq %rax, %rdi
callq 0x2120
callq 0x2370
jmp 0x5451
movq %rax, %rbx
callq 0x2370
jmp 0x5820
movq %rax, %rdi
callq 0x606c
nop