// File: /workspace/github_cpp_makefile_star2_O2/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::ClusteringMatchInThread(int, int, int)
bool WholeGenome::ClusteringMatchInThread(int start, int end, int thread_index) {

	for (int cluster_id = start; cluster_id < end; cluster_id++) {
        if(cluster_id >= variants_by_cluster.size()) break;
        //dout << cluster_id << endl;
        //bool method1 = MatchingSingleCluster(cluster_id, thread_index);
        vector<VariantIndicator> vi_list = variants_by_cluster[cluster_id];
        if(vi_list.size() <= 1) continue;
        // create variant_list from vi_list;

        for(int t = 0; t < threshold_num; t++){

            double quality_threshold = threshold_list[t];

            vector<DiploidVariant> variant_list;
            int chr_id = -1;
            for(int i = 0; i < vi_list.size(); i++){
                VariantIndicator vi = vi_list[i];
                chr_id = vi.chr_id;
                int var_id = vi.var_id;
                DiploidVariant var;
                if(vi.refer){
                    var = ref_variant_by_chrid[chr_id]->at(var_id);
                }else{
                    var = que_variant_by_chrid[chr_id]->at(var_id);
                }
                if(var.qual < quality_threshold) continue;
                variant_list.push_back(var);
            }
            if(chr_id == -1 || chr_id >= chrom_num){
                cout << "[VarMatch] Error in matching single cluster" << endl;
                continue;
            }

            MatchVariantListInThread(thread_index, 
                                    t,
                                    chr_id,
                                    variant_list,
                                    cluster_id);

        }

        //if(method1 != method2){
        //    cout << "not same result for cluster :" << cluster_id << ": " << method1 << "," << method2 << endl;
        //}

	}
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl %ecx, 0x14(%rsp)
movq %rdi, %r12
movslq %esi, %rcx
movslq %edx, %rax
movq %rax, 0x58(%rsp)
leaq 0x11c38(%rip), %rbp     # 0x225aa
cmpq 0x58(%rsp), %rcx
jge 0x10bed
movq 0x160(%r12), %rsi
movq 0x168(%r12), %rax
subq %rsi, %rax
cqto
pushq $0x18
popq %rdi
idivq %rdi
cmpq %rcx, %rax
jbe 0x10bed
movq %rcx, 0x18(%rsp)
imulq $0x18, %rcx, %rax
addq %rax, %rsi
leaq 0x28(%rsp), %rdi
callq 0x1a2ee
movq 0x30(%rsp), %rax
subq 0x28(%rsp), %rax
cqto
pushq $0xc
popq %rcx
idivq %rcx
cmpq $0x2, %rax
jae 0x109e3
leaq 0x28(%rsp), %rdi
callq 0x1f18e
movq 0x18(%rsp), %rcx
incq %rcx
jmp 0x10972
xorl %ebx, %ebx
movslq 0x268(%r12), %rax
cmpq %rax, %rbx
jge 0x109cf
movq 0x250(%r12), %rax
movq %rbx, 0x20(%rsp)
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x60(%rsp)
andq $0x0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
xorl %edi, %edi
pushq $-0x1
popq %r15
movl %r15d, 0xc(%rsp)
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rax
subq %rcx, %rax
cqto
pushq $0xc
popq %rsi
idivq %rsi
cmpq %rdi, %rax
jbe 0x10b8d
movq %rdi, %r13
imulq $0xc, %rdi, %rax
movsbl (%rcx,%rax), %edx
movl %edx, 0xc(%rsp)
movslq 0x4(%rcx,%rax), %r14
movb 0x8(%rcx,%rax), %bl
leaq 0x68(%rsp), %rdi
movq %rbp, %rsi
leaq 0x13(%rsp), %rdx
callq 0x72ee
leaq 0xc8(%rsp), %r15
leaq 0x88(%rsp), %rdi
movq %rbp, %rsi
leaq 0x12(%rsp), %rdx
callq 0x72ee
leaq 0xa8(%rsp), %rdi
movq %rbp, %rsi
leaq 0x11(%rsp), %rdx
callq 0x72ee
movq %r15, %rdi
leaq 0x88(%rsp), %rsi
pushq $0x2
popq %rdx
leaq 0x10(%rsp), %rcx
callq 0x1a34c
xorpd %xmm0, %xmm0
leaq 0xe0(%rsp), %rdi
pushq $-0x1
popq %rsi
leaq 0x68(%rsp), %rdx
movq %r15, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq $0x0
pushq $0x0
pushq $0x0
callq 0x19b60
addq $0x20, %rsp
movq %r15, %rdi
movq %rbp, %r15
movq %r12, %rbp
callq 0xadcc
pushq $0x20
popq %r12
leaq (%rsp,%r12), %rdi
addq $0x88, %rdi
callq 0x55e8
addq $-0x20, %r12
cmpq $-0x20, %r12
jne 0x10af7
leaq 0x68(%rsp), %rdi
callq 0x55e8
movslq 0xc(%rsp), %rax
notb %bl
movzbl %bl, %ecx
andl $0x1, %ecx
movq %rbp, %r12
movq 0x148(%rbp,%rcx,8), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x1a386
leaq 0xe0(%rsp), %rdi
movq %rax, %rsi
callq 0x1a3a4
movsd 0x60(%rsp), %xmm0
ucomisd 0x130(%rsp), %xmm0
ja 0x10b72
leaq 0x40(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x19bea
leaq 0xe0(%rsp), %rdi
callq 0x19c16
movq %r13, %rdi
incq %rdi
movq %r15, %rbp
jmp 0x10a25
movl 0xc(%rsp), %ecx
cmpl $-0x1, %ecx
je 0x10bbb
cmpl (%r12), %ecx
jge 0x10bbb
movq %r12, %rdi
movl 0x14(%rsp), %esi
movq 0x20(%rsp), %rbx
movl %ebx, %edx
leaq 0x40(%rsp), %r8
movq 0x18(%rsp), %r9
callq 0xf996
jmp 0x10bdb
movq 0x1f3fe(%rip), %rdi     # 0x2ffc0
leaq 0x119f0(%rip), %rsi     # 0x225b9
callq 0x52f0
movq 0x20(%rsp), %rbx
movq %rax, %rdi
callq 0x5190
leaq 0x40(%rsp), %rdi
callq 0x19a38
incq %rbx
jmp 0x109e5
movb $0x1, %al
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10c03
movq %rax, %rbx
jmp 0x10c6e
movq %rax, %rbx
jmp 0x10c22
movq %rax, %rbx
jmp 0x10c52
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0xadcc
pushq $0x20
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x88, %rdi
callq 0x55e8
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x10c26
jmp 0x10c52
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x55e8
leaq 0x68(%rsp), %rdi
callq 0x55e8
jmp 0x10c6e
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x19c16
leaq 0x40(%rsp), %rdi
callq 0x19a38
leaq 0x28(%rsp), %rdi
callq 0x1f18e
movq %rbx, %rdi
callq 0x5540