// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, (%rsp)
movq 0x88(%rsp), %r15
testb $0x3f, %r15b
jne 0x1fcd
movq %rdx, %rbx
leaq 0x80(%rsp), %r14
movq 0x10(%r14), %rsi
movq %rsi, 0x10(%rsp)
imulq %r15, %rsi
shrq $0x6, %r15
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %rsi, 0x38(%rsp)
callq 0x2645
movq %rbx, %rdi
callq 0x2540
movq (%r14), %rax
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
movq %r15, 0x20(%rsp)
cmpq (%rsp), %r12
je 0x1e8b
movq 0x10(%rsp), %rdi
callq 0x122f
movq %rax, %rbp
imulq %r15, %rbp
xorl %r13d, %r13d
cmpq %r15, %r13
je 0x1e86
callq 0x11ec
movl %eax, %r15d
movq 0x18(%rsp), %r14
subq $0x1, %r14
jb 0x1e69
callq 0x11ec
andl %eax, %r15d
jmp 0x1e59
movq %r13, %rax
addq %rbp, %rax
cmpq %rax, 0x8(%rbx)
jbe 0x1e7c
movq (%rbx), %rcx
orq %r15, (%rcx,%rax,8)
incq %r13
movq 0x20(%rsp), %r15
jmp 0x1e47
incq %r12
jmp 0x1e2d
xorl %r14d, %r14d
xorl %eax, %eax
cmpq 0x8(%rsp), %rax
je 0x1f2a
movq %rax, 0x40(%rsp)
movq %r14, (%rsp)
movq 0x10(%rsp), %rdi
callq 0x122f
movq %rax, %r13
imulq %r15, %r13
movb $0x1, %bpl
xorl %r12d, %r12d
cmpq %r15, %r12
je 0x1f0e
callq 0x11ec
movl %eax, %r15d
movq 0x18(%rsp), %r14
subq $0x1, %r14
jb 0x1edd
callq 0x11ec
andl %eax, %r15d
jmp 0x1ecd
leaq (%r12,%r13), %rax
cmpq %rax, 0x8(%rbx)
jbe 0x1ef0
movq (%rbx), %rcx
movq (%rcx,%rax,8), %rax
jmp 0x1ef2
xorl %eax, %eax
notq %rax
testq %rax, %r15
movzbl %bpl, %ebp
movl $0x0, %eax
cmovnel %eax, %ebp
incq %r12
movq 0x20(%rsp), %r15
jmp 0x1ebb
andb $0x1, %bpl
movzbl %bpl, %eax
movq (%rsp), %r14
addq %rax, %r14
movq 0x40(%rsp), %rax
incq %rax
jmp 0x1e90
movq 0x38(%rsp), %xmm0
movq 0x8(%rsp), %xmm1
punpcklqdq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0]
movdqa %xmm1, %xmm0
pand 0x20ca(%rip), %xmm0     # 0x4010
por 0x20d2(%rip), %xmm0     # 0x4020
psrlq $0x20, %xmm1
por 0x20d5(%rip), %xmm1     # 0x4030
subpd 0x20dd(%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 0x2085(%rip), %xmm1     # 0x4010
pand %xmm0, %xmm1
por 0x2089(%rip), %xmm1     # 0x4020
psrlq $0x20, %xmm0
por 0x208c(%rip), %xmm0     # 0x4030
subpd 0x2094(%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
leaq 0x232b(%rip), %rdi      # 0x42ff
xorl %eax, %eax
callq 0x1080
callq 0x1060