// File: lemire[P]fastscancount/benchmark/counters.cpp
// Function: scancount(std::vector<std::vector<unsigned int, std::allocator<unsigned int>> const*, std::allocator<std::vector<unsigned int, std::allocator<unsigned int>> const*>> const&, std::vector<unsigned int, std::allocator<unsigned int>>&, unsigned long)
void scancount(const std::vector<const std::vector<uint32_t>*> &data,
               std::vector<uint32_t> &out, size_t threshold) {
  uint64_t largest = 0;
  for(auto z : data) {
    const std::vector<uint32_t> & v = *z;
    if(v[v.size() - 1] > largest) largest = v[v.size() - 1];
  }
  std::vector<uint8_t> counters(largest+1);
  out.clear();
  for (size_t c = 0; c < data.size(); c++) {
    const std::vector<uint32_t> &v = *data[c];
    for (size_t i = 0; i < v.size(); i++) {
      counters[v[i]]++;
    }
  }
  for (uint32_t i = 0; i < counters.size(); i++) {
    if (counters[i] > threshold)
      out.push_back(i);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x7b80
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x7bb0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x7be0
testb $0x1, %al
jne 0x3d57
jmp 0x3ddb
leaq -0x30(%rbp), %rdi
callq 0x7c20
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rdi
callq 0x7a40
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x7a20
movl (%rax), %eax
cmpq -0x20(%rbp), %rax
jbe 0x3dcb
movq -0x48(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x48(%rbp), %rdi
callq 0x7a40
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
subq $0x1, %rsi
callq 0x7a20
movl (%rax), %eax
movq %rax, -0x20(%rbp)
jmp 0x3dcd
leaq -0x30(%rbp), %rdi
callq 0x7c40
jmp 0x3d41
movq -0x20(%rbp), %rax
incq %rax
movq %rax, -0xb8(%rbp)
leaq -0x61(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x77d0
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rdx
leaq -0x60(%rbp), %rdi
callq 0x77f0
jmp 0x3e12
leaq -0x61(%rbp), %rdi
callq 0x7860
movq -0x10(%rbp), %rdi
callq 0x7c60
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7880
movq %rax, %rcx
movq -0xc0(%rbp), %rax
cmpq %rcx, %rax
jae 0x3f06
movq -0x8(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x7a00
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x88(%rbp), %rdi
callq 0x7a40
movq %rax, %rcx
movq -0xc8(%rbp), %rax
cmpq %rcx, %rax
jae 0x3ef3
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x7a20
movl (%rax), %eax
movl %eax, %esi
leaq -0x60(%rbp), %rdi
callq 0x7c80
movb (%rax), %cl
addb $0x1, %cl
movb %cl, (%rax)
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x3e75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x7860
jmp 0x3f9f
jmp 0x3ef5
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x3e2c
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movq %rax, -0xd0(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x7ca0
movq %rax, %rcx
movq -0xd0(%rbp), %rax
cmpq %rcx, %rax
jae 0x3f8d
movl -0x94(%rbp), %eax
movl %eax, %esi
leaq -0x60(%rbp), %rdi
callq 0x7c80
movzbl (%rax), %eax
cmpq -0x18(%rbp), %rax
jbe 0x3f7a
movq -0x10(%rbp), %rdi
leaq -0x94(%rbp), %rsi
callq 0x7cc0
jmp 0x3f61
jmp 0x3f7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x7b20
jmp 0x3f9f
jmp 0x3f7c
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x3f10
leaq -0x60(%rbp), %rdi
callq 0x7b20
addq $0xd0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x3470
nopl (%rax,%rax)