// File: /workspace/github_c_makefile_star2_O0/FastFilter[P]BlockBloomSimulator/src/windowedblockmodel.h
// Function: simulateWindow
sim_stats_t simulateWindow(size_t HowManyKeys, windowed_model_t model, size_t howmanytests,
                bitset_t *b) {
  bitset_resize(b, model.TotalBits, true);
  bitset_clear(b);
  for (size_t i = 0; i < HowManyKeys; i++) {
    size_t blockindex = random_integer(NumberOfBlocks(&model));
    for (size_t j = 0; j < model.BitsPerKeyPerBlock; j++) {
      size_t bi = random_integer(model.BlockSizeInBits);
      bitset_set(b, blockindex * model.WindowSizeInBits + bi);
    }
  }
  size_t matches = 0;
  for (size_t i = 0; i < howmanytests; i++) {
    size_t blockindex = random_integer(NumberOfBlocks(&model));
    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.WindowSizeInBits + bi);
    }
    if (is_matched)
      matches++;
  }
  sim_stats_t answer;
  answer.collision_rate = matches * 1.0 / howmanytests;
  answer.density = bitset_count(b) * 1.0 / model.TotalBits;
  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
movl $0x1, %edx
callq 0x2800
movq 0x80(%rsp), %rdi
callq 0x25c0
movq $0x0, 0x78(%rsp)
movq 0x78(%rsp), %rax
cmpq 0x90(%rsp), %rax
jae 0x13b6
movq 0x28(%rsp), %rdi
callq 0x1290
movq %rax, %rdi
callq 0x1260
movq %rax, 0x70(%rsp)
movq $0x0, 0x68(%rsp)
movq 0x28(%rsp), %rcx
movq 0x68(%rsp), %rax
cmpq (%rcx), %rax
jae 0x13a1
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1260
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x60(%rsp)
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rsi
imulq 0x18(%rax), %rsi
addq 0x60(%rsp), %rsi
callq 0x1570
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x134b
jmp 0x13a3
movq 0x78(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x78(%rsp)
jmp 0x1318
movq $0x0, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x88(%rsp), %rax
jae 0x1498
movq 0x28(%rsp), %rdi
callq 0x1290
movq %rax, %rdi
callq 0x1260
movq %rax, 0x48(%rsp)
movb $0x1, 0x47(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x28(%rsp), %rcx
movq 0x38(%rsp), %rax
cmpq (%rcx), %rax
jae 0x146e
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1260
movq %rax, 0x30(%rsp)
xorl %eax, %eax
testb $0x1, 0x47(%rsp)
movb %al, 0x27(%rsp)
je 0x1454
movq 0x28(%rsp), %rax
movq 0x80(%rsp), %rdi
movq 0x48(%rsp), %rsi
imulq 0x18(%rax), %rsi
addq 0x30(%rsp), %rsi
callq 0x15e0
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 0x1400
testb $0x1, 0x47(%rsp)
je 0x1483
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x1485
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x13c8
movq 0x58(%rsp), %xmm0
movaps 0x3b6b(%rip), %xmm3     # 0x5010
movaps %xmm3, (%rsp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x3b6b(%rip), %xmm2     # 0x5020
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 0x2ab0
movaps (%rsp), %xmm3
movaps 0x10(%rsp), %xmm2
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, %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(%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
nopw (%rax,%rax)