// File: 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
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x188(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x21783
movq -0x188(%rbp), %rdi
movslq -0x18(%rbp), %rax
movq %rax, -0x190(%rbp)
addq $0x160, %rdi            # imm = 0x160
callq 0x338b0
movq %rax, %rcx
movq -0x190(%rbp), %rax
cmpq %rcx, %rax
jb 0x21167
jmp 0x21783
movq -0x188(%rbp), %rdi
addq $0x160, %rdi            # imm = 0x160
movslq -0x18(%rbp), %rsi
callq 0x34620
movq %rax, %rsi
leaq -0x30(%rbp), %rdi
callq 0x34640
leaq -0x30(%rbp), %rdi
callq 0x33a90
cmpq $0x1, %rax
ja 0x211a5
movl $0x4, -0x34(%rbp)
jmp 0x2175f
movl $0x0, -0x38(%rbp)
movq -0x188(%rbp), %rcx
movl -0x38(%rbp), %eax
cmpl 0x268(%rcx), %eax
jge 0x21758
movq -0x188(%rbp), %rdi
addq $0x250, %rdi            # imm = 0x250
movslq -0x38(%rbp), %rsi
callq 0x34730
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x322d0
movl $0xffffffff, -0x5c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x60(%rbp)
movslq -0x60(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x33a90
movq %rax, %rcx
movq -0x198(%rbp), %rax
cmpq %rcx, %rax
jae 0x21698
movslq -0x60(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x34750
movl 0x8(%rax), %ecx
movl %ecx, -0x68(%rbp)
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movsbl -0x70(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x74(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x6760
movq -0x1a0(%rbp), %rdx
leaq 0x34336(%rip), %rsi     # 0x5559e
leaq -0xf0(%rbp), %rdi
callq 0x9680
jmp 0x21276
movb $0x1, -0x17b(%rbp)
leaq -0x170(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq %rax, -0x178(%rbp)
leaq -0x179(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x6760
movq -0x1b0(%rbp), %rdi
movq -0x1a8(%rbp), %rdx
leaq 0x342e4(%rip), %rsi     # 0x5559e
callq 0x9680
jmp 0x212c1
leaq -0x150(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq %rax, -0x178(%rbp)
leaq -0x17a(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x6760
movq -0x1c0(%rbp), %rdi
movq -0x1b8(%rbp), %rdx
leaq 0x342a0(%rip), %rsi     # 0x5559e
callq 0x9680
jmp 0x21305
movb $0x0, -0x17b(%rbp)
leaq -0x170(%rbp), %rax
movq %rax, -0x130(%rbp)
movq $0x2, -0x128(%rbp)
leaq -0x17c(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x13420
movq -0x1c8(%rbp), %rcx
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rdx
leaq -0x120(%rbp), %rdi
callq 0x34770
jmp 0x2135b
movq %rsp, %rax
movl $0x0, 0x18(%rax)
movl $0x0, 0x10(%rax)
movl $0x0, 0x8(%rax)
movl $0x0, (%rax)
leaq -0xd0(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq -0xf0(%rbp), %rdx
leaq -0x120(%rbp), %rcx
xorl %r9d, %r9d
xorps %xmm0, %xmm0
movl %r9d, %r8d
callq 0x32ac0
jmp 0x213a3
leaq -0x120(%rbp), %rdi
callq 0x13370
leaq -0x17c(%rbp), %rdi
callq 0x14fa0
leaq -0x170(%rbp), %rax
movq %rax, -0x1d8(%rbp)
addq $0x40, %rax
movq %rax, -0x1d0(%rbp)
movq -0x1d0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x6828
movq -0x1d8(%rbp), %rcx
movq -0x1e0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1d0(%rbp)
jne 0x213d4
leaq -0x17a(%rbp), %rdi
callq 0x64b0
leaq -0x179(%rbp), %rdi
callq 0x64b0
leaq -0xf0(%rbp), %rdi
callq 0x6828
leaq -0xf1(%rbp), %rdi
callq 0x64b0
testb $0x1, -0x68(%rbp)
je 0x21600
movq -0x188(%rbp), %rax
movq 0x148(%rax), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x74(%rbp), %rsi
callq 0x347f0
movq %rax, -0x1e8(%rbp)
jmp 0x21467
movq -0x1e8(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x34830
jmp 0x2147c
jmp 0x2163f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x215cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x2155c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x21550
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x214f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x13370
leaq -0x17c(%rbp), %rdi
callq 0x14fa0
leaq -0x170(%rbp), %rax
movq %rax, -0x1f8(%rbp)
addq $0x40, %rax
movq %rax, -0x1f0(%rbp)
movq -0x1f0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x200(%rbp)
callq 0x6828
movq -0x1f8(%rbp), %rcx
movq -0x200(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1f0(%rbp)
jne 0x2151d
jmp 0x21550
leaq -0x17a(%rbp), %rdi
callq 0x64b0
leaq -0x179(%rbp), %rdi
callq 0x64b0
testb $0x1, -0x17b(%rbp)
jne 0x21573
jmp 0x215c0
movq -0x178(%rbp), %rax
leaq -0x170(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x208(%rbp)
je 0x215be
movq -0x208(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x210(%rbp)
callq 0x6828
movq -0x210(%rbp), %rax
leaq -0x170(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x208(%rbp)
jne 0x2158d
jmp 0x215c0
leaq -0xf0(%rbp), %rdi
callq 0x6828
leaq -0xf1(%rbp), %rdi
callq 0x64b0
jmp 0x21744
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x32c60
jmp 0x21744
movq -0x188(%rbp), %rax
movq 0x150(%rax), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x74(%rbp), %rsi
callq 0x347f0
movq %rax, -0x218(%rbp)
jmp 0x21628
movq -0x218(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x34830
jmp 0x2163d
jmp 0x2163f
movsd -0x80(%rbp), %xmm1
movsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x21658
movl $0xa, -0x34(%rbp)
jmp 0x21671
leaq -0x58(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x32bf0
jmp 0x2166a
movl $0x0, -0x34(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x32c60
movl -0x34(%rbp), %eax
testl %eax, %eax
je 0x21688
jmp 0x21686
jmp 0x2168a
jmp 0x2168a
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x211f9
cmpl $-0x1, -0x5c(%rbp)
je 0x216ac
movq -0x188(%rbp), %rcx
movl -0x5c(%rbp), %eax
cmpl (%rcx), %eax
jl 0x216fa
movq 0x52905(%rip), %rdi     # 0x73fb8
leaq 0x33ef3(%rip), %rsi     # 0x555ad
callq 0x6420
movq %rax, -0x220(%rbp)
jmp 0x216c8
movq -0x220(%rbp), %rdi
movq 0x528aa(%rip), %rsi     # 0x73f80
callq 0x6480
jmp 0x216dd
movl $0x7, -0x34(%rbp)
jmp 0x21720
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x21744
movq -0x188(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x38(%rbp), %edx
movl -0x5c(%rbp), %ecx
movl -0x18(%rbp), %r9d
leaq -0x58(%rbp), %r8
callq 0x1f5e0
jmp 0x21719
movl $0x0, -0x34(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x32680
movl -0x34(%rbp), %eax
testl %eax, %eax
je 0x21734
jmp 0x21732
jmp 0x21736
jmp 0x21736
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x211ac
leaq -0x58(%rbp), %rdi
callq 0x32680
leaq -0x30(%rbp), %rdi
callq 0x348a0
jmp 0x21790
movl $0x0, -0x34(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x348a0
movl -0x34(%rbp), %eax
testl %eax, %eax
je 0x21773
jmp 0x21771
jmp 0x21775
jmp 0x21775
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x21129
movb $0x1, %al
andb $0x1, %al
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
movq -0x100(%rbp), %rdi
callq 0x6750
nopl (%rax)