// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xb8, %rsp
leaq 0xc0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movq %rdx, 0x90(%rsp)
movq 0x90(%rsp), %rdi
movq 0x8(%rax), %rsi
imulq 0x10(%rax), %rsi
movl $0x1, %edx
callq 0x3870
movq 0x90(%rsp), %rdi
callq 0x3630
movq 0x30(%rsp), %rcx
movq 0x8(%rcx), %rax
xorl %edx, %edx
divq (%rcx)
movq %rax, 0x88(%rsp)
movq $0x0, 0x80(%rsp)
movq 0x80(%rsp), %rax
cmpq 0xa0(%rsp), %rax
jae 0x1dd9
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1270
movq %rax, 0x78(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x30(%rsp), %rcx
movq 0x70(%rsp), %rax
cmpq (%rcx), %rax
jae 0x1dbe
movq 0x88(%rsp), %rdi
callq 0x1270
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x68(%rsp)
movq 0x90(%rsp), %rdi
movq 0x78(%rsp), %rsi
imulq 0x8(%rax), %rsi
movq 0x70(%rsp), %rax
imulq 0x88(%rsp), %rax
addq %rax, %rsi
addq 0x68(%rsp), %rsi
callq 0x1550
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x1d58
jmp 0x1dc0
movq 0x80(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x80(%rsp)
jmp 0x1d26
movq $0x0, 0x60(%rsp)
movq $0x0, 0x58(%rsp)
movq 0x58(%rsp), %rax
cmpq 0x98(%rsp), %rax
jae 0x1ec7
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1270
movq %rax, 0x50(%rsp)
movb $0x1, 0x4f(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x30(%rsp), %rcx
movq 0x40(%rsp), %rax
cmpq (%rcx), %rax
jae 0x1e9d
movq 0x88(%rsp), %rdi
callq 0x1270
movq %rax, 0x38(%rsp)
xorl %eax, %eax
testb $0x1, 0x4f(%rsp)
movb %al, 0x2f(%rsp)
je 0x1e83
movq 0x30(%rsp), %rax
movq 0x90(%rsp), %rdi
movq 0x50(%rsp), %rsi
imulq 0x8(%rax), %rsi
movq 0x40(%rsp), %rax
imulq 0x88(%rsp), %rax
addq %rax, %rsi
addq 0x38(%rsp), %rsi
callq 0x15c0
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
andb $0x1, %al
movb %al, 0x4f(%rsp)
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x1e1f
testb $0x1, 0x4f(%rsp)
je 0x1eb2
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x1eb4
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x1deb
movq 0x60(%rsp), %xmm0
movaps 0x413c(%rip), %xmm3     # 0x6010
movaps %xmm3, (%rsp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x413c(%rip), %xmm2     # 0x6020
movaps %xmm2, 0x10(%rsp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0x98(%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, 0xa8(%rsp)
movq 0x90(%rsp), %rdi
callq 0x3b20
movq 0x30(%rsp), %rcx
movaps (%rsp), %xmm3
movaps 0x10(%rsp), %xmm2
movq %rax, %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(%rcx), %rax
movq 0x10(%rcx), %rcx
imulq %rcx, %rax
movq %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, 0xb0(%rsp)
movsd 0xa8(%rsp), %xmm0
movsd 0xb0(%rsp), %xmm1
addq $0xb8, %rsp
retq
nop