// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %rdx, %rbx
movq %rsi, 0x8(%rsp)
movq %rdi, (%rsp)
movq 0x88(%rsp), %r14
movq 0x90(%rsp), %rsi
movq %rsi, 0x18(%rsp)
imulq %r14, %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %rsi, 0x38(%rsp)
callq 0x2645
movq %rbx, %rdi
callq 0x2540
movq 0x80(%rsp), %rcx
xorl %r15d, %r15d
movq %r14, 0x20(%rsp)
movq %r14, %rax
xorl %edx, %edx
movq %rcx, 0x10(%rsp)
divq %rcx
movq %rax, %rbp
cmpq (%rsp), %r15
je 0x190d
movq 0x18(%rsp), %rdi
callq 0x122f
movq %rax, %r14
imulq 0x20(%rsp), %r14
movq 0x10(%rsp), %r13
xorl %r12d, %r12d
subq $0x1, %r13
jb 0x1908
movq %rbp, %rdi
callq 0x122f
movq %r12, %rsi
imulq %rbp, %rsi
addq %r14, %rsi
addq %rax, %rsi
movq %rbx, %rdi
callq 0x13ed
incq %r12
jmp 0x18e0
incq %r15
jmp 0x18bf
xorl %r14d, %r14d
xorl %eax, %eax
cmpq 0x8(%rsp), %rax
je 0x198e
movq %rax, 0x40(%rsp)
movq %r14, (%rsp)
movq 0x18(%rsp), %rdi
callq 0x122f
movq %rax, %r12
imulq 0x20(%rsp), %r12
movb $0x1, %r14b
movq 0x10(%rsp), %r15
xorl %r13d, %r13d
subq $0x1, %r15
jb 0x1976
movq %rbp, %rdi
callq 0x122f
testb $0x1, %r14b
je 0x196e
movq %r13, %rsi
imulq %rbp, %rsi
addq %r12, %rsi
addq %rax, %rsi
movq %rbx, %rdi
callq 0x1483
movl %eax, %r14d
jmp 0x1971
xorl %r14d, %r14d
incq %r13
jmp 0x1940
movzbl %r14b, %eax
andl $0x1, %eax
movq (%rsp), %r14
addq %rax, %r14
movq 0x40(%rsp), %rax
incq %rax
jmp 0x1912
movq 0x38(%rsp), %xmm0
movq 0x8(%rsp), %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movdqa %xmm1, %xmm0
pand 0x2666(%rip), %xmm0     # 0x4010
por 0x266e(%rip), %xmm0     # 0x4020
psrlq $0x20, %xmm1
por 0x2671(%rip), %xmm1     # 0x4030
subpd 0x2679(%rip), %xmm1     # 0x4040
addpd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
callq 0x2772
movq %r14, %xmm0
movq %rax, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqa 0x2621(%rip), %xmm1     # 0x4010
pand %xmm0, %xmm1
por 0x2625(%rip), %xmm1     # 0x4020
psrlq $0x20, %xmm0
por 0x2628(%rip), %xmm0     # 0x4030
subpd 0x2630(%rip), %xmm0     # 0x4040
addpd %xmm1, %xmm0
divpd 0x20(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq