// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xa8, %rsp
leaq 0xb0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdx, 0x80(%rsp)
movq 0x80(%rsp), %rdi
movq 0x8(%rax), %rsi
imulq 0x10(%rax), %rsi
movl $0x1, %edx
callq 0x3870
movq 0x80(%rsp), %rdi
callq 0x3630
movq $0x0, 0x78(%rsp)
movq 0x78(%rsp), %rax
cmpq 0x90(%rsp), %rax
jae 0x1397
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1270
movq %rax, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movq 0x28(%rsp), %rcx
movq 0x68(%rsp), %rax
cmpq (%rcx), %rax
jae 0x1382
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1270
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x60(%rsp)
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rsi
imulq 0x8(%rax), %rsi
addq 0x60(%rsp), %rsi
callq 0x1550
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x132c
jmp 0x1384
movq 0x78(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x78(%rsp)
jmp 0x12fd
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x88(%rsp), %rax
jae 0x1475
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1270
movq %rax, 0x48(%rsp)
movb $0x1, 0x47(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x28(%rsp), %rcx
movq 0x38(%rsp), %rax
cmpq (%rcx), %rax
jae 0x144b
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x1270
movq %rax, 0x30(%rsp)
xorl %eax, %eax
testb $0x1, 0x47(%rsp)
movb %al, 0x27(%rsp)
je 0x1431
movq 0x28(%rsp), %rax
movq 0x80(%rsp), %rdi
movq 0x48(%rsp), %rsi
imulq 0x8(%rax), %rsi
addq 0x30(%rsp), %rsi
callq 0x15c0
movb %al, 0x27(%rsp)
movb 0x27(%rsp), %al
andb $0x1, %al
movb %al, 0x47(%rsp)
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x13dd
testb $0x1, 0x47(%rsp)
je 0x1460
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x1462
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x13a9
movq 0x58(%rsp), %xmm0
movaps 0x4b8e(%rip), %xmm3     # 0x6010
movaps %xmm3, (%rsp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x4b8e(%rip), %xmm2     # 0x6020
movaps %xmm2, 0x10(%rsp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0x88(%rsp), %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
movq 0x80(%rsp), %rdi
callq 0x3b20
movq 0x28(%rsp), %rcx
movaps (%rsp), %xmm3
movaps 0x10(%rsp), %xmm2
movq %rax, %xmm0
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0x8(%rcx), %rax
movq 0x10(%rcx), %rcx
imulq %rcx, %rax
movq %rax, %xmm1
punpckldq %xmm3, %xmm1    # xmm1 = xmm1[0],xmm3[0],xmm1[1],xmm3[1]
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movsd 0x98(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm1
addq $0xa8, %rsp
retq
nopl (%rax)