// File: /workspace/github_cpp_makefile_star2_O3/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 $0x128, %rsp            # imm = 0x128
movl %ecx, 0xc(%rsp)
movl %edx, 0x8(%rsp)
cmpl %edx, %esi
jge 0x16f36
movq %rdi, %rbx
movslq %esi, %rdx
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
movq 0x264a2(%rip), %r15     # 0x3cfd0
leaq 0x1aabd(%rip), %r12     # 0x315f2
leaq 0x30(%rsp), %rbp
movq 0x160(%rbx), %rax
movq 0x168(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r14, %rcx
cmpq %rdx, %rcx
jbe 0x16f36
movq %rdx, 0x28(%rsp)
leaq (%rdx,%rdx,2), %rcx
leaq (%rax,%rcx,8), %rsi
leaq 0x10(%rsp), %rdi
callq 0x28df4
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
subq %rdi, %rax
sarq $0x2, %rax
imulq %r14, %rax
cmpq $0x2, %rax
jb 0x16f12
cmpl $0x0, 0x268(%rbx)
jle 0x16f12
xorl %r13d, %r13d
movq 0x250(%rbx), %rax
movsd (%rax,%r13,8), %xmm0
movsd %xmm0, 0x70(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x16eb5
movq %r13, 0x68(%rsp)
xorl %r13d, %r13d
leaq (,%r13,2), %rcx
addq %r13, %rcx
movsbl (%rax,%rcx,4), %edx
movl %edx, 0x4(%rsp)
movslq 0x4(%rax,%rcx,4), %r15
movb 0x8(%rax,%rcx,4), %r14b
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xc3da
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xc3da
leaq 0xa8(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x98(%rsp), %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xc3da
movl $0x2, %edx
leaq 0x110(%rsp), %r12
movq %r12, %rdi
leaq 0x78(%rsp), %rsi
leaq 0x3(%rsp), %rcx
callq 0x28e82
xorpd %xmm0, %xmm0
leaq 0xb8(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq %rbp, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %eax, %eax
pushq %rax
pushq %rax
pushq %rax
pushq %rax
callq 0x2860c
addq $0x20, %rsp
movq %rbx, %rbp
movq %r12, %rdi
callq 0xe71c
movq $-0x40, %r12
leaq 0xa8(%rsp), %rbx
movq -0x10(%rbx), %rdi
cmpq %rdi, %rbx
je 0x16cce
movq (%rbx), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %rbx
addq $0x20, %r12
jne 0x16cba
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x16cf4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5340
movslq 0x4(%rsp), %rax
testb $0x1, %r14b
movq %rbp, %rbx
je 0x16d71
movq 0x148(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movq (%rax), %r12
movq 0x8(%rax), %rdx
subq %r12, %rdx
sarq $0x3, %rdx
movabsq $0x2e8ba2e8ba2e8ba3, %rax # imm = 0x2E8BA2E8BA2E8BA3
imulq %rax, %rdx
cmpq %r15, %rdx
leaq 0xc0(%rsp), %rbp
jbe 0x16f4a
imulq $0x58, %r15, %r14
leaq (%r12,%r14), %rsi
addq $0x8, %rsi
movl -0x8(%rsi), %eax
movl %eax, 0xb8(%rsp)
movq %rbp, %rdi
callq 0x51c0
addq %r12, %r14
addq $0x28, %r14
leaq 0xe0(%rsp), %rdi
movq %r14, %rsi
callq 0xa5da
jmp 0x16dde
movq 0x150(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movq (%rax), %r12
movq 0x8(%rax), %rdx
subq %r12, %rdx
sarq $0x3, %rdx
movabsq $0x2e8ba2e8ba2e8ba3, %rax # imm = 0x2E8BA2E8BA2E8BA3
imulq %rax, %rdx
cmpq %r15, %rdx
leaq 0xc0(%rsp), %rbp
jbe 0x16f4a
imulq $0x58, %r15, %r14
leaq (%r12,%r14), %rsi
addq $0x8, %rsi
movl -0x8(%rsi), %eax
movl %eax, 0xb8(%rsp)
movq %rbp, %rdi
callq 0x51c0
addq %r12, %r14
addq $0x28, %r14
leaq 0xe0(%rsp), %rdi
movq %r14, %rsi
callq 0xa5da
imulq $0x58, %r15, %rax
movq 0x50(%r12,%rax), %rcx
movq %rcx, 0x48(%rbp)
movups 0x40(%r12,%rax), %xmm0
movups %xmm0, 0x38(%rbp)
movsd 0x70(%rsp), %xmm0
ucomisd 0x108(%rsp), %xmm0
ja 0x16e18
leaq 0x50(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x286b0
leaq 0xe0(%rsp), %rdi
callq 0xe71c
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x16e4a
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x5340
incq %r13
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r14, %rcx
cmpq %r13, %rcx
leaq 0x1a77c(%rip), %r12     # 0x315f2
leaq 0x30(%rsp), %rbp
ja 0x16be0
movl 0x4(%rsp), %ecx
cmpb $-0x1, %cl
movq 0x26141(%rip), %r15     # 0x3cfd0
movq 0x68(%rsp), %r13
je 0x16eb5
cmpl %ecx, (%rbx)
jle 0x16eb5
movq %rbx, %rdi
movl 0xc(%rsp), %esi
movl %r13d, %edx
leaq 0x50(%rsp), %r8
movq 0x28(%rsp), %r9
callq 0x14f7e
jmp 0x16ef0
movl $0x2b, %edx
movq %r15, %rdi
leaq 0x1a73d(%rip), %rsi     # 0x31601
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 0x50(%rsp), %rdi
callq 0x284ec
incq %r13
movslq 0x268(%rbx), %rax
cmpq %rax, %r13
jl 0x16ba2
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x16f24
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movq 0x28(%rsp), %rdx
incq %rdx
cmpl 0x8(%rsp), %edx
jne 0x16b3a
movb $0x1, %al
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1aba3(%rip), %rdi     # 0x31af4
movq %r15, %rsi
xorl %eax, %eax
callq 0x5490
jmp 0x16f8e
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x16fd4
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x16fd4
movq %rax, %rbx
jmp 0x16fd4
movq %rax, %rbx
jmp 0x16fa3
movq %rax, %rbx
jmp 0x17004
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xe71c
leaq 0xa8(%rsp), %r14
xorl %r15d, %r15d
movq 0x98(%rsp,%r15), %rdi
leaq (%r14,%r15), %rax
cmpq %rdi, %rax
je 0x16fca
movq (%rax), %rsi
incq %rsi
callq 0x5340
addq $-0x20, %r15
cmpq $-0x40, %r15
jne 0x16fae
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x17004
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x17004
jmp 0x16ff4
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x286da
leaq 0x50(%rsp), %rdi
callq 0x284ec
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x17025
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movq %rbx, %rdi
callq 0x55c0
nop