// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %rdx, %r13
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movq 0xb8(%rsp), %rbx
movq 0xc0(%rsp), %rsi
movq %rsi, 0x48(%rsp)
imulq %rbx, %rsi
movq %rdx, %rdi
movq %rsi, 0x58(%rsp)
movl $0x1, %edx
callq 0x29aa
movq %r13, %rdi
callq 0x2891
movq 0xb0(%rsp), %rcx
movq %rbx, 0x50(%rsp)
movq %rbx, %rax
xorl %edx, %edx
movq %rcx, 0x8(%rsp)
divq %rcx
movq %r14, 0x68(%rsp)
testq %r14, %r14
movq %r13, 0x18(%rsp)
movq %rax, 0x30(%rsp)
je 0x1a9a
movq %rax, %rbx
movq 0x8(%rsp), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, 0x60(%rsp)
xorl %eax, %eax
movq %rax, 0x70(%rsp)
movq 0x48(%rsp), %rdi
callq 0x1220
imulq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x60(%rsp), %r12
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x1220
movq %r14, %r15
imulq %rbx, %r15
addq 0x20(%rsp), %r15
addq %rax, %r15
movq %r15, %rbp
shrq $0x6, %rbp
cmpq 0x8(%r13), %rbp
jb 0x1a63
leaq 0x1(%rbp), %rbx
cmpq %rbp, 0x10(%r13)
ja 0x1a3e
leaq (%rbx,%rbx), %rax
movq %rax, 0x10(%r13)
movq (%r13), %rdi
movq %rbx, %rsi
shlq $0x4, %rsi
callq 0x10d0
movq %r13, %rcx
movq %rax, %r13
testq %rax, %rax
je 0x1a2c
movq %r13, (%rcx)
jmp 0x1a34
movq (%rcx), %rdi
callq 0x1040
testq %r13, %r13
movq 0x18(%rsp), %r13
je 0x1a76
movq 0x8(%r13), %rax
leaq (,%rax,8), %rdi
addq (%r13), %rdi
movq %rbx, %rdx
subq %rax, %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x1090
movq %rbx, 0x8(%r13)
movl $0x1, %eax
movl %r15d, %ecx
shlq %cl, %rax
movq (%r13), %rcx
orq %rax, (%rcx,%rbp,8)
incq %r14
decq %r12
movq 0x30(%rsp), %rbx
jne 0x19d6
movq 0x70(%rsp), %rax
incq %rax
cmpq 0x68(%rsp), %rax
jne 0x19b4
cmpq $0x0, 0x10(%rsp)
je 0x1b6f
movq 0x8(%rsp), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
xorl %eax, %eax
movq 0x30(%rsp), %r12
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rdi
callq 0x1220
movq %rax, %r14
imulq 0x50(%rsp), %r14
movb $0x1, %bl
movq 0x8(%rsp), %r13
xorl %ebp, %ebp
movq %r12, %rdi
callq 0x1220
testb $0x1, %bl
je 0x1b1f
movq %rbp, %rcx
imulq %r12, %rcx
addq %r14, %rcx
addq %rax, %rcx
movq %rcx, %rax
shrq $0x6, %rax
movq 0x18(%rsp), %rdx
cmpq 0x8(%rdx), %rax
jae 0x1b1f
movq (%rdx), %rdx
movq (%rdx,%rax,8), %rax
btq %rcx, %rax
setb %bl
jmp 0x1b21
xorl %ebx, %ebx
incq %rbp
decq %r13
jne 0x1ae3
movzbl %bl, %eax
movq 0x20(%rsp), %rcx
addq %rax, %rcx
movq %rcx, %rax
incq %r15
cmpq 0x10(%rsp), %r15
jne 0x1ac2
movq %rax, %xmm0
punpckldq 0x24c2(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x24ca(%rip), %xmm0     # 0x4020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movq 0x18(%rsp), %r13
jmp 0x1b79
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq 0x58(%rsp), %xmm0
movq 0x10(%rsp), %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movdqa 0x249f(%rip), %xmm0     # 0x4030
pand %xmm1, %xmm0
por 0x24a3(%rip), %xmm0     # 0x4040
psrlq $0x20, %xmm1
por 0x24a6(%rip), %xmm1     # 0x4050
subpd 0x24ae(%rip), %xmm1     # 0x4060
addpd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movq %r13, %rdi
callq 0x2b06
movq %rax, %xmm0
punpckldq 0x243f(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2447(%rip), %xmm0     # 0x4020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addpd %xmm0, %xmm1
movapd 0x30(%rsp), %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
divpd 0x20(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq