// File: /workspace/github_c_makefile_star2_O1/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, 0x38(%rsp)
movq %rax, (%rsp)
imulq %rax, %rsi
movq %rdx, %rdi
movq %rsi, 0x40(%rsp)
movl $0x1, %edx
callq 0x29aa
movq %rbx, %rdi
callq 0x2891
movq %r14, 0x48(%rsp)
testq %r14, %r14
je 0x13bc
leaq 0x90(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movq 0x38(%rsp), %rdi
callq 0x1220
cmpq $0x0, 0x30(%rsp)
je 0x13a9
movq %rax, %rbp
imulq (%rsp), %rbp
movq 0x30(%rsp), %r13
movq %rbp, 0x20(%rsp)
movq (%rsp), %rdi
callq 0x1220
movq %rax, %r12
addq %rbp, %r12
movq %r12, %r14
shrq $0x6, %r14
cmpq 0x8(%rbx), %r14
jb 0x138e
leaq 0x1(%r14), %r15
cmpq %r14, 0x10(%rbx)
ja 0x136a
leaq (%r15,%r15), %rax
movq %rax, 0x10(%rbx)
movq (%rbx), %rdi
movq %r15, %rsi
shlq $0x4, %rsi
callq 0x10d0
movq %rax, %rbp
testq %rax, %rax
je 0x1358
movq %rbp, (%rbx)
jmp 0x1360
movq (%rbx), %rdi
callq 0x1040
testq %rbp, %rbp
movq 0x20(%rsp), %rbp
je 0x13a0
movq 0x8(%rbx), %rax
leaq (,%rax,8), %rdi
addq (%rbx), %rdi
movq %r15, %rdx
subq %rax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x1090
movq %r15, 0x8(%rbx)
movl $0x1, %eax
movl %r12d, %ecx
shlq %cl, %rax
movq (%rbx), %rcx
orq %rax, (%rcx,%r14,8)
decq %r13
jne 0x130e
movq 0x50(%rsp), %rax
incq %rax
cmpq 0x48(%rsp), %rax
jne 0x12e1
cmpq $0x0, 0x18(%rsp)
je 0x1474
leaq 0x90(%rsp), %rax
movq (%rax), %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r12, 0x20(%rsp)
movq 0x38(%rsp), %rdi
callq 0x1220
testq %r12, %r12
je 0x143a
movq %rax, %r14
imulq (%rsp), %r14
movb $0x1, %r15b
movq (%rsp), %rdi
callq 0x1220
testb $0x1, %r15b
je 0x1427
addq %r14, %rax
movq %rax, %rcx
shrq $0x6, %rcx
cmpq 0x8(%rbx), %rcx
jae 0x1427
movq (%rbx), %rdx
movq (%rdx,%rcx,8), %rcx
btq %rax, %rcx
setb %r15b
jmp 0x142a
xorl %r15d, %r15d
decq %r12
jne 0x13f7
movzbl %r15b, %eax
movq 0x20(%rsp), %r12
jmp 0x143f
movl $0x1, %eax
addq %rax, %rbp
incq %r13
cmpq 0x18(%rsp), %r13
jne 0x13dd
movq %rbp, %xmm0
punpckldq 0x2bb7(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2bbf(%rip), %xmm0     # 0x4020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, (%rsp)
jmp 0x147d
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq 0x40(%rsp), %xmm0
movq 0x18(%rsp), %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movdqa 0x2b9b(%rip), %xmm0     # 0x4030
pand %xmm1, %xmm0
por 0x2b9f(%rip), %xmm0     # 0x4040
psrlq $0x20, %xmm1
por 0x2ba2(%rip), %xmm1     # 0x4050
subpd 0x2baa(%rip), %xmm1     # 0x4060
addpd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
callq 0x2b06
movq %rax, %xmm0
punpckldq 0x2b3b(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2b43(%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 0x20(%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