// File: /workspace/github_cpp_makefile_star2_O2/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 0x43ec
pushq $0x1
popq %rbp
cmpl $0x1, %edi
jne 0x44ff
pushq $0x1
popq %rbx
movq 0x8c43(%rip), %r14      # 0xcfc8
leaq 0x3e4a(%rip), %r15      # 0x81d6
pushq $0x64
popq %r12
leaq 0x3e4f(%rip), %r13      # 0x81e6
cmpq $0xa, %rbx
je 0x4786
movq %r14, %rdi
movq %r15, %rsi
callq 0x21e0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2150
movq %rax, %rdi
callq 0x2110
movl $0x1312d00, %edi        # imm = 0x1312D00
movl $0xc350, %esi           # imm = 0xC350
movq %r12, %rdx
movq %rbx, %rcx
callq 0x36df
movq %r14, %rdi
movq %r13, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x2110
incq %rbx
jmp 0x4397
movq %rsi, %r14
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0xd8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %edx, %edx
movb %dl, (%rax)
movb %dl, (%rcx)
pushq $0x1
popq %rbx
pushq $-0x1
popq %rax
movl %eax, 0x4(%rsp)
leaq 0x8(%rsp), %r15
leaq 0x30(%rsp), %r12
cmpl $0x7, %ebx
jge 0x4531
movslq %ebx, %r13
movq (%r14,%r13,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x4c2c
movq %r15, %rdi
leaq 0x3d1d(%rip), %rsi      # 0x816d
callq 0x4cf1
movl %eax, %ebp
movq %r15, %rdi
callq 0x2100
testb %bpl, %bpl
je 0x4478
movq 0x8(%r14,%r13,8), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x2390
jmp 0x44b7
movq (%r14,%r13,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x4c2c
movq %r15, %rdi
leaq 0x3ce7(%rip), %rsi      # 0x8178
callq 0x4cf1
movl %eax, %ebp
movq %r15, %rdi
callq 0x2100
testb %bpl, %bpl
je 0x44c0
movq 0x8(%r14,%r13,8), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x2390
incl %ebx
incl %ebx
jmp 0x442b
movq (%r14,%r13,8), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x4c2c
movq %r15, %rdi
leaq 0x3ca9(%rip), %rsi      # 0x8182
callq 0x4cf1
movl %eax, %ebp
movq %r15, %rdi
callq 0x2100
testb %bpl, %bpl
je 0x44b9
incl %ebx
movq 0x8(%r14,%r13,8), %rdi
callq 0x22c0
movl %eax, 0x4(%rsp)
jmp 0x44b9
leaq 0x3bb0(%rip), %rsi      # 0x80b6
leaq 0x8(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x4c2c
leaq 0x8(%rsp), %rdi
callq 0x431e
leaq 0x8(%rsp), %rdi
callq 0x2100
jmp 0x4788
cmpq $0x0, 0xb0(%rsp)
je 0x45c4
cmpq $0x0, 0xd0(%rsp)
je 0x45c4
cmpl $0x0, 0x4(%rsp)
js 0x45c4
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
andq $0x0, 0xa0(%rsp)
movaps %xmm0, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x4cfe
leaq 0x8(%rsp), %rdi
callq 0x4d0e
movl %eax, %ebx
testb %al, %al
je 0x45f8
leaq 0x8(%rsp), %r14
leaq 0x90(%rsp), %r15
leaq 0x70(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x4dca
testb %al, %al
je 0x462a
movq %r12, %rdi
movq %r15, %rsi
callq 0x4f2c
jmp 0x45a8
leaq 0x3bc3(%rip), %rsi      # 0x818e
leaq 0x8(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x4c2c
leaq 0x8(%rsp), %rdi
callq 0x431e
leaq 0x8(%rsp), %rdi
callq 0x2100
pushq $0x1
popq %rbp
xorl %ebx, %ebx
jmp 0x4768
leaq 0x3bbd(%rip), %rsi      # 0x81bc
leaq 0x30(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x4d54
leaq 0x30(%rsp), %rdi
callq 0x431e
leaq 0x30(%rsp), %rdi
callq 0x2100
pushq $0x1
popq %rbp
jmp 0x462c
xorl %ebp, %ebp
leaq 0x8(%rsp), %rdi
callq 0x4f58
testb %bl, %bl
je 0x4698
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x4cfe
leaq 0x8(%rsp), %rdi
callq 0x4d0e
movl %eax, %ebx
testb %al, %al
je 0x469f
leaq 0x8(%rsp), %r14
leaq 0x90(%rsp), %r15
leaq 0x50(%rsp), %r12
movq %r14, %rdi
movq %r15, %rsi
callq 0x4dca
testb %al, %al
je 0x46cf
movq %r12, %rdi
movq %r15, %rsi
callq 0x4f2c
jmp 0x467c
xorl %ebx, %ebx
jmp 0x4751
leaq 0x3b16(%rip), %rsi      # 0x81bc
leaq 0x30(%rsp), %rdi
leaq 0xc8(%rsp), %rdx
callq 0x4d54
leaq 0x30(%rsp), %rdi
callq 0x431e
leaq 0x30(%rsp), %rdi
callq 0x2100
pushq $0x1
popq %rbp
leaq 0x8(%rsp), %rdi
callq 0x4f58
testb %bl, %bl
je 0x4745
movl 0x4(%rsp), %edx
movb $0x1, %bl
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2962
jmp 0x4747
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x4805
movq %rbx, %rdi
callq 0x20d0
movq %rax, %rbx
movq 0x88d6(%rip), %rdi      # 0xcfe8
leaq 0x3ab1(%rip), %rsi      # 0x81ca
callq 0x21e0
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x2110
callq 0x2340
pushq $0x1
popq %rbp
xorl %ebx, %ebx
leaq 0x50(%rsp), %rdi
callq 0x4c68
leaq 0x70(%rsp), %rdi
callq 0x4c68
leaq 0x90(%rsp), %rdi
callq 0x620e
leaq 0xc8(%rsp), %rdi
callq 0x2100
leaq 0xa8(%rsp), %rdi
callq 0x2100
testb %bl, %bl
je 0x4788
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x47bb
movq %rax, %rbx
callq 0x2340
jmp 0x4805
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2100
jmp 0x47fb
jmp 0x47f8
jmp 0x47f8
movq %rax, %rbx
jmp 0x4805
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2100
jmp 0x4816
jmp 0x4813
jmp 0x4813
movq %rax, %rbx
jmp 0x4820
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2100
jmp 0x4840
jmp 0x483d
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x4855
movq %rax, %rbx
jmp 0x485a
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4f58
leaq 0x50(%rsp), %rdi
callq 0x4c68
jmp 0x4820
jmp 0x483d
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x4f58
leaq 0x70(%rsp), %rdi
callq 0x4c68
leaq 0x90(%rsp), %rdi
callq 0x620e
jmp 0x4840
jmp 0x483d
jmp 0x483d
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x2100
leaq 0xa8(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2360
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x485a
movq %rbx, %rdi
callq 0x20d0
movq %rax, %rbx
movq 0x876c(%rip), %rdi      # 0xcfe8
leaq 0x3947(%rip), %rsi      # 0x81ca
callq 0x21e0
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x21e0
movq %rax, %rdi
callq 0x2110
callq 0x2340
jmp 0x4788
movq %rax, %rbx
callq 0x2340
jmp 0x485a
movq %rax, %rdi
callq 0x4f72
nop