// File: medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::MatchingSingleClusterDirectly(int, int, int, int, int, std::vector<DiploidVariant, std::allocator<DiploidVariant>>&)
bool WholeGenome::MatchingSingleClusterDirectly(int cluster_index, 
    int thread_index, 
    int mode_index, 
    int threshold_index, 
    int chr_id,
    vector<DiploidVariant> & variant_list){
    //cout << "direct match : " << variant_list.size() << endl;
    map<int, vector<DiploidVariant>> separate_var_list_map[2];
    for (int i = 0; i < variant_list.size(); i++) {
        int flag = 0;
        if (variant_list[i].flag) flag = 1; // flag indicate if the variant is from ref set(0) or query set(1)
        int pos = variant_list[i].pos;

        if(separate_var_list_map[flag].find(pos) == separate_var_list_map[flag].end()){
            separate_var_list_map[flag][pos] = vector<DiploidVariant>({variant_list[i]});
        }else{
            separate_var_list_map[flag][pos].push_back(variant_list[i]);
        }
    }

    //int match_mode = GetMatchmodeFromModeIndex(mode_index);

    for(auto baseline_it = separate_var_list_map[0].begin(); baseline_it != separate_var_list_map[0].end(); ++baseline_it){
        int pos = baseline_it->first;
        if(separate_var_list_map[1].find(pos) != separate_var_list_map[1].end()){
            vector<DiploidVariant> baseline_var_list = baseline_it->second;
            vector<DiploidVariant> query_var_list = separate_var_list_map[1][pos];
            for(auto baseline_var : baseline_var_list){
                for(auto query_var : query_var_list){
                    if(baseline_var == query_var){
                        DiploidVariant tv = baseline_var;
                        string match_record = chrname_by_chrid[chr_id] + "\t" + to_string(tv.pos+1) + "\t" + tv.ref + "\t" + tv.alts[0];
                        if(tv.multi_alts) match_record += "/" + tv.alts[1];
                        match_record += "\t.\t.\t.\t.\t.\n";
                        int edit_distance = CalculateEditDistance(tv, 0, 0);
                        match_records_by_mode_by_thread[thread_index][mode_index]->push_back(match_record);
                        baseline_total_match_num[thread_index][threshold_index]->at(mode_index)++;
                        query_total_match_num[thread_index][threshold_index]->at(mode_index)++;

                        baseline_total_edit_distance[thread_index][threshold_index]->at(mode_index) += edit_distance;
                        query_total_edit_distance[thread_index][threshold_index]->at(mode_index) += edit_distance;
                        break;
                    }
                }
            }
        }
    } 
    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x500, %rsp            # imm = 0x500
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x400(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, %rcx
addq $0x60, %rcx
movq %rcx, -0x3f8(%rbp)
movq %rax, -0x3f0(%rbp)
movq -0x3f0(%rbp), %rdi
movq %rdi, -0x408(%rbp)
callq 0x35800
movq -0x408(%rbp), %rax
movq -0x3f8(%rbp), %rcx
addq $0x30, %rax
cmpq %rcx, %rax
movq %rax, -0x3f0(%rbp)
jne 0x277bb
movl $0x0, -0x94(%rbp)
movslq -0x94(%rbp), %rax
movq %rax, -0x410(%rbp)
movq 0x10(%rbp), %rdi
callq 0x335b0
movq %rax, %rcx
movq -0x410(%rbp), %rax
cmpq %rcx, %rax
jae 0x27b6f
movl $0x0, -0x98(%rbp)
movq 0x10(%rbp), %rdi
movslq -0x94(%rbp), %rsi
callq 0x33de0
testb $0x1, 0x4c(%rax)
je 0x2784a
movl $0x1, -0x98(%rbp)
movq 0x10(%rbp), %rdi
movslq -0x94(%rbp), %rsi
callq 0x33de0
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
movslq -0x98(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x90(%rbp,%rax), %rdi
leaq -0x9c(%rbp), %rsi
callq 0x35850
movq %rax, -0x418(%rbp)
jmp 0x2788e
movq -0x418(%rbp), %rax
movq %rax, -0xa8(%rbp)
movslq -0x98(%rbp), %rax
leaq -0x90(%rbp), %rdi
imulq $0x30, %rax, %rax
addq %rax, %rdi
callq 0x35880
movq %rax, -0xc0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x35820
testb $0x1, %al
jne 0x278d9
jmp 0x27b0a
leaq -0x140(%rbp), %rax
movq %rax, -0x420(%rbp)
movq %rax, -0x148(%rbp)
movq 0x10(%rbp), %rdi
movslq -0x94(%rbp), %rsi
callq 0x33de0
movq -0x420(%rbp), %rdi
movq %rax, %rsi
callq 0x340a0
jmp 0x2790f
leaq -0x140(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq $0x1, -0xe0(%rbp)
leaq -0x149(%rbp), %rdi
movq %rdi, -0x428(%rbp)
callq 0x358b0
movq -0x428(%rbp), %rcx
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
leaq -0xd8(%rbp), %rdi
callq 0x358d0
jmp 0x2795e
movslq -0x98(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x90(%rbp,%rax), %rdi
leaq -0x9c(%rbp), %rsi
callq 0x35950
movq %rax, -0x430(%rbp)
jmp 0x2798a
movq -0x430(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x35a30
leaq -0xd8(%rbp), %rdi
callq 0x32680
leaq -0x149(%rbp), %rdi
callq 0x35a60
leaq -0x140(%rbp), %rax
movq %rax, -0x440(%rbp)
addq $0x58, %rax
movq %rax, -0x438(%rbp)
movq -0x438(%rbp), %rdi
addq $-0x58, %rdi
movq %rdi, -0x448(%rbp)
callq 0x32c60
movq -0x440(%rbp), %rcx
movq -0x448(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x438(%rbp)
jne 0x279ce
jmp 0x27b59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x28365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
movq -0x148(%rbp), %rax
leaq -0x140(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x450(%rbp)
je 0x27a78
movq -0x450(%rbp), %rdi
addq $-0x58, %rdi
movq %rdi, -0x458(%rbp)
callq 0x32c60
movq -0x458(%rbp), %rax
leaq -0x140(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x450(%rbp)
jne 0x27a47
jmp 0x28365
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x27aaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x32680
leaq -0x149(%rbp), %rdi
callq 0x35a60
leaq -0x140(%rbp), %rax
movq %rax, -0x468(%rbp)
addq $0x58, %rax
movq %rax, -0x460(%rbp)
movq -0x460(%rbp), %rdi
addq $-0x58, %rdi
movq %rdi, -0x470(%rbp)
callq 0x32c60
movq -0x468(%rbp), %rcx
movq -0x470(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x460(%rbp)
jne 0x27ad4
jmp 0x28365
movslq -0x98(%rbp), %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
leaq -0x90(%rbp,%rax), %rdi
leaq -0x9c(%rbp), %rsi
callq 0x35950
movq %rax, -0x478(%rbp)
jmp 0x27b36
movq 0x10(%rbp), %rdi
movslq -0x94(%rbp), %rsi
callq 0x33de0
movq -0x478(%rbp), %rdi
movq %rax, %rsi
callq 0x32bf0
jmp 0x27b57
jmp 0x27b59
jmp 0x27b5b
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x277f6
leaq -0x90(%rbp), %rdi
callq 0x35a80
movq %rax, -0x158(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x35880
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x35ab0
testb $0x1, %al
jne 0x27bb1
jmp 0x282ff
leaq -0x158(%rbp), %rdi
callq 0x35ae0
movl (%rax), %eax
movl %eax, -0x164(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x164(%rbp), %rsi
callq 0x35850
movq %rax, -0x480(%rbp)
jmp 0x27bde
movq -0x480(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x90(%rbp), %rdi
addq $0x30, %rdi
callq 0x35880
movq %rax, -0x178(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x35ab0
testb $0x1, %al
jne 0x27c1f
jmp 0x282ec
leaq -0x158(%rbp), %rdi
callq 0x35ae0
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x190(%rbp), %rdi
callq 0x35b00
jmp 0x27c40
leaq -0x60(%rbp), %rdi
leaq -0x164(%rbp), %rsi
callq 0x35950
movq %rax, -0x488(%rbp)
jmp 0x27c59
movq -0x488(%rbp), %rsi
leaq -0x1a8(%rbp), %rdi
callq 0x35b00
jmp 0x27c6e
leaq -0x190(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x1b0(%rbp), %rdi
callq 0x33d60
movq %rax, -0x1b8(%rbp)
movq -0x1b0(%rbp), %rdi
callq 0x33d90
movq %rax, -0x1c0(%rbp)
leaq -0x1b8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0x35bf0
testb $0x1, %al
jne 0x27cbe
jmp 0x282b8
leaq -0x1b8(%rbp), %rdi
callq 0x35c30
movq %rax, %rsi
leaq -0x218(%rbp), %rdi
callq 0x340a0
jmp 0x27cdb
leaq -0x1a8(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x220(%rbp), %rdi
callq 0x33d60
movq %rax, -0x228(%rbp)
movq -0x220(%rbp), %rdi
callq 0x33d90
movq %rax, -0x230(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x35bf0
testb $0x1, %al
jne 0x27d2b
jmp 0x2828d
leaq -0x228(%rbp), %rdi
callq 0x35c30
movq %rax, %rsi
leaq -0x288(%rbp), %rdi
callq 0x340a0
jmp 0x27d48
leaq -0x218(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x33e50
movb %al, -0x489(%rbp)
jmp 0x27d63
movb -0x489(%rbp), %al
testb $0x1, %al
jne 0x27d72
jmp 0x28248
leaq -0x2e0(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x340a0
jmp 0x27d87
movq -0x400(%rbp), %rdi
addq $0xb8, %rdi
leaq -0x24(%rbp), %rsi
callq 0x32770
movq %rax, -0x498(%rbp)
jmp 0x27da7
movq -0x498(%rbp), %rsi
leaq 0x2d7e8(%rip), %rdx     # 0x5559d
leaq -0x3a0(%rbp), %rdi
callq 0xe200
jmp 0x27dc3
movl -0x2e0(%rbp), %esi
incl %esi
leaq -0x3c0(%rbp), %rdi
callq 0xb190
jmp 0x27dd9
leaq -0x380(%rbp), %rdi
leaq -0x3a0(%rbp), %rsi
leaq -0x3c0(%rbp), %rdx
callq 0xde60
jmp 0x27df5
leaq 0x2d7a1(%rip), %rdx     # 0x5559d
leaq -0x360(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0xb0f0
jmp 0x27e11
leaq -0x2d8(%rbp), %rdx
leaq -0x340(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0xe1b0
jmp 0x27e2d
leaq 0x2d769(%rip), %rdx     # 0x5559d
leaq -0x320(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0xb0f0
jmp 0x27e49
leaq -0x2b8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9080
movq %rax, %rdx
leaq -0x300(%rbp), %rdi
leaq -0x320(%rbp), %rsi
callq 0xe1b0
jmp 0x27e71
leaq -0x320(%rbp), %rdi
callq 0x6828
leaq -0x340(%rbp), %rdi
callq 0x6828
leaq -0x360(%rbp), %rdi
callq 0x6828
leaq -0x380(%rbp), %rdi
callq 0x6828
leaq -0x3c0(%rbp), %rdi
callq 0x6828
leaq -0x3a0(%rbp), %rdi
callq 0x6828
testb $0x1, -0x29f(%rbp)
je 0x28088
leaq -0x2b8(%rbp), %rdi
movl $0x1, %esi
callq 0x9080
movq %rax, %rdx
leaq 0x2d6be(%rip), %rsi     # 0x5559f
leaq -0x3e0(%rbp), %rdi
callq 0x10610
jmp 0x27eef
leaq -0x300(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
callq 0x6560
jmp 0x27f04
leaq -0x3e0(%rbp), %rdi
callq 0x6828
jmp 0x28088
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x282de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x282d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x282aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2827f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2823a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2803d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x28031
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x28025
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x28019
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2800d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x320(%rbp), %rdi
callq 0x6828
leaq -0x340(%rbp), %rdi
callq 0x6828
leaq -0x360(%rbp), %rdi
callq 0x6828
leaq -0x380(%rbp), %rdi
callq 0x6828
leaq -0x3c0(%rbp), %rdi
callq 0x6828
leaq -0x3a0(%rbp), %rdi
callq 0x6828
jmp 0x2823a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
jmp 0x2822e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb0(%rbp)
movl %eax, -0xb4(%rbp)
leaq -0x3e0(%rbp), %rdi
callq 0x6828
jmp 0x2822e
leaq 0x2d512(%rip), %rsi     # 0x555a1
leaq -0x300(%rbp), %rdi
callq 0x6410
jmp 0x2809d
movq -0x400(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x20ac0
movl %eax, -0x49c(%rbp)
jmp 0x280bc
movq -0x400(%rbp), %rax
movl -0x49c(%rbp), %ecx
movl %ecx, -0x3e4(%rbp)
movq 0x178(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x300(%rbp), %rsi
callq 0x17750
jmp 0x280f4
movq -0x400(%rbp), %rax
movq 0x180(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x34130
movq %rax, -0x4a8(%rbp)
jmp 0x28124
movq -0x400(%rbp), %rax
movq -0x4a8(%rbp), %rcx
movl (%rcx), %edx
incl %edx
movl %edx, (%rcx)
movq 0x188(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x34130
movq %rax, -0x4b0(%rbp)
jmp 0x28161
movq -0x400(%rbp), %rax
movq -0x4b0(%rbp), %rcx
movl (%rcx), %edx
incl %edx
movl %edx, (%rcx)
movl -0x3e4(%rbp), %ecx
movl %ecx, -0x4bc(%rbp)
movq 0x190(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x34130
movq %rax, -0x4b8(%rbp)
jmp 0x281aa
movq -0x400(%rbp), %rax
movq -0x4b8(%rbp), %rcx
movl -0x4bc(%rbp), %esi
movl (%rcx), %edx
addl %esi, %edx
movl %edx, (%rcx)
movl -0x3e4(%rbp), %ecx
movl %ecx, -0x4cc(%rbp)
movq 0x198(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x34130
movq %rax, -0x4c8(%rbp)
jmp 0x281f9
movq -0x4c8(%rbp), %rax
movl -0x4cc(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
movl $0xa, -0x3e8(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x6828
leaq -0x2e0(%rbp), %rdi
callq 0x32c60
jmp 0x28252
leaq -0x300(%rbp), %rdi
callq 0x6828
leaq -0x2e0(%rbp), %rdi
callq 0x32c60
jmp 0x2827f
movl $0x0, -0x3e8(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x32c60
movl -0x3e8(%rbp), %eax
testl %eax, %eax
je 0x2826c
jmp 0x2826a
jmp 0x2828d
jmp 0x2826e
leaq -0x228(%rbp), %rdi
callq 0x35c50
jmp 0x27d0f
leaq -0x288(%rbp), %rdi
callq 0x32c60
jmp 0x282aa
leaq -0x218(%rbp), %rdi
callq 0x32c60
leaq -0x1b8(%rbp), %rdi
callq 0x35c50
jmp 0x27ca2
leaq -0x218(%rbp), %rdi
callq 0x32c60
jmp 0x282d2
leaq -0x1a8(%rbp), %rdi
callq 0x32680
leaq -0x190(%rbp), %rdi
callq 0x32680
jmp 0x282ec
leaq -0x1a8(%rbp), %rdi
callq 0x32680
leaq -0x190(%rbp), %rdi
callq 0x32680
jmp 0x28365
jmp 0x282ee
leaq -0x158(%rbp), %rdi
callq 0x35c70
jmp 0x27b82
movb $0x1, -0x1(%rbp)
movl $0x1, -0x3e8(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0x4e0(%rbp)
addq $0x60, %rax
movq %rax, -0x4d8(%rbp)
movq -0x4d8(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x4e8(%rbp)
callq 0x35ca0
movq -0x4e0(%rbp), %rcx
movq -0x4e8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x4d8(%rbp)
jne 0x28326
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x500, %rsp            # imm = 0x500
popq %rbp
retq
leaq -0x90(%rbp), %rax
movq %rax, -0x4f8(%rbp)
addq $0x60, %rax
movq %rax, -0x4f0(%rbp)
movq -0x4f0(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x500(%rbp)
callq 0x35ca0
movq -0x4f8(%rbp), %rcx
movq -0x500(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x4f0(%rbp)
jne 0x2837e
jmp 0x283b1
movq -0xb0(%rbp), %rdi
callq 0x6750
nopl (%rax)