// File: /workspace/github_c_makefile_star2_O0/FastFilter[P]BlockBloomSimulator/src/softblockmodel.h
// Function: simulate_soft
sim_stats_t simulate_soft(size_t HowManyKeys, softmodel_t model, size_t howmanytests,
                     bitset_t *b) {
  if((model.BlockSizeInBits % 64)!=0) {
      printf("block size should be divisible by 64 bits");
      abort();
  }
  size_t wordsperblock = model.BlockSizeInBits / 64;
  bitset_resize(b, model.BlockSizeInBits * model.NumberOfBlocks, true);
  bitset_clear(b);
  for (size_t i = 0; i < HowManyKeys; i++) {
    size_t blockindex = random_integer(model.NumberOfBlocks);
    for(size_t j = 0; j < wordsperblock; j++) {
        uint64_t w = random_word64();
        for(size_t k = 0; k < model.FoldCount; k++) {
            w &= random_word64();
        }
        w = w | bitset_get_word(b, blockindex * wordsperblock + j);
        bitset_set_word(b, w, blockindex * wordsperblock + j);
    }
  }
  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 < wordsperblock; j++) {
        uint64_t w = random_word64();
        for(size_t k = 0; k < model.FoldCount; k++) {
            w &= random_word64();;
        }
        uint64_t tw = bitset_get_word(b, blockindex * wordsperblock + j);
        if( (tw & w) != w) {
            is_matched = false; 
        }
    }
    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 $0xc8, %rsp
leaq 0xd0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0xa0(%rsp)
movq 0x8(%rax), %rax
andq $0x3f, %rax
cmpq $0x0, %rax
je 0x276d
leaq 0x3b4e(%rip), %rdi      # 0x62af
movb $0x0, %al
callq 0x1060
callq 0x1040
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rcx
shrq $0x6, %rcx
movq %rcx, 0x98(%rsp)
movq 0xa0(%rsp), %rdi
movq 0x8(%rax), %rsi
imulq 0x10(%rax), %rsi
movl $0x1, %edx
callq 0x3870
movq 0xa0(%rsp), %rdi
callq 0x3630
movq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rax
cmpq 0xb0(%rsp), %rax
jae 0x28e8
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1270
movq %rax, 0x88(%rsp)
movq $0x0, 0x80(%rsp)
movq 0x80(%rsp), %rax
cmpq 0x98(%rsp), %rax
jae 0x28cd
callq 0x11c0
movl %eax, %eax
movq %rax, 0x78(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x28(%rsp), %rcx
movq 0x70(%rsp), %rax
cmpq (%rcx), %rax
jae 0x2849
callq 0x11c0
movl %eax, %eax
andq 0x78(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x2819
movq 0x78(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xa0(%rsp), %rdi
movq 0x88(%rsp), %rsi
imulq 0x98(%rsp), %rsi
addq 0x80(%rsp), %rsi
callq 0x2ae0
movq %rax, %rcx
movq 0x20(%rsp), %rax
orq %rcx, %rax
movq %rax, 0x78(%rsp)
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x88(%rsp), %rdx
imulq 0x98(%rsp), %rdx
addq 0x80(%rsp), %rdx
callq 0x2b30
movq 0x80(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x80(%rsp)
jmp 0x27ee
jmp 0x28cf
movq 0x90(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x90(%rsp)
jmp 0x27b6
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movq 0x60(%rsp), %rax
cmpq 0xa8(%rsp), %rax
jae 0x2a00
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1270
movq %rax, 0x58(%rsp)
movb $0x1, 0x57(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq 0x98(%rsp), %rax
jae 0x29d6
callq 0x11c0
movl %eax, %eax
movq %rax, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x28(%rsp), %rcx
movq 0x38(%rsp), %rax
cmpq (%rcx), %rax
jae 0x2986
callq 0x11c0
movl %eax, %eax
andq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x2956
movq 0xa0(%rsp), %rdi
movq 0x58(%rsp), %rsi
imulq 0x98(%rsp), %rsi
addq 0x48(%rsp), %rsi
callq 0x2ae0
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
andq 0x40(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0x29c1
movb $0x0, 0x57(%rsp)
jmp 0x29c3
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x292e
testb $0x1, 0x57(%rsp)
je 0x29eb
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x29ed
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x28fa
movq 0x68(%rsp), %xmm0
movaps 0x3603(%rip), %xmm3     # 0x6010
movaps %xmm3, (%rsp)
punpckldq %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1]
movapd 0x3603(%rip), %xmm2     # 0x6020
movaps %xmm2, 0x10(%rsp)
subpd %xmm2, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movq 0xa8(%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, 0xb8(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x3b20
movq 0x28(%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, 0xc0(%rsp)
movsd 0xb8(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm1
addq $0xc8, %rsp
retq
nopl (%rax,%rax)