// File: /workspace/github_cpp_makefile_star2_O1/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, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
cmpl %edx, %esi
jge 0x170f7
movq %rdi, %r14
leaq 0xa8(%rsp), %rbx
movslq %esi, %rdx
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movq 0x252fc(%rip), %r15     # 0x3bfd0
leaq 0x88(%rsp), %rbp
movq 0x160(%r14), %rax
movq 0x168(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
cmpq %rdx, %rcx
jbe 0x170f7
movq %rdx, 0x38(%rsp)
leaq (%rdx,%rdx,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x20(%rsp), %rdi
callq 0x2925a
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
sarq $0x2, %rax
imulq %r12, %rax
cmpq $0x2, %rax
jb 0x170ce
cmpl $0x0, 0x268(%r14)
jle 0x170ce
xorl %r13d, %r13d
movq 0x250(%r14), %rax
movsd (%rax,%r13,8), %xmm0
movsd %xmm0, 0x80(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x1704c
movq %r13, 0x78(%rsp)
xorl %r15d, %r15d
leaq (%r15,%r15,2), %rcx
movsbl (%rax,%rcx,4), %edx
movl %edx, 0xc(%rsp)
movslq 0x4(%rax,%rcx,4), %rdx
movq %rdx, 0x10(%rsp)
movb 0x8(%rax,%rcx,4), %r13b
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x1a80e(%rip), %r12     # 0x315c2
movq %r12, %rsi
movq %r12, %rdx
callq 0xc45c
leaq 0x98(%rsp), %rax
movq %rax, 0x88(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xc45c
leaq 0xb8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xc45c
movl $0x2, %edx
leaq 0x120(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
leaq 0xb(%rsp), %rcx
callq 0x292e8
xorpd %xmm0, %xmm0
leaq 0xc8(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x40(%rsp), %rdx
movq %r12, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %rax
pushq %rax
pushq %rax
pushq %rax
callq 0x28a76
addq $0x20, %rsp
movq %r12, %rdi
movq %r14, %r12
callq 0xe7ca
movq $-0x40, %rbp
leaq 0xb8(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x16e74
movq (%r14), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r14
addq $0x20, %rbp
jne 0x16e60
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x16e9a
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5340
movslq 0xc(%rsp), %rax
testb $0x1, %r13b
movq %r12, %r14
je 0x16f1f
movq 0x148(%r14), %rcx
movq (%rcx,%rax,8), %rax
movq (%rax), %rbp
movq 0x8(%rax), %rdx
subq %rbp, %rdx
sarq $0x3, %rdx
movabsq $0x2e8ba2e8ba2e8ba3, %rax # imm = 0x2E8BA2E8BA2E8BA3
imulq %rax, %rdx
movq 0x10(%rsp), %rsi
cmpq %rsi, %rdx
leaq 0xd0(%rsp), %r12
jbe 0x1710b
imulq $0x58, %rsi, %r13
leaq 0x8(,%r13), %rsi
addq %rbp, %rsi
movl -0x8(%rsi), %eax
movl %eax, 0xc8(%rsp)
movq %r12, %rdi
callq 0x51c0
addq %rbp, %r13
addq $0x28, %r13
leaq 0xf0(%rsp), %rdi
movq %r13, %rsi
callq 0xa67a
jmp 0x16f94
movq 0x150(%r14), %rcx
movq (%rcx,%rax,8), %rax
movq (%rax), %rbp
movq 0x8(%rax), %rdx
subq %rbp, %rdx
sarq $0x3, %rdx
movabsq $0x2e8ba2e8ba2e8ba3, %rax # imm = 0x2E8BA2E8BA2E8BA3
imulq %rax, %rdx
movq 0x10(%rsp), %rsi
cmpq %rsi, %rdx
leaq 0xd0(%rsp), %r12
jbe 0x1710b
imulq $0x58, %rsi, %r13
leaq 0x8(,%r13), %rsi
addq %rbp, %rsi
movl -0x8(%rsi), %eax
movl %eax, 0xc8(%rsp)
movq %r12, %rdi
callq 0x51c0
addq %rbp, %r13
addq $0x28, %r13
leaq 0xf0(%rsp), %rdi
movq %r13, %rsi
callq 0xa67a
imulq $0x58, 0x10(%rsp), %rax
movq 0x50(%rbp,%rax), %rcx
movq %rcx, 0x48(%r12)
movups 0x40(%rbp,%rax), %xmm0
movups %xmm0, 0x38(%r12)
movsd 0x80(%rsp), %xmm0
ucomisd 0x118(%rsp), %xmm0
ja 0x16fd5
leaq 0x60(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x28b1a
leaq 0xf0(%rsp), %rdi
callq 0xe7ca
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x17007
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x5340
incq %r15
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r12, %rcx
cmpq %r15, %rcx
leaq 0x88(%rsp), %rbp
ja 0x16d83
movq 0x24f8f(%rip), %r15     # 0x3bfd0
movq 0x78(%rsp), %r13
movl 0xc(%rsp), %ecx
jmp 0x17051
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $-0x1, %ecx
je 0x17076
cmpl (%r14), %ecx
jge 0x17076
movq %r14, %rdi
movl 0x1c(%rsp), %esi
movl %r13d, %edx
leaq 0x60(%rsp), %r8
movq 0x38(%rsp), %r9
callq 0x150b8
jmp 0x170b1
movl $0x2b, %edx
movq %r15, %rdi
leaq 0x1a54c(%rip), %rsi     # 0x315d1
callq 0x53a0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %r15, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
leaq 0x60(%rsp), %rdi
callq 0x28958
incq %r13
movslq 0x268(%r14), %rax
cmpq %rax, %r13
jl 0x16d42
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x170e5
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movq 0x38(%rsp), %rdx
incq %rdx
cmpl 0x18(%rsp), %edx
jne 0x16cdc
movb $0x1, %al
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a9b2(%rip), %rdi     # 0x31ac4
xorl %eax, %eax
callq 0x5490
jmp 0x17136
jmp 0x171d9
movq %rax, %r14
xorl %eax, %eax
jmp 0x17181
movq %rax, %r14
jmp 0x1714e
movq %rax, %r14
xorl %eax, %eax
movq %rbp, %rbx
jmp 0x17181
movq %rax, %r14
jmp 0x171e9
movq %rax, %r14
leaq 0x120(%rsp), %rdi
callq 0xe7ca
leaq 0xb8(%rsp), %r15
xorl %r12d, %r12d
movq 0xa8(%rsp,%r12), %rdi
leaq (%r15,%r12), %rax
cmpq %rdi, %rax
je 0x17175
movq (%rax), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r12
cmpq $-0x40, %r12
jne 0x17159
movb $0x1, %al
cmpq %rbx, %rbp
sete %cl
orb %al, %cl
jne 0x171bb
addq $-0x10, %rbx
leaq 0x88(%rsp), %r15
movq -0x10(%rbx), %rdi
cmpq %rdi, %rbx
je 0x171ab
movq (%rbx), %rsi
incq %rsi
callq 0x5340
leaq -0x20(%rbx), %rax
addq $-0x10, %rbx
cmpq %r15, %rbx
movq %rax, %rbx
jne 0x17197
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x171e9
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x171e9
movq %rax, %r14
leaq 0xc8(%rsp), %rdi
callq 0x28b44
leaq 0x60(%rsp), %rdi
callq 0x28958
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1720a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movq %r14, %rdi
callq 0x55c0