// File: /workspace/github_cpp_makefile_star2_O1/medvedevgroup[P]varmatch/src/wholegenome.cpp
// Function: WholeGenome::ReadWholeGenomeVariant(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
int WholeGenome::ReadWholeGenomeVariant(string filename, bool flag){
    int total_num = 0;
    int long_num = 0;
    double QUAL_LOWER_BOUND = 0.1;

	ifstream vcf_file;
	vcf_file.open(filename.c_str());
	if (!vcf_file.good()) {
		cout << "[VarMatch] Error: can not open vcf file" << endl;
		return -1;
	}

    vector<float> quality_list;

	int genotype_index = -1;
	char genotype_separator = '/';
	//int genome_sequence_length = genome_sequence.length();
	while (!vcf_file.eof()) { // alternative way is vcf_file != NULL
		string line;
		getline(vcf_file, line, '\n');
		// check ineligible lines
		//dout << line << endl;
		if ((int)line.length() <= 1) continue;
		//if (line.find_first_not_of(' ') == std::string::npos) continue;

		if (line[0] == '#') {
			continue;
		}
		auto columns = split(line, '\t');
		if (columns.size() < 10) {
			if(match_mode_indicator != 1){
                cout << "[VarMatch] Warning: not enough information in VCF file for genotype matching." << endl;
                cout << "[VarMatch] \tAutomatically turn off genotype matching module " << filename << endl;
                match_mode_indicator = 1;
                //continue;
            }
            if(columns.size() < 6){
                cout << "[VarMatch] Warning: not enough information in VCF file for variant matching." << endl;
                cout << "[VarMatch] skip current variant: " << line << endl;
                continue;
            }
		}
		string chr_name = columns[0];
		auto pos = atoi(columns[1].c_str()) - 1; // 0-based coordinate

		auto ref = columns[3];
		auto alt_line = columns[4];
		//double quality = stod(columns[5]);

		double quality = 1.0;
		if(columns[5] != ".") quality = stod(columns[5]);

        if(flag){
            quality_list.push_back(quality);
        }

		ToUpper(ref);
		ToUpper(alt_line);

		bool is_heterozygous_variant = false;
		bool is_multi_alternatives = false;
        bool is_zero_one_var = false;
        
        vector<string> genotype_columns;
		
        if (match_mode_indicator != 1) { // match mode indicator is -1 or 0
			if (genotype_index < 0) {
                // change genotype index
                auto formats = split(columns[8], ':');
                for (int i = 0; i < formats.size(); i++) {
                    if (formats[i] == "GT") {
                        genotype_index = i;
                        break;
                    }
                }
                // if GT not found
                if(genotype_index < 0){
                    if(match_mode_indicator != 1 && match_mode_indicator != 1){
                        cout << "[VarMatch] Warning: VCF entry does not contain genotype information." << endl;
                        cout << "[VarMatch] \tAutomatically turn off genotype matching mode. " << endl;
                        match_mode_indicator = 1;
                    }
                }
			}

            
            if(match_mode_indicator != 1){

    			auto additionals = split(columns[9], ':');
                genotype_columns = split(additionals[genotype_index], genotype_separator);

                if(genotype_columns.size() != 2){
                    
                    if(genotype_separator == '/'){
                        genotype_separator = '|';
                    }else{
                        genotype_separator = '/';
                    }
                    genotype_columns = split(additionals[genotype_index], genotype_separator);
                }

    			// normalize format of genotype: sorted, separated by |
    			if (genotype_columns.size() != 2) {
    				cout << "[VarMatch] Warning: Unrecognized Genotype: " << additionals[genotype_index] << endl;
                    cout << "[VarMatch] \tAutomatically turn off genotype matching mode." << endl;
                    match_mode_indicator = 1;
    			}
    			else {
    				if (genotype_columns[0] != genotype_columns[1]) {
    					is_heterozygous_variant = true;
    				}
                    if (genotype_columns[1] == "0" && genotype_columns[0] == "0") {
                        //cout << "Skip Variants when both genotype is refernce allele: " << line << endl;   
                        continue;
                    }
                    if(genotype_columns[0] == "0" || genotype_columns[1] == "0"){
                        is_zero_one_var = true;
                    }
    			}
            }
		}

		vector<string> alt_list;
		if (alt_line.find(",") != std::string::npos) {
			alt_list = split(alt_line, ',');
			is_multi_alternatives = true;
		}
		else {
			alt_list.push_back(alt_line);
		}

        if(alt_list.size() > 2){
            if(match_mode_indicator != 1){
            vector<string> temp_alt_list = alt_list;
            alt_list.clear();
            for(int i = 0; i < 2; i++){
                int alt_indicator = stoi(genotype_columns[i]);
                if(alt_indicator == 0) continue;
                alt_list.push_back(temp_alt_list[alt_indicator-1]);
            }
            }else{
                vector<string> temp_alt_list = alt_list;
                alt_list.clear();
                alt_list.push_back(temp_alt_list[0]);
                alt_list.push_back(temp_alt_list[1]);
            }
        }

        int snp_ins = max(0, (int)alt_list[0].length() - (int)ref.length());
        int snp_del = max(0, (int)ref.length() - (int)alt_list[0].length());
        if(is_multi_alternatives){
            snp_ins = max(snp_ins, (int)alt_list[1].length() - (int)ref.length());
            snp_del = max(snp_del, (int)ref.length() - (int)alt_list[1].length());
        }

        if(snp_ins > VAR_LEN || snp_del > VAR_LEN){
            //dout << "[VarMatch] skip large INDEL with length > " << VAR_LEN << "| "<< line <<endl;
            long_num ++;
            continue;
        }

		DiploidVariant dv(pos, ref, alt_list, is_heterozygous_variant, is_multi_alternatives, snp_del, snp_ins, flag, quality, is_zero_one_var);
		//if (normalization) {
			//NormalizeDiploidVariant(dv);
		//}
        if(chrid_by_chrname.find(chr_name) != chrid_by_chrname.end()){
            int chr_id = chrid_by_chrname[chr_name];
            if(flag == false){
                ref_variant_by_chrid[chr_id]->push_back(dv);
                //baseline_variant_strings.push_back(line);
            }else{
                que_variant_by_chrid[chr_id]->push_back(dv);
                query_variant_strings.push_back(line);
            }
        }else{
            //cout << "[VarMatch] skip current variant as no corresponding reference genome sequence found." << endl;
            cout << "[VarMatch] Warning: variant skipped, no reference genome sequence found for chromosome name: " << chr_name << "." << endl;
            continue;
            int chr_id = chrname_dict[chr_name];
            if(flag == false){
                ref_variant_by_chrid[chr_id]->push_back(dv);
                //baseline_variant_strings.push_back(line);
            }else{
                que_variant_by_chrid[chr_id]->push_back(dv);
                query_variant_strings.push_back(line);
            }
        }

        total_num++;
	}
	vcf_file.close();

    if(flag){
        sort(quality_list.begin(), quality_list.end());
        auto qual_lower_it = lower_bound(quality_list.begin(), quality_list.end(), QUAL_LOWER_BOUND);
        int qual_lower_index = qual_lower_it - quality_list.begin();
        int rest_size = quality_list.size() - qual_lower_index;

        vector<float> temp_percentage_list;
        temp_percentage_list.push_back(0.0);
        threshold_list.push_back(0.0);
        
        for(int i = 1; i < per_list.size(); i++){
            int additional_index = (int)(rest_size * per_list[i]);
            int real_index = qual_lower_index + additional_index;
            if(real_index >= quality_list.size()) real_index = quality_list.size() - 1;
            double quality = quality_list[real_index];
            threshold_list.push_back(quality);

            auto quality_lowit = lower_bound(quality_list.begin(), quality_list.end(), quality);
            int quality_low_index = quality_lowit - quality_list.begin();
            // following program will retain variants >= quality threshold
            
            int quality_size = quality_low_index + 1; // counting number, +/- 1 does not matter
            if(quality_size > quality_list.size()) quality_size = quality_list.size();
            double percentage = (double)quality_size/ quality_list.size();
            temp_percentage_list.push_back(percentage);
        }
        threshold_num = threshold_list.size();
        // revice percentage
        per_list = temp_percentage_list;
    }
    //cout << flag << "," << total_num << "," << long_num << endl;
	return total_num;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3e8, %rsp            # imm = 0x3E8
movl %edx, 0x8(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x1e0(%rsp), %r14
movq %r14, %rdi
callq 0x5390
movq (%r15), %rsi
movq %r14, %rdi
movl $0x8, %edx
callq 0x5210
movq 0x1e0(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x200(%rsp,%rax)
je 0x126f1
movq 0x29928(%rip), %rbx     # 0x3bfd0
leaq 0x1eca5(%rip), %rsi     # 0x31354
movl $0x27, %edx
movq %rbx, %rdi
callq 0x53a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq 0x298f6(%rip), %rdi     # 0x3bfd0
callq 0x5040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x5240
jmp 0x138d0
movq %r15, 0x1c0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
movq 0x1e0(%rsp), %rax
movq -0x18(%rax), %rax
movl $0x0, 0x2c(%rsp)
testb $0x2, 0x200(%rsp,%rax)
jne 0x13594
leaq 0x40(%rsp), %r15
leaq 0x88(%rbx), %rax
movq %rax, 0x188(%rsp)
leaq 0x90(%rbx), %rax
movq %rax, 0x1b8(%rsp)
leaq 0x68(%rbx), %rax
movq %rax, 0x1b0(%rsp)
movb $0x2f, %al
movl %eax, 0x28(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
leaq 0x1e0(%rsp), %r12
leaq 0x30(%rsp), %r13
movq 0x29850(%rip), %rbp     # 0x3bfd0
movl $0x0, 0x2c(%rsp)
movq %r15, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x5600
cmpl $0x2, 0x38(%rsp)
jl 0x13543
movq 0x30(%rsp), %rax
cmpb $0x23, (%rax)
je 0x13543
leaq 0x100(%rsp), %rdi
movq %r13, %rsi
movl $0x9, %edx
callq 0x2f46e
movq 0x108(%rsp), %rax
subq 0x100(%rsp), %rax
cmpq $0x13f, %rax            # imm = 0x13F
ja 0x1294a
cmpl $0x1, 0x1e4(%rbx)
je 0x1289d
movl $0x4d, %edx
movq %rbp, %rdi
leaq 0x1eb6b(%rip), %rsi     # 0x3137c
callq 0x53a0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %rbp, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
movl $0x3c, %edx
movq %rbp, %rdi
leaq 0x1eb7d(%rip), %rsi     # 0x313ca
callq 0x53a0
movq 0x1c0(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbp, %rdi
callq 0x53a0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
movl $0x1, 0x1e4(%rbx)
movq 0x108(%rsp), %rax
subq 0x100(%rsp), %rax
cmpq $0xbf, %rax
ja 0x1294a
movl $0x4c, %edx
movq %rbp, %rdi
leaq 0x1eb3f(%rip), %rsi     # 0x31407
callq 0x53a0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %rbp, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
movl $0x21, %edx
movq %rbp, %rdi
leaq 0x1eb50(%rip), %rsi     # 0x31454
callq 0x53a0
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbp, %rdi
callq 0x53a0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
jmp 0x13536
movq 0x100(%rsp), %rax
leaq 0x158(%rsp), %rcx
movq %rcx, 0x148(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x148(%rsp), %rdi
callq 0x112ce
movq 0x100(%rsp), %r14
movq 0x20(%r14), %rdi
callq 0x54c0
movl %eax, %r15d
leaq 0x178(%rsp), %rax
movq %rax, 0x168(%rsp)
movq 0x60(%r14), %rsi
movq 0x68(%r14), %rdx
addq %rsi, %rdx
leaq 0x168(%rsp), %rdi
callq 0x112ce
movq 0x100(%rsp), %rax
leaq 0x138(%rsp), %rcx
movq %rcx, 0x128(%rsp)
movq 0x80(%rax), %rsi
movq 0x88(%rax), %rdx
addq %rsi, %rdx
leaq 0x128(%rsp), %rdi
callq 0x112ce
movq 0x100(%rsp), %rdi
movl $0xa0, %eax
addq %rax, %rdi
leaq 0x1f054(%rip), %rsi     # 0x31a56
callq 0x50e0
movsd 0x1e871(%rip), %xmm0    # 0x31280
movsd %xmm0, 0x118(%rsp)
testl %eax, %eax
je 0x12a87
movq 0x100(%rsp), %rax
movq 0xa0(%rax), %rbp
callq 0x5060
movq %rax, %r13
movl (%rax), %r14d
movl $0x0, (%rax)
movq %rbp, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x5290
movsd %xmm0, 0x118(%rsp)
cmpq %rbp, 0xa0(%rsp)
je 0x13909
movl (%r13), %eax
testl %eax, %eax
je 0x12a7c
cmpl $0x22, %eax
movq 0x2955b(%rip), %rbp     # 0x3bfd0
jne 0x12a87
jmp 0x13915
movl %r14d, (%r13)
movq 0x29549(%rip), %rbp     # 0x3bfd0
cmpb $0x0, 0x8(%rsp)
je 0x12ad3
xorps %xmm0, %xmm0
cvtsd2ss 0x118(%rsp), %xmm0
movss %xmm0, 0xa0(%rsp)
movq 0x78(%rsp), %rsi
cmpq 0x80(%rsp), %rsi
je 0x12ac1
movss %xmm0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x78(%rsp)
jmp 0x12ad3
leaq 0x70(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x2b954
movl %r15d, 0x124(%rsp)
movq 0x170(%rsp), %r14
testq %r14, %r14
je 0x12b09
movq 0x168(%rsp), %r15
xorl %r12d, %r12d
movsbl (%r15,%r12), %edi
callq 0x5610
movb %al, (%r15,%r12)
incq %r12
cmpq %r12, %r14
jne 0x12af3
movq 0x130(%rsp), %r14
testq %r14, %r14
je 0x12b37
movq 0x128(%rsp), %r15
xorl %r12d, %r12d
movsbl (%r15,%r12), %edi
callq 0x5610
movb %al, (%r15,%r12)
incq %r12
cmpq %r12, %r14
jne 0x12b21
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
cmpl $0x1, 0x1e4(%rbx)
jne 0x12b71
movl $0x0, 0x4(%rsp)
xorl %r15d, %r15d
leaq 0x128(%rsp), %r14
leaq 0x88(%rsp), %r12
jmp 0x12fa2
cmpl $0x0, 0xc(%rsp)
leaq 0x128(%rsp), %r14
leaq 0x88(%rsp), %r12
jns 0x12cb2
movq 0x100(%rsp), %rsi
movl $0x100, %eax            # imm = 0x100
addq %rax, %rsi
leaq 0xa0(%rsp), %rdi
movl $0x3a, %edx
callq 0x2f46e
movq 0xa0(%rsp), %rdi
cmpq %rdi, 0xa8(%rsp)
je 0x12c03
xorl %r15d, %r15d
xorl %r14d, %r14d
addq %r15, %rdi
leaq 0x1e8a6(%rip), %rsi     # 0x31476
callq 0x50e0
testl %eax, %eax
je 0x12bfe
incq %r14
movq 0xa0(%rsp), %rdi
movq 0xa8(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %r14, %rax
ja 0x12bc6
jmp 0x12c03
movl %r14d, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
jns 0x12c9d
cmpl $0x1, 0x1e4(%rbx)
je 0x12c9d
movl $0x44, %edx
movq %rbp, %rdi
leaq 0x1e84f(%rip), %rsi     # 0x31479
callq 0x53a0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %rbp, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
movl $0x3b, %edx
movq %rbp, %rdi
leaq 0x1e858(%rip), %rsi     # 0x314be
callq 0x53a0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %rbp, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
movl $0x1, 0x1e4(%rbx)
leaq 0xa0(%rsp), %rdi
callq 0xe7ca
leaq 0x128(%rsp), %r14
cmpl $0x1, 0x1e4(%rbx)
jne 0x12ccb
movl $0x0, 0x4(%rsp)
xorl %r15d, %r15d
jmp 0x12fa2
movq 0x100(%rsp), %rsi
movl $0x120, %eax            # imm = 0x120
addq %rax, %rsi
leaq 0x10(%rsp), %rdi
movl $0x3a, %edx
callq 0x2f46e
movslq 0xc(%rsp), %r15
shlq $0x5, %r15
movq 0x10(%rsp), %rsi
addq %r15, %rsi
movsbl 0x28(%rsp), %edx
movq %r12, %rdi
callq 0x2f46e
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps 0x50(%rsp), %xmm0
movq 0x60(%rsp), %rax
movups 0x88(%rsp), %xmm1
movaps %xmm1, 0x50(%rsp)
movq 0x98(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movaps 0xa0(%rsp), %xmm1
movaps %xmm0, 0xa0(%rsp)
movq %rax, 0xb0(%rsp)
movups %xmm1, 0x88(%rsp)
movq $0x0, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0xe7ca
movq %r12, %rdi
callq 0xe7ca
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
cmpq $0x40, %rax
je 0x12e22
cmpb $0x2f, 0x28(%rsp)
movl $0x2f, %edx
movl $0x7c, %eax
cmovel %eax, %edx
movq 0x10(%rsp), %rsi
addq %r15, %rsi
movq %r12, %rdi
movl %edx, 0x28(%rsp)
callq 0x2f46e
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps 0x50(%rsp), %xmm0
movq 0x60(%rsp), %rax
movups 0x88(%rsp), %xmm1
movaps %xmm1, 0x50(%rsp)
movq 0x98(%rsp), %rcx
movq %rcx, 0x60(%rsp)
movaps 0xa0(%rsp), %xmm1
movaps %xmm0, 0xa0(%rsp)
movq %rax, 0xb0(%rsp)
movups %xmm1, 0x88(%rsp)
movq $0x0, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0xe7ca
movq %r12, %rdi
callq 0xe7ca
movq 0x50(%rsp), %r13
movq 0x58(%rsp), %rax
subq %r13, %rax
cmpq $0x40, %rax
jne 0x12e67
movq 0x8(%r13), %rdx
movb $0x1, %r15b
cmpq 0x28(%r13), %rdx
jne 0x12f14
testq %rdx, %rdx
je 0x12f11
movq (%r13), %rdi
movq 0x20(%r13), %rsi
callq 0x5350
testl %eax, %eax
setne %r15b
jmp 0x12f14
movl $0x2b, %edx
movq %rbp, %rdi
leaq 0x1e684(%rip), %rsi     # 0x314fa
callq 0x53a0
movq 0x10(%rsp), %rax
movq (%rax,%r15), %rsi
movq 0x8(%rax,%r15), %rdx
movq %rbp, %rdi
callq 0x53a0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %r13, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
movl $0x3a, %edx
movq %rbp, %rdi
leaq 0x1e65c(%rip), %rsi     # 0x31526
callq 0x53a0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %rbp, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
movl $0x1, 0x1e4(%rbx)
movb $0x1, %bpl
movl $0x0, 0x4(%rsp)
xorl %r15d, %r15d
jmp 0x12f87
xorl %r15d, %r15d
addq $0x20, %r13
movq %r13, %rdi
leaq 0x1e92f(%rip), %r14     # 0x31851
movq %r14, %rsi
callq 0x50e0
testl %eax, %eax
jne 0x12f3f
movq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x50e0
testl %eax, %eax
je 0x12f7d
movq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x50e0
testl %eax, %eax
je 0x12f72
movq 0x50(%rsp), %rdi
addq $0x20, %rdi
movq %r14, %rsi
callq 0x50e0
testl %eax, %eax
je 0x12f72
movb $0x1, %bpl
movl $0x0, 0x4(%rsp)
jmp 0x12f87
movb $0x1, %al
movl %eax, 0x4(%rsp)
movb $0x1, %bpl
jmp 0x12f87
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
leaq 0x10(%rsp), %rdi
callq 0xe7ca
testb %bpl, %bpl
leaq 0x128(%rsp), %r14
je 0x13576
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x1, %ecx
movq %r14, %rdi
leaq 0x1e59f(%rip), %rsi     # 0x31561
xorl %edx, %edx
callq 0x55b0
movq %rax, %rbp
cmpq $-0x1, %rax
je 0x13058
movq %r12, %rdi
movq %r14, %rsi
movl $0x2c, %edx
callq 0x2f46e
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movaps 0x10(%rsp), %xmm0
movq 0x20(%rsp), %rax
movups 0x88(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movq 0x98(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movaps 0xa0(%rsp), %xmm1
movaps %xmm0, 0xa0(%rsp)
movq %rax, 0xb0(%rsp)
movups %xmm1, 0x88(%rsp)
movq $0x0, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0xe7ca
movq %r12, %rdi
callq 0xe7ca
jmp 0x13065
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x10ca6
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
cmpq $0x41, %rax
jb 0x13234
cmpl $0x1, 0x1e4(%rbx)
jne 0x13118
movl %r15d, %r13d
leaq 0xa0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x289ec
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r14, %r15
je 0x130da
leaq 0x10(%r14), %r12
movq -0x10(%r12), %rdi
cmpq %rdi, %r12
je 0x130c4
movq (%r12), %rsi
incq %rsi
callq 0x5340
leaq 0x20(%r12), %rax
addq $0x10, %r12
cmpq %r15, %r12
movq %rax, %r12
jne 0x130ae
movq %r14, 0x18(%rsp)
movq 0xa0(%rsp), %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x10ca6
movq 0xa0(%rsp), %rsi
addq $0x20, %rsi
movq %r14, %rdi
callq 0x10ca6
leaq 0xa0(%rsp), %rdi
callq 0xe7ca
movl %r13d, %r15d
jmp 0x13234
movl %r15d, 0x120(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x289ec
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r14, %r15
je 0x13171
leaq 0x10(%r14), %r12
movq -0x10(%r12), %rdi
cmpq %rdi, %r12
je 0x1315b
movq (%r12), %rsi
incq %rsi
callq 0x5340
leaq 0x20(%r12), %rax
addq $0x10, %r12
cmpq %r15, %r12
movq %rax, %r12
jne 0x13145
movq %r14, 0x18(%rsp)
callq 0x5060
movq %rax, %r13
xorl %r14d, %r14d
movq 0x50(%rsp), %rax
movq (%rax,%r14), %r12
movl (%r13), %r15d
movl $0x0, (%r13)
movq %r12, %rdi
leaq 0x88(%rsp), %rsi
movl $0xa, %edx
callq 0x5430
cmpq %r12, 0x88(%rsp)
je 0x138fd
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x138f1
movl (%r13), %ecx
cmpl $0x22, %ecx
je 0x138f1
testl %ecx, %ecx
jne 0x131e3
movl %r15d, (%r13)
testl %eax, %eax
je 0x13211
shlq $0x20, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
sarq $0x1b, %rax
addq 0xa0(%rsp), %rax
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x10ca6
addq $0x20, %r14
cmpq $0x20, %r14
je 0x1317c
leaq 0xa0(%rsp), %rdi
callq 0xe7ca
movl 0x120(%rsp), %r15d
movq 0x10(%rsp), %rax
movl 0x8(%rax), %r13d
movq 0x170(%rsp), %rdx
movl %edx, %r12d
subl %r13d, %r12d
subl %edx, %r13d
testl %r13d, %r13d
movl $0x0, %ecx
cmovlel %ecx, %r13d
testl %r12d, %r12d
cmovlel %ecx, %r12d
cmpq $-0x1, %rbp
je 0x13286
movl 0x28(%rax), %eax
movl %eax, %ecx
subl %edx, %ecx
cmpl %ecx, %r13d
cmovgl %r13d, %ecx
movl %edx, %esi
subl %eax, %esi
cmpl %esi, %r12d
cmovgl %r12d, %esi
movl %esi, %r12d
movl %ecx, %r13d
cmpl $0x64, %r13d
jg 0x133db
cmpl $0x64, %r12d
jg 0x133db
leaq 0x1a0(%rsp), %rax
movq %rax, 0x190(%rsp)
movq 0x168(%rsp), %rsi
addq %rsi, %rdx
leaq 0x190(%rsp), %rdi
callq 0x112ce
leaq 0x1c8(%rsp), %r14
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
callq 0x289ec
movl 0x124(%rsp), %esi
decl %esi
xorl %r9d, %r9d
cmpq $-0x1, %rbp
setne %r9b
movzbl 0x4(%rsp), %eax
movzbl 0x8(%rsp), %r10d
movzbl %r15b, %r8d
leaq 0xa0(%rsp), %rdi
leaq 0x190(%rsp), %rdx
movq %r14, %rcx
movsd 0x118(%rsp), %xmm0
pushq %rax
pushq %r10
pushq %r13
pushq %r12
callq 0x28a76
addq $0x20, %rsp
movq %r14, %rdi
callq 0xe7ca
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
leaq 0x40(%rsp), %r15
leaq 0x1e0(%rsp), %r12
leaq 0x30(%rsp), %r13
movq 0x28c76(%rip), %rbp     # 0x3bfd0
je 0x1336c
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x188(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x2b6fe
cmpq 0x1b8(%rsp), %rax
je 0x133f9
movq 0x188(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x28812
movslq (%rax), %rax
cmpb $0x0, 0x8(%rsp)
je 0x13465
movq 0x150(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x28b1a
movq 0x1b0(%rsp), %rdi
movq %r13, %rsi
callq 0x10ca6
jmp 0x1347d
leaq 0x40(%rsp), %r15
leaq 0x1e0(%rsp), %r12
leaq 0x30(%rsp), %r13
movq 0x28bdc(%rip), %rbp     # 0x3bfd0
jmp 0x134b3
movl $0x5d, %edx
movq %rbp, %rdi
leaq 0x1e15b(%rip), %rsi     # 0x31563
callq 0x53a0
movq 0x148(%rsp), %rsi
movq 0x150(%rsp), %rdx
movq %rbp, %rdi
callq 0x53a0
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1e61f(%rip), %rsi     # 0x31a56
callq 0x53a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5310
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5240
jmp 0x13481
movq 0x148(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x28b1a
incl 0x2c(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0xe7ca
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x134b3
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x10(%rsp), %rdi
callq 0xe7ca
leaq 0x50(%rsp), %rdi
callq 0xe7ca
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x134ec
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x168(%rsp), %rdi
leaq 0x178(%rsp), %rax
cmpq %rax, %rdi
je 0x13511
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x13536
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x100(%rsp), %rdi
callq 0xe7ca
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x1355a
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x1e0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x2, 0x200(%rsp,%rax)
je 0x12788
jmp 0x13594
leaq 0x40(%rsp), %r15
leaq 0x1e0(%rsp), %r12
leaq 0x30(%rsp), %r13
movq 0x28a41(%rip), %rbp     # 0x3bfd0
jmp 0x134bd
leaq 0x1e0(%rsp), %rdi
callq 0x50a0
cmpb $0x0, 0x8(%rsp)
je 0x138b2
movq 0x70(%rsp), %r14
movq 0x78(%rsp), %r15
cmpq %r15, %r14
je 0x135e8
movq %r15, %rax
subq %r14, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2bddc
movq %r14, %rdi
movq %r15, %rsi
callq 0x2becb
movq 0x70(%rsp), %r12
movq 0x78(%rsp), %r15
subq %r12, %r15
sarq $0x2, %r15
movq %r12, %rbp
testq %r15, %r15
jle 0x13637
movsd 0x1dc7f(%rip), %xmm0    # 0x31288
movq %r15, %rcx
movq %r12, %rbp
movq %r15, %rax
shrq %rax
xorps %xmm1, %xmm1
cvtss2sd (%rbp,%rax,4), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1362f
leaq 0x4(%rbp,%rax,4), %rbp
notq %rax
addq %rcx, %rax
movq %rax, %rcx
testq %rax, %rax
jg 0x13612
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq $0x0, 0xb0(%rsp)
movl $0x0, 0x30(%rsp)
movq 0xa8(%rsp), %rsi
testq %rsi, %rsi
je 0x13677
movl $0x0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xa8(%rsp)
jmp 0x13689
leaq 0xa0(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x2b954
leaq 0x250(%rbx), %r14
movq $0x0, 0x30(%rsp)
movq 0x258(%rbx), %rsi
cmpq 0x260(%rbx), %rsi
je 0x136bd
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x258(%rbx)
jmp 0x136ca
leaq 0x30(%rsp), %rdx
movq %r14, %rdi
callq 0x2c19e
movq 0x270(%rbx), %rax
movq 0x278(%rbx), %rcx
subq %rax, %rcx
cmpq $0x5, %rcx
jb 0x13869
subq %r12, %rbp
shrq $0x2, %rbp
subl %ebp, %r15d
xorps %xmm0, %xmm0
cvtsi2ss %r15d, %xmm0
movss %xmm0, 0x8(%rsp)
movl $0x1, %r15d
leaq 0xa0(%rsp), %r12
leaq 0x148(%rsp), %r13
movss (%rax,%r15,4), %xmm0
mulss 0x8(%rsp), %xmm0
cvttss2si %xmm0, %eax
addl %ebp, %eax
cltq
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
leal -0x1(%rdx), %esi
cmpq %rax, %rdx
cmovbel %esi, %eax
cltq
xorps %xmm0, %xmm0
cvtss2sd (%rcx,%rax,4), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x258(%rbx), %rsi
cmpq 0x260(%rbx), %rsi
je 0x13772
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x258(%rbx)
jmp 0x1377f
movq %r14, %rdi
leaq 0x30(%rsp), %rdx
callq 0x2c2de
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
subq %rcx, %rax
sarq $0x2, %rax
movq %rcx, %rdx
testq %rax, %rax
jle 0x137ce
movsd 0x30(%rsp), %xmm0
movq %rax, %rdi
movq %rcx, %rdx
movq %rax, %rsi
shrq %rsi
xorps %xmm1, %xmm1
cvtss2sd (%rdx,%rsi,4), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x137c6
leaq (%rdx,%rsi,4), %rdx
addq $0x4, %rdx
notq %rsi
addq %rdi, %rsi
movq %rsi, %rdi
testq %rsi, %rsi
jg 0x137a7
subq %rcx, %rdx
shrq $0x2, %rdx
incl %edx
movslq %edx, %rcx
cmpq %rcx, %rax
cmovbl %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movq %rax, %xmm1
punpckldq 0x1da6c(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1da74(%rip), %xmm1    # 0x31270
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x148(%rsp)
movq 0xa8(%rsp), %rsi
cmpq 0xb0(%rsp), %rsi
je 0x1383d
movss %xmm0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0xa8(%rsp)
jmp 0x13848
movq %r12, %rdi
movq %r13, %rdx
callq 0x2b954
incq %r15
movq 0x270(%rbx), %rax
movq 0x278(%rbx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r15, %rcx
ja 0x13713
leaq 0x270(%rbx), %rdi
movq 0x258(%rbx), %rax
subq 0x250(%rbx), %rax
shrq $0x3, %rax
movl %eax, 0x268(%rbx)
leaq 0xa0(%rsp), %rsi
callq 0x28b6c
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x138b2
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x138cc
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
movl 0x2c(%rsp), %ebx
leaq 0x1e0(%rsp), %rdi
callq 0x50c0
movl %ebx, %eax
addq $0x3e8, %rsp            # imm = 0x3E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e195(%rip), %rdi     # 0x31a8d
callq 0x5460
leaq 0x1e189(%rip), %rdi     # 0x31a8d
callq 0x51f0
leaq 0x1e178(%rip), %rdi     # 0x31a88
callq 0x51f0
leaq 0x1e16c(%rip), %rdi     # 0x31a88
callq 0x5460
jmp 0x13a03
jmp 0x13a03
jmp 0x13a27
jmp 0x13a03
jmp 0x13948
movq %rax, %rbx
jmp 0x13a7a
jmp 0x139ac
jmp 0x139ac
jmp 0x13a27
movq %rax, %rbx
jmp 0x13a70
jmp 0x139ac
jmp 0x139dd
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
callq 0xe7ca
jmp 0x1396c
movq %rax, %rbx
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x13a66
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x5340
jmp 0x13a66
jmp 0x139ac
movq %rax, %rbx
jmp 0x13a59
movq %rax, %rbx
jmp 0x13b12
movq %rax, %rbx
jmp 0x13a66
jmp 0x139dd
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
jmp 0x13a6b
movq %rax, %rbx
cmpl $0x0, (%r13)
jne 0x13a7a
movl %r14d, (%r13)
jmp 0x13a7a
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x28b44
jmp 0x13a66
movq %rax, %rbx
jmp 0x13a9f
movq %rax, %rbx
jmp 0x13ac4
jmp 0x13a43
jmp 0x13a03
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x13b12
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
jmp 0x13b0d
movq %rax, %rbx
jmp 0x13a66
jmp 0x13a3b
movq %rax, %rbx
jmp 0x13b2c
movq %rax, %rbx
jmp 0x13a59
movq %rax, %rbx
jmp 0x13af6
movq %rax, %rbx
jmp 0x13ae9
movq %rax, %rbx
cmpl $0x0, (%r13)
jne 0x13a59
movl %r15d, (%r13)
leaq 0xa0(%rsp), %rdi
callq 0xe7ca
leaq 0x10(%rsp), %rdi
callq 0xe7ca
leaq 0x50(%rsp), %rdi
callq 0xe7ca
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x13a9f
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x168(%rsp), %rdi
leaq 0x178(%rsp), %rax
cmpq %rax, %rdi
je 0x13ac4
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x13ae9
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x5340
leaq 0x100(%rsp), %rdi
callq 0xe7ca
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x13b12
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x5340
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x13b2c
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x5340
leaq 0x1e0(%rsp), %rdi
callq 0x50c0
movq %rbx, %rdi
callq 0x55c0
nop