// File: /workspace/github_cpp_makefile_star2_O2/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 $0x3f8, %rsp            # imm = 0x3F8
movl %edx, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, 0x170(%rsp)
leaq 0x1f0(%rsp), %r14
movq %r14, %rdi
callq 0x5350
movq %r15, 0x148(%rsp)
movq (%r15), %rsi
pushq $0x8
popq %rdx
movq %r14, %rdi
callq 0x5210
movq 0x1f0(%rsp), %rax
movq -0x18(%rax), %rcx
cmpl $0x0, 0x210(%rsp,%rcx)
je 0xddfa
movq 0x221e2(%rip), %rdi     # 0x2ffc0
leaq 0x14557(%rip), %rsi     # 0x2233c
callq 0x52f0
movq %rax, %rdi
callq 0x5190
pushq $-0x1
popq %rbx
jmp 0xe908
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rcx
andq $0x0, 0x10(%rcx)
movaps %xmm0, (%rcx)
leaq 0x88(%rbx), %rcx
movq %rcx, 0x130(%rsp)
leaq 0x90(%rbx), %rcx
movq %rcx, 0x140(%rsp)
movq %rbx, 0x8(%rsp)
leaq 0x68(%rbx), %rcx
movq %rcx, 0x138(%rsp)
pushq $-0x1
popq %rcx
movl %ecx, 0x14(%rsp)
movb $0x2f, %cl
movl %ecx, 0x1c(%rsp)
leaq 0xa8(%rsp), %r15
pushq $0xa
popq %r13
leaq 0x149e0(%rip), %rbp     # 0x22839
movl $0x0, 0x18(%rsp)
movq -0x18(%rax), %rax
testb $0x2, 0x210(%rsp,%rax)
jne 0xe701
leaq 0xb8(%rsp), %rax
movq %rax, 0xa8(%rsp)
andq $0x0, 0xb0(%rsp)
movb $0x0, 0xb8(%rsp)
leaq 0x1f0(%rsp), %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x5580
cmpl $0x2, 0xb0(%rsp)
jl 0xe6ec
movq 0xa8(%rsp), %rax
cmpb $0x23, (%rax)
je 0xe6ec
leaq 0x90(%rsp), %rdi
movq %r15, %rsi
pushq $0x9
popq %rdx
callq 0x2061d
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rax
subq %rsi, %rax
cmpq $0x13f, %rax            # imm = 0x13F
ja 0xdfbc
movq 0x8(%rsp), %rcx
cmpl $0x1, 0x1e4(%rcx)
je 0xdf6e
movq 0x220b3(%rip), %rdi     # 0x2ffc0
leaq 0x14450(%rip), %rsi     # 0x22364
callq 0x52f0
movq %rax, %rdi
callq 0x5190
movq 0x22098(%rip), %rdi     # 0x2ffc0
leaq 0x14483(%rip), %rsi     # 0x223b2
callq 0x52f0
movq %rax, %rdi
movq 0x148(%rsp), %rsi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
movq 0x8(%rsp), %rax
movl $0x1, 0x1e4(%rax)
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %rax
subq %rsi, %rax
cmpq $0xbf, %rax
ja 0xdfbc
movq 0x22043(%rip), %rdi     # 0x2ffc0
leaq 0x1446b(%rip), %rsi     # 0x223ef
callq 0x52f0
movq %rax, %rdi
callq 0x5190
movq 0x22028(%rip), %rdi     # 0x2ffc0
leaq 0x1449d(%rip), %rsi     # 0x2243c
callq 0x52f0
movq %rax, %rdi
movq %r15, %rsi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
jmp 0xe6df
leaq 0x150(%rsp), %rdi
callq 0x53f0
movq 0x90(%rsp), %r14
movq 0x20(%r14), %rdi
callq 0x5460
movl %eax, 0xcc(%rsp)
addq $0x60, %r14
leaq 0x198(%rsp), %rdi
movq %r14, %rsi
callq 0x53f0
movq 0x90(%rsp), %rsi
subq $-0x80, %rsi
leaq 0x178(%rsp), %rdi
callq 0x53f0
movq 0x90(%rsp), %rdi
movl $0xa0, %eax
addq %rax, %rdi
leaq 0x14a19(%rip), %rsi     # 0x22a3e
callq 0xca73
movsd 0x1424e(%rip), %xmm0    # 0x22280
movsd %xmm0, 0x28(%rsp)
testb %al, %al
je 0xe059
movq 0x90(%rsp), %rdi
movl $0xa0, %eax
addq %rax, %rdi
xorl %esi, %esi
callq 0x19aa8
movsd %xmm0, 0x28(%rsp)
cmpb $0x0, 0x20(%rsp)
je 0xe081
cvtsd2ss 0x28(%rsp), %xmm0
movss %xmm0, 0xd0(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x1cda4
movq 0x8(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x19ac2
movq 0x8(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x19ac2
andq $0x0, 0x60(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x8(%rsp), %rax
cmpl $0x1, 0x1e4(%rax)
jne 0xe0d9
movl $0x0, 0x10(%rsp)
xorl %r14d, %r14d
leaq 0x178(%rsp), %rdi
jmp 0xe387
cmpl $0x0, 0x14(%rsp)
jns 0xe1c3
movq 0x90(%rsp), %rsi
movl $0x100, %eax            # imm = 0x100
addq %rax, %rsi
leaq 0xd0(%rsp), %rdi
pushq $0x3a
popq %rdx
callq 0x2061d
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0xd0(%rsp), %rdi
movq 0xd8(%rsp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq %rbx, %rax
jbe 0xe141
addq %r14, %rdi
leaq 0x1432f(%rip), %rsi     # 0x2245e
callq 0xa912
testb %al, %al
jne 0xe147
incq %rbx
addq $0x20, %r14
jmp 0xe109
movl 0x14(%rsp), %eax
jmp 0xe149
movl %ebx, %eax
movl %eax, 0x14(%rsp)
testl %eax, %eax
jns 0xe1a4
movq 0x8(%rsp), %rax
cmpl $0x1, 0x1e4(%rax)
je 0xe1a4
movq 0x21e5a(%rip), %rdi     # 0x2ffc0
leaq 0x142f4(%rip), %rsi     # 0x22461
callq 0x52f0
movq %rax, %rdi
callq 0x5190
movq 0x21e3f(%rip), %rdi     # 0x2ffc0
leaq 0x1431e(%rip), %rsi     # 0x224a6
callq 0x52f0
movq %rax, %rdi
callq 0x5190
movq 0x8(%rsp), %rax
movl $0x1, 0x1e4(%rax)
leaq 0xd0(%rsp), %rdi
callq 0xadcc
movq 0x8(%rsp), %rax
cmpl $0x1, 0x1e4(%rax)
je 0xe0c1
movq 0x90(%rsp), %rsi
movl $0x120, %eax            # imm = 0x120
addq %rax, %rsi
leaq 0xd0(%rsp), %rdi
pushq $0x3a
popq %rdx
callq 0x2061d
movslq 0x14(%rsp), %r14
shlq $0x5, %r14
movq 0xd0(%rsp), %rsi
addq %r14, %rsi
movsbl 0x1c(%rsp), %edx
leaq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x2061d
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x1cee6
movq %rbx, %rdi
callq 0xadcc
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rax
movq %rax, %rcx
subq %rdi, %rcx
cmpq $0x40, %rcx
je 0xe278
cmpb $0x2f, 0x1c(%rsp)
pushq $0x2f
popq %rdx
pushq $0x7c
popq %rax
cmovel %eax, %edx
movq 0xd0(%rsp), %rsi
addq %r14, %rsi
movq %rbx, %rdi
movl %edx, 0x1c(%rsp)
callq 0x2061d
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x1cee6
movq %rbx, %rdi
callq 0xadcc
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rax
subq %rdi, %rax
cmpq $0x40, %rax
jne 0xe2c9
leaq 0x20(%rdi), %rsi
callq 0xa908
movl %eax, %r14d
movq 0x50(%rsp), %rdi
addq $0x20, %rdi
movq %rbp, %rbx
movq %rbp, %rsi
callq 0xa912
testb %al, %al
je 0xe330
movq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0xa912
testb %al, %al
je 0xe330
movl $0x0, 0x10(%rsp)
xorl %ebx, %ebx
jmp 0xe36a
movq 0x21cf0(%rip), %rdi     # 0x2ffc0
leaq 0x1420b(%rip), %rsi     # 0x224e2
callq 0x52f0
addq 0xd0(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x52c0
movq %rax, %rdi
callq 0x5190
movq 0x21cc2(%rip), %rdi     # 0x2ffc0
leaq 0x14209(%rip), %rsi     # 0x2250e
callq 0x52f0
movq %rax, %rdi
callq 0x5190
movq 0x8(%rsp), %rax
movl $0x1, 0x1e4(%rax)
movb $0x1, %bl
movl $0x0, 0x10(%rsp)
xorl %r14d, %r14d
jmp 0xe36a
movq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0xa912
testb %al, %al
jne 0xe356
movq 0x50(%rsp), %rdi
addq $0x20, %rdi
movq %rbp, %rsi
callq 0xa912
testb %al, %al
je 0xe360
movb $0x1, %al
movl %eax, 0x10(%rsp)
movb $0x1, %bl
jmp 0xe36a
movb $0x1, %bl
movl $0x0, 0x10(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xadcc
testb %bl, %bl
leaq 0x178(%rsp), %rdi
je 0xe6ae
movl %r14d, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
leaq 0x141a7(%rip), %rsi     # 0x22549
xorl %edx, %edx
movq %rdi, %rbx
callq 0x55d0
movq %rax, %r14
cmpq $-0x1, %rax
je 0xe3e2
leaq 0xd0(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
pushq $0x2c
popq %rdx
callq 0x2061d
leaq 0x70(%rsp), %rdi
movq %r12, %rsi
callq 0x1cee6
movq %r12, %rdi
callq 0xadcc
jmp 0xe3ef
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
callq 0xc896
movq 0x78(%rsp), %rax
subq 0x70(%rsp), %rax
cmpq $0x41, %rax
jb 0xe4c2
movq 0x8(%rsp), %rax
cmpl $0x1, 0x1e4(%rax)
jne 0xe454
leaq 0xd0(%rsp), %rdi
leaq 0x70(%rsp), %rbx
movq %rbx, %rsi
callq 0x19af0
movq %rbx, %rdi
callq 0xc9ca
movq 0xd0(%rsp), %rsi
movq %rbx, %rdi
callq 0xc896
movq 0xd0(%rsp), %rsi
addq $0x20, %rsi
movq %rbx, %rdi
callq 0xc896
jmp 0xe4b5
leaq 0xd0(%rsp), %rdi
leaq 0x70(%rsp), %rbx
movq %rbx, %rsi
callq 0x19af0
movq %rbx, %rdi
callq 0xc9ca
xorl %ebx, %ebx
cmpq $0x40, %rbx
je 0xe4b5
movq 0x50(%rsp), %rdi
addq %rbx, %rdi
xorl %esi, %esi
movl %r13d, %edx
callq 0x19b43
testl %eax, %eax
je 0xe4af
movq 0xd0(%rsp), %rcx
cltq
shlq $0x5, %rax
leaq (%rcx,%rax), %rsi
addq $-0x20, %rsi
leaq 0x70(%rsp), %rdi
callq 0xc896
addq $0x20, %rbx
jmp 0xe473
leaq 0xd0(%rsp), %rdi
callq 0xadcc
leaq 0x198(%rsp), %rsi
movq 0x70(%rsp), %rcx
movl 0x8(%rcx), %edx
movl 0x1a0(%rsp), %eax
movl %edx, %r13d
subl %eax, %r13d
testl %r13d, %r13d
movl $0x0, %edi
cmovlel %edi, %r13d
movl %eax, %ebx
subl %edx, %ebx
testl %ebx, %ebx
cmovlel %edi, %ebx
cmpq $-0x1, %r14
je 0xe514
movl 0x28(%rcx), %ecx
movl %ecx, %edx
subl %eax, %edx
cmpl %edx, %r13d
cmovgl %r13d, %edx
subl %ecx, %eax
cmpl %eax, %ebx
cmovgl %ebx, %eax
movl %eax, %ebx
movl %edx, %r13d
leaq 0x1b8(%rsp), %rdi
cmpl $0x64, %r13d
ja 0xe624
cmpl $0x64, %ebx
ja 0xe624
callq 0x53f0
leaq 0x1d8(%rsp), %r12
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
callq 0x19af0
movl 0xcc(%rsp), %esi
decl %esi
xorl %r9d, %r9d
cmpq $-0x1, %r14
setne %r9b
movzbl 0x10(%rsp), %eax
movzbl 0x20(%rsp), %r10d
movzbl %r15b, %r8d
leaq 0xd0(%rsp), %rdi
leaq 0x1b8(%rsp), %r14
movq %r14, %rdx
movq %r12, %rcx
movsd 0x28(%rsp), %xmm0
pushq %rax
pushq %r10
pushq %r13
pushq %rbx
callq 0x19b60
addq $0x20, %rsp
movq %r12, %rdi
callq 0xadcc
movq %r14, %rdi
callq 0x55e8
movq 0x130(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x1caec
cmpq 0x140(%rsp), %rax
pushq $0xa
popq %r13
je 0xe632
movq 0x130(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x19942
leaq 0xa8(%rsp), %r15
movslq (%rax), %rax
cmpb $0x0, 0x20(%rsp)
je 0xe676
movq 0x8(%rsp), %rcx
movq 0x150(%rcx), %rcx
movq (%rcx,%rax,8), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x19bea
movq 0x138(%rsp), %rdi
movq %r15, %rsi
callq 0xc896
jmp 0xe693
pushq $0xa
popq %r13
leaq 0xa8(%rsp), %r15
jmp 0xe6a4
movq 0x21987(%rip), %rdi     # 0x2ffc0
leaq 0x13f0b(%rip), %rsi     # 0x2254b
callq 0x52f0
leaq 0xa8(%rsp), %r15
movq %rax, %rdi
leaq 0x150(%rsp), %rsi
callq 0x52c0
movq %rax, %rdi
leaq 0x143d7(%rip), %rsi     # 0x22a3e
callq 0x52f0
movq %rax, %rdi
callq 0x5190
jmp 0xe697
movq 0x8(%rsp), %rcx
movq 0x148(%rcx), %rcx
movq (%rcx,%rax,8), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x19bea
incl 0x18(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x19c16
leaq 0x70(%rsp), %rdi
callq 0xadcc
leaq 0x50(%rsp), %rdi
callq 0xadcc
leaq 0x178(%rsp), %rdi
callq 0x55e8
leaq 0x198(%rsp), %rdi
callq 0x55e8
leaq 0x150(%rsp), %rdi
callq 0x55e8
leaq 0x90(%rsp), %rdi
callq 0xadcc
movq %r15, %rdi
callq 0x55e8
movq 0x1f0(%rsp), %rax
jmp 0xde61
leaq 0x1f0(%rsp), %rdi
callq 0x50a0
movq 0x8(%rsp), %r13
movl 0x18(%rsp), %ebx
cmpb $0x0, 0x20(%rsp)
je 0xe8fe
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x1d185
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0x170(%rsp), %rdx
callq 0x1d5e0
movq %rax, %r14
movq 0x30(%rsp), %r12
movq 0x38(%rsp), %rbx
xorps %xmm0, %xmm0
leaq 0xd0(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0xa8(%rsp), %rsi
andl $0x0, (%rsi)
callq 0x1cda4
leaq 0x250(%r13), %r15
leaq 0xa8(%rsp), %rsi
andq $0x0, (%rsi)
movq %r15, %rdi
callq 0x1d618
subq %r12, %r14
shrq $0x2, %r14
subq %r12, %rbx
shrq $0x2, %rbx
subl %r14d, %ebx
cvtsi2ss %ebx, %xmm0
movss %xmm0, 0x28(%rsp)
leaq 0x270(%r13), %rax
movq %rax, 0x20(%rsp)
pushq $0x1
popq %rbx
leaq 0xa8(%rsp), %r13
leaq 0xd0(%rsp), %rbp
leaq 0x150(%rsp), %r12
movq 0x8(%rsp), %rcx
movq 0x270(%rcx), %rax
movq 0x278(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0xe8be
movss (%rax,%rbx,4), %xmm0
mulss 0x28(%rsp), %xmm0
cvttss2si %xmm0, %eax
addl %r14d, %eax
cltq
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
leal -0x1(%rdx), %esi
cmpq %rax, %rdx
cmovbel %esi, %eax
cltq
cvtss2sd (%rcx,%rax,4), %xmm0
movsd %xmm0, 0xa8(%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x19c30
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0x1d5e0
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
subq %rcx, %rax
shrq $0x2, %rax
incl %eax
cltq
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %rax, %rdx
cmovbl %edx, %eax
cvtsi2sd %eax, %xmm0
movq %rdx, %xmm1
punpckldq 0x139da(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x139e2(%rip), %xmm1    # 0x22270
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x150(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x1cda4
incq %rbx
jmp 0xe7d5
movq 0x8(%rsp), %rcx
movq 0x258(%rcx), %rax
subq 0x250(%rcx), %rax
shrq $0x3, %rax
movl %eax, 0x268(%rcx)
leaq 0xd0(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x19c52
leaq 0xd0(%rsp), %rdi
callq 0x1c3c2
movl 0x18(%rsp), %ebx
leaq 0x30(%rsp), %rdi
callq 0x1c3c2
leaq 0x1f0(%rsp), %rdi
callq 0x50e0
movl %ebx, %eax
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xe9c4
jmp 0xe9c4
jmp 0xe9c4
jmp 0xe942
jmp 0xe97d
jmp 0xe982
jmp 0xe982
jmp 0xe9a9
movq %rax, %rbx
jmp 0xea4a
jmp 0xe982
jmp 0xe9a9
jmp 0xe982
jmp 0xe9e5
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
callq 0xadcc
jmp 0xe96a
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x55e8
jmp 0xe9f5
jmp 0xe98b
jmp 0xe9a9
movq %rax, %rbx
jmp 0xe9ff
movq %rax, %rbx
jmp 0xe9f5
jmp 0xe9db
jmp 0xe98b
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x19c16
jmp 0xe9f5
movq %rax, %rbx
jmp 0xea16
jmp 0xe9d6
movq %rax, %rbx
jmp 0xea23
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
jmp 0xe9fa
movq %rax, %rbx
jmp 0xea54
jmp 0xe9e0
jmp 0xe9c4
jmp 0xe9c4
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x1c3c2
jmp 0xea4a
movq %rax, %rbx
jmp 0xea30
movq %rax, %rbx
jmp 0xea09
movq %rax, %rbx
jmp 0xea3d
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0xadcc
leaq 0x70(%rsp), %rdi
callq 0xadcc
leaq 0x50(%rsp), %rdi
callq 0xadcc
leaq 0x178(%rsp), %rdi
callq 0x55e8
leaq 0x198(%rsp), %rdi
callq 0x55e8
leaq 0x150(%rsp), %rdi
callq 0x55e8
leaq 0x90(%rsp), %rdi
callq 0xadcc
leaq 0xa8(%rsp), %rdi
callq 0x55e8
leaq 0x30(%rsp), %rdi
callq 0x1c3c2
leaq 0x1f0(%rsp), %rdi
callq 0x50e0
movq %rbx, %rdi
callq 0x5540
nop