// File: /workspace/github_c_makefile_star2_O3/FastFilter[P]BlockBloomSimulator/src/blockmodel.h
// Function: simulate
sim_stats_t simulate(size_t HowManyKeys, model_t model, size_t howmanytests,
                bitset_t *b) {
  bitset_resize(b, model.BlockSizeInBits * model.NumberOfBlocks, true);
  bitset_clear(b);

  for (size_t i = 0; i < HowManyKeys; i++) {
    size_t blockindex = random_integer(model.NumberOfBlocks);
    for (size_t j = 0; j < model.BitsPerKeyPerBlock; j++) {
      size_t bi = random_integer(model.BlockSizeInBits);
      bitset_set(b, blockindex * model.BlockSizeInBits + bi);
    }
  }
  size_t matches = 0;
  for (size_t i = 0; i < howmanytests; i++) {
    size_t blockindex = random_integer(model.NumberOfBlocks);
    bool is_matched = true;
    for (size_t j = 0; j < model.BitsPerKeyPerBlock; j++) {
      size_t bi = random_integer(model.BlockSizeInBits);
      is_matched =
          is_matched && bitset_get(b, blockindex * model.BlockSizeInBits + bi);
    }
    if (is_matched)
      matches++;
  }
  sim_stats_t answer;
  answer.collision_rate = matches * 1.0 / howmanytests;
  answer.density = bitset_count(b) * 1.0 /  (model.BlockSizeInBits * model.NumberOfBlocks) ;
  return answer;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
leaq 0x90(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rsi
movq %rsi, 0x30(%rsp)
movq %rax, (%rsp)
imulq %rax, %rsi
movq %rdx, %rdi
movq %rsi, 0x48(%rsp)
movl $0x1, %edx
callq 0x296e
movq %rbx, %rdi
callq 0x2856
movq %r14, 0x50(%rsp)
testq %r14, %r14
je 0x13b7
leaq 0x90(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq 0x30(%rsp), %rdi
callq 0x1230
cmpq $0x0, 0x28(%rsp)
je 0x13a4
movq %rax, %r15
imulq (%rsp), %r15
movq 0x28(%rsp), %rbp
movq (%rsp), %rdi
callq 0x1230
movq %rax, %r13
addq %r15, %r13
movq %r13, %r14
shrq $0x6, %r14
movq 0x8(%rbx), %rcx
cmpq %rcx, %r14
jb 0x1381
leaq 0x1(%r14), %r12
movq (%rbx), %rax
cmpq %r14, 0x10(%rbx)
ja 0x1368
leaq (%r12,%r12), %rcx
movq %rcx, 0x10(%rbx)
movq %r12, %rsi
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x10e0
testq %rax, %rax
je 0x139a
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
leaq (%rax,%rcx,8), %rdi
movq %r12, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x1090
movq %r12, 0x8(%rbx)
movl $0x1, %eax
movl %r13d, %ecx
shlq %cl, %rax
movq (%rbx), %rcx
orq %rax, (%rcx,%r14,8)
decq %rbp
jne 0x1319
jmp 0x13a4
movq (%rbx), %rdi
callq 0x1040
jmp 0x1393
movq 0x20(%rsp), %rax
incq %rax
cmpq 0x50(%rsp), %rax
jne 0x12f1
cmpq $0x0, 0x18(%rsp)
je 0x146f
leaq 0x90(%rsp), %rax
movq (%rax), %r15
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r15, 0x20(%rsp)
movq 0x30(%rsp), %rdi
callq 0x1230
testq %r15, %r15
je 0x1435
movq %rax, %r14
imulq (%rsp), %r14
movb $0x1, %r12b
movq (%rsp), %rdi
callq 0x1230
testb $0x1, %r12b
je 0x1422
addq %r14, %rax
movq %rax, %rcx
shrq $0x6, %rcx
cmpq 0x8(%rbx), %rcx
jae 0x1422
movq (%rbx), %rdx
movq (%rdx,%rcx,8), %rcx
btq %rax, %rcx
setb %r12b
jmp 0x1425
xorl %r12d, %r12d
decq %r15
jne 0x13f2
movzbl %r12b, %eax
movq 0x20(%rsp), %r15
jmp 0x143a
movl $0x1, %eax
addq %rax, %rbp
incq %r13
cmpq 0x18(%rsp), %r13
jne 0x13d8
movq %rbp, %xmm0
punpckldq 0x2bbc(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2bc4(%rip), %xmm0     # 0x4020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
jmp 0x1478
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq 0x48(%rsp), %xmm0
movq 0x18(%rsp), %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movdqa 0x2ba0(%rip), %xmm0     # 0x4030
pand %xmm1, %xmm0
por 0x2ba4(%rip), %xmm0     # 0x4040
psrlq $0x20, %xmm1
por 0x2ba7(%rip), %xmm1     # 0x4050
subpd 0x2baf(%rip), %xmm1     # 0x4060
addpd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movq %rbx, %rdi
callq 0x2aaa
movq %rax, %xmm0
punpckldq 0x2b40(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2b48(%rip), %xmm0     # 0x4020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addpd %xmm0, %xmm1
movapd (%rsp), %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
divpd 0x30(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq