// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
movq %rsi, 0x38(%rsp)
movq %rdi, %r14
leaq 0xa0(%rsp), %rax
movq 0x8(%rax), %rsi
movq %rdx, %rdi
movq %rsi, 0x28(%rsp)
movl $0x1, %edx
callq 0x1f5e
movq %rbx, %rdi
callq 0x1e46
movq %r14, 0x30(%rsp)
testq %r14, %r14
je 0x13e9
leaq 0xa0(%rsp), %rcx
movq (%rcx), %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rcx), %r13
movq 0x28(%rsp), %rax
subq %r13, %rax
movq 0x18(%rcx), %rcx
xorl %esi, %esi
xorl %edx, %edx
movq %rcx, 0x58(%rsp)
divq %rcx
incq %rax
movq %rax, 0x60(%rsp)
movq %rsi, 0x40(%rsp)
movq 0x60(%rsp), %rdi
callq 0x1220
cmpq $0x0, 0x8(%rsp)
je 0x13d6
movq %rax, %r15
imulq 0x58(%rsp), %r15
movq 0x8(%rsp), %r12
movq %r15, 0x10(%rsp)
movq %r13, %rdi
callq 0x1220
movq %rax, %rbp
addq %r15, %rbp
movq %rbp, %r14
shrq $0x6, %r14
movq 0x8(%rbx), %rcx
cmpq %rcx, %r14
jb 0x13a8
movq %r13, %r15
leaq 0x1(%r14), %r13
movq (%rbx), %rax
cmpq %r14, 0x10(%rbx)
ja 0x1387
leaq (,%r13,2), %rcx
movq %rcx, 0x10(%rbx)
movq %r13, %rsi
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x10d0
testq %rax, %rax
je 0x13c4
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
leaq (%rax,%rcx,8), %rdi
movq %r13, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x1080
movq %r13, 0x8(%rbx)
movq %r15, %r13
movq 0x10(%rsp), %r15
movl $0x1, %eax
movl %ebp, %ecx
shlq %cl, %rax
movq (%rbx), %rcx
orq %rax, (%rcx,%r14,8)
decq %r12
jne 0x1332
jmp 0x13d6
movq (%rbx), %rdi
callq 0x1030
movq %r15, %r13
movq 0x10(%rsp), %r15
jmp 0x13b9
movq 0x40(%rsp), %rsi
incq %rsi
cmpq 0x30(%rsp), %rsi
jne 0x1304
cmpq $0x0, 0x38(%rsp)
je 0x14ce
leaq 0xa0(%rsp), %rcx
movq (%rcx), %r13
movq 0x10(%rcx), %r12
movq 0x28(%rsp), %rax
subq %r12, %rax
movq 0x18(%rcx), %rcx
xorl %ebp, %ebp
xorl %edx, %edx
movq %rcx, 0x30(%rsp)
divq %rcx
incq %rax
movq %rax, 0x40(%rsp)
xorl %r15d, %r15d
movq %r13, 0x8(%rsp)
movq 0x40(%rsp), %rdi
callq 0x1220
testq %r13, %r13
je 0x1493
movq %rax, %r14
movq %r15, 0x10(%rsp)
imulq 0x30(%rsp), %r14
movb $0x1, %r15b
movq %r12, %rdi
callq 0x1220
testb $0x1, %r15b
je 0x147b
addq %r14, %rax
movq %rax, %rcx
shrq $0x6, %rcx
cmpq 0x8(%rbx), %rcx
jae 0x147b
movq (%rbx), %rdx
movq (%rdx,%rcx,8), %rcx
btq %rax, %rcx
setb %r15b
jmp 0x147e
xorl %r15d, %r15d
decq %r13
jne 0x144c
movzbl %r15b, %eax
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %r15
jmp 0x1498
movl $0x1, %eax
addq %rax, %r15
incq %rbp
cmpq 0x38(%rsp), %rbp
jne 0x142c
movq %r15, %xmm0
punpckldq 0x1b5e(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1b66(%rip), %xmm0     # 0x3020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x10(%rsp)
jmp 0x14d8
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %xmm0
movq 0x38(%rsp), %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movdqa 0x1b40(%rip), %xmm0     # 0x3030
pand %xmm1, %xmm0
por 0x1b44(%rip), %xmm0     # 0x3040
psrlq $0x20, %xmm1
por 0x1b47(%rip), %xmm1     # 0x3050
subpd 0x1b4f(%rip), %xmm1     # 0x3060
addpd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
movq %rbx, %rdi
callq 0x209a
movq %rax, %xmm0
punpckldq 0x1ae0(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1ae8(%rip), %xmm0     # 0x3020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addpd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
divpd 0x40(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq