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

  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(lane_size);
      bitset_set(b, blockindex * model.BlockSizeInBits + j * lane_size + 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(lane_size);
      is_matched =
          is_matched && bitset_get(b, blockindex * model.BlockSizeInBits +
                                          j * lane_size + 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 $0x68, %rsp
movq %rdx, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
movq 0xa8(%rsp), %r14
movq 0xb0(%rsp), %rsi
movq %rsi, 0x40(%rsp)
imulq %r14, %rsi
movq %rdx, %rdi
movq %rsi, 0x50(%rsp)
movl $0x1, %edx
callq 0x296e
movq %rbx, %rdi
callq 0x2856
movq 0xa0(%rsp), %rcx
movq %r14, 0x48(%rsp)
movq %r14, %rax
xorl %edx, %edx
movq %rcx, 0x8(%rsp)
divq %rcx
movq %r15, 0x60(%rsp)
testq %r15, %r15
movq %rax, 0x20(%rsp)
je 0x1a87
movq %rax, %rbp
movq 0x8(%rsp), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, 0x58(%rsp)
xorl %eax, %eax
movq %rax, 0x18(%rsp)
movq 0x40(%rsp), %rdi
callq 0x1230
imulq 0x48(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x58(%rsp), %r12
xorl %r13d, %r13d
movq %rbp, %rdi
callq 0x1230
movq %r13, %r15
imulq %rbp, %r15
addq 0x30(%rsp), %r15
addq %rax, %r15
movq %r15, %r14
shrq $0x6, %r14
movq 0x8(%rbx), %rcx
cmpq %rcx, %r14
jb 0x1a45
leaq 0x1(%r14), %rbp
movq (%rbx), %rax
cmpq %r14, 0x10(%rbx)
ja 0x1a27
leaq (,%rbp,2), %rcx
movq %rcx, 0x10(%rbx)
movq %rbp, %rsi
shlq $0x4, %rsi
movq %rax, %rdi
callq 0x10e0
testq %rax, %rax
je 0x1a65
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
leaq (%rax,%rcx,8), %rdi
movq %rbp, %rdx
subq %rcx, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x1090
movq %rbp, 0x8(%rbx)
movq 0x20(%rsp), %rbp
movl $0x1, %eax
movl %r15d, %ecx
shlq %cl, %rax
movq (%rbx), %rcx
orq %rax, (%rcx,%r14,8)
incq %r13
decq %r12
jne 0x19cc
jmp 0x1a74
movq (%rbx), %rdi
callq 0x1040
movq 0x20(%rsp), %rbp
jmp 0x1a57
movq 0x18(%rsp), %rax
incq %rax
cmpq 0x60(%rsp), %rax
jne 0x19aa
cmpq $0x0, 0x10(%rsp)
je 0x1b61
movq 0x8(%rsp), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, 0x8(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x20(%rsp), %r15
movq %rcx, 0x18(%rsp)
movq %rax, 0x30(%rsp)
movq 0x40(%rsp), %rdi
callq 0x1230
movq %rax, %r14
imulq 0x48(%rsp), %r14
movb $0x1, %bpl
movq 0x8(%rsp), %r13
xorl %r12d, %r12d
movq %r15, %rdi
callq 0x1230
testb $0x1, %bpl
je 0x1b0f
movq %r12, %rcx
imulq %r15, %rcx
addq %r14, %rcx
addq %rax, %rcx
movq %rcx, %rax
shrq $0x6, %rax
cmpq 0x8(%rbx), %rax
jae 0x1b0f
movq (%rbx), %rdx
movq (%rdx,%rax,8), %rax
btq %rcx, %rax
setb %bpl
jmp 0x1b11
xorl %ebp, %ebp
incq %r12
decq %r13
jne 0x1ad6
movzbl %bpl, %eax
movq 0x18(%rsp), %rcx
addq %rax, %rcx
movq 0x30(%rsp), %rax
incq %rax
cmpq 0x10(%rsp), %rax
jne 0x1aae
movq %rcx, %xmm0
punpckldq 0x24cb(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x24d3(%rip), %xmm0     # 0x4020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
jmp 0x1b6b
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq 0x50(%rsp), %xmm0
movq 0x10(%rsp), %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movdqa 0x24ad(%rip), %xmm0     # 0x4030
pand %xmm1, %xmm0
por 0x24b1(%rip), %xmm0     # 0x4040
psrlq $0x20, %xmm1
por 0x24b4(%rip), %xmm1     # 0x4050
subpd 0x24bc(%rip), %xmm1     # 0x4060
addpd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movq %rbx, %rdi
callq 0x2aaa
movq %rax, %xmm0
punpckldq 0x244d(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2455(%rip), %xmm0     # 0x4020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addpd %xmm0, %xmm1
movapd 0x20(%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 $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq