// File: millanek[P]evo/evo_AlleleFeq.cpp
// Function: AFmain(int, char**)
int AFmain(int argc, char** argv) {
    parseAFoptions(argc, argv);
    string line; // for reading the input files
    

    
    std::istream* vcfFile = createReader(opt::vcfFile.c_str());
    std::ifstream* setsFile = new std::ifstream(opt::setsFile.c_str());
    
    std::map<string, std::vector<string>> popToIDsMap;
    std::map<string, string> IDsToPopMap;
    std::map<string, std::vector<size_t>> popToPosMap;
    std::map<size_t, string> posToPopMap;
    
    // Get the sample sets
    while (getline(*setsFile, line)) {
        // std::cerr << line << std::endl;
        std::vector<string> ID_Pop = split(line, '\t');
        popToIDsMap[ID_Pop[1]].push_back(ID_Pop[0]);
        IDsToPopMap[ID_Pop[0]] = ID_Pop[1];
        //std::cerr << ID_Species[1] << "\t" << ID_Species[0] << std::endl;
    }
    // Get a vector of set names (usually populations/species)
    std::vector<string> populations;
    for(std::map<string,std::vector<string>>::iterator it = popToIDsMap.begin(); it != popToIDsMap.end(); ++it) {
        populations.push_back(it->first);
        // std::cerr << it->first << std::endl;
    } std::cerr << "There are " << populations.size() << " populations " << std::endl;

    int totalVariantNumber = 0;
    std::vector<string> sampleNames; std::vector<std::string> fields;
    int reportProgressEvery = 10000; string chr; string coord; double coordDouble;
    std::clock_t start; std::clock_t startGettingCounts;
    double durationOverall; double durationGettingCounts; 
    //std::ofstream* outFileAF = new std::ofstream(stripExtension(opt::setsFile) + "_" + opt::runName + "_AF" + ".txt");
    std::ostream* outFileAF = createWriter(stripExtension(opt::setsFile) + "_" + opt::runName + "_AF" + ".txt");
    
    while (getline(*vcfFile, line)) {
        line.erase(std::remove(line.begin(), line.end(), '\r'), line.end()); // Deal with any left over \r from files prepared on Windows
        if (line[0] == '#' && line[1] == '#')
            continue;
        else if (line[0] == '#' && line[1] == 'C') {
            fields = split(line, '\t');
            std::vector<std::string> sampleNames(fields.begin()+NUM_NON_GENOTYPE_COLUMNS,fields.end());
            // print_vector_stream(sampleNames, std::cerr);
            for (std::vector<std::string>::size_type i = 0; i != sampleNames.size(); i++) {
                posToPopMap[i] = IDsToPopMap[sampleNames[i]];
            }
            // Iterate over all the keys in the map to find the samples in the VCF:
            // Give an error if no sample is found for a species:
            for(std::map<string, std::vector<string>>::iterator it = popToIDsMap.begin(); it != popToIDsMap.end(); ++it) {
                string sp =  it->first;
                //std::cerr << "sp " << sp << std::endl;
                std::vector<string> IDs = it->second;
                std::vector<size_t> spPos = locateSet(sampleNames, IDs);
                if (spPos.empty()) {
                    std::cerr << "Did not find any samples in the VCF for \"" << sp << "\"" << std::endl;
                    assert(!spPos.empty());
                }
                popToPosMap[sp] = spPos;
            }
            start = std::clock();
            //  std::cerr << " " << std::endl;
            //  std::cerr << "Outgroup at pos: "; print_vector_stream(speciesToPosMap["Outgroup"], std::cerr);
            //  std::cerr << "telvit at pos: "; print_vector_stream(speciesToPosMap["telvit"], std::cerr);
        } else {
            totalVariantNumber++;
            if (totalVariantNumber == 1) {
                *outFileAF << "chr" << "\t" << "coord" << "\t" << "ref" << "\t" << "alt";
                for(std::map<string,std::vector<size_t>>::iterator iter =  popToPosMap.begin(); iter != popToPosMap.end(); ++iter) {
                    *outFileAF << "\t" << iter->first;
                }
                *outFileAF << "\n";
            }
            if (totalVariantNumber % reportProgressEvery == 0) {
                durationOverall = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
                std::cerr << "Processed " << totalVariantNumber << " variants in " << durationOverall << "secs" << std::endl;
            }
            fields = split(line, '\t'); chr = fields[0]; coord = fields[1]; coordDouble = stringToDouble(coord);
            std::vector<std::string> genotypes(fields.begin()+NUM_NON_GENOTYPE_COLUMNS,fields.end());
            // Only consider biallelic SNPs
            string refAllele = fields[3]; string altAllele = fields[4];
            if (refAllele.length() > 1 || altAllele.length() > 1 || altAllele == "*") {
                refAllele.clear(); refAllele.shrink_to_fit(); altAllele.clear(); altAllele.shrink_to_fit();
                genotypes.clear(); genotypes.shrink_to_fit(); continue;
            }
            startGettingCounts = std::clock();
            GeneralSetCounts* c = new GeneralSetCounts(popToPosMap, (int)genotypes.size());
            c->getSetVariantCountsSimple(genotypes, posToPopMap);
            durationGettingCounts = ( std::clock() - startGettingCounts ) / (double) CLOCKS_PER_SEC;
            // std::cerr << "Here:" << totalVariantNumber << std::endl;

            
            *outFileAF << chr << "\t" << coord << "\t" << refAllele << "\t" << altAllele;
            if (opt::useGenotypeProbabilities) {
                int likelihoodsOrProbabilitiesTagPosition = c->checkForGenotypeLikelihoodsOrProbabilities(fields);
                if (likelihoodsOrProbabilitiesTagPosition == LikelihoodsProbabilitiesAbsent) {
                    printMissingLikelihoodsWarning(fields[0], fields[1]);
                    opt::useGenotypeProbabilities = false;
                } else c->getAFsFromGenotypeLikelihoodsOrProbabilities(genotypes,posToPopMap,likelihoodsOrProbabilitiesTagPosition);
                for(std::map<string,double>::iterator iter =  c->setAAFsFromLikelihoods.begin(); iter != c->setAAFsFromLikelihoods.end(); ++iter) {
                    *outFileAF << "\t" << iter->second;
                }
            
            } else {
                for(std::map<string,double>::iterator iter =  c->setAAFs.begin(); iter != c->setAAFs.end(); ++iter) {
                    *outFileAF << "\t" << iter->second;
                }
            }
            *outFileAF << "\n";

            genotypes.clear(); genotypes.shrink_to_fit();
            
            delete c;
        }
    }
    
    outFileAF->flush();
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x6e0, %rsp            # imm = 0x6E0
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x111e00
leaq -0x30(%rbp), %rdi
callq 0xa820
leaq 0x8ac8a(%rip), %rdi     # 0x19b558
callq 0xa220
movq %rax, -0x4c8(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x4c0(%rbp)
callq 0xab60
movq -0x4c8(%rbp), %rsi
movq -0x4c0(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x2d6c0
jmp 0x110903
leaq -0x58(%rbp), %rdi
movl $0x8, %esi
callq 0x80e30
movq %rax, -0x4d0(%rbp)
jmp 0x11091a
leaq -0x58(%rbp), %rdi
callq 0xac88
leaq -0x59(%rbp), %rdi
callq 0xa640
movq -0x4d0(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x208, %edi            # imm = 0x208
callq 0xa5d0
movq %rax, -0x4d8(%rbp)
jmp 0x11094a
leaq 0x8ac27(%rip), %rdi     # 0x19b578
callq 0xa220
movq -0x4d8(%rbp), %rdi
movq %rax, %rsi
movl $0x8, %edx
callq 0xab90
jmp 0x11096c
movq -0x4d8(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x58920
leaq -0xd8(%rbp), %rdi
callq 0x584b0
leaq -0x108(%rbp), %rdi
callq 0x951b0
leaq -0x138(%rbp), %rdi
callq 0x951d0
movq -0x78(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x4e0(%rbp)
jmp 0x1109bd
movq -0x4e0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x4e1(%rbp)
jmp 0x1109db
movb -0x4e1(%rbp), %al
testb $0x1, %al
jne 0x1109ea
jmp 0x110b4a
leaq -0x150(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x9, %edx
callq 0x7bbe0
jmp 0x110a01
leaq -0x150(%rbp), %rdi
movl $0x1, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x6b400
movq %rax, -0x4f0(%rbp)
jmp 0x110a2a
xorl %eax, %eax
movl %eax, %esi
leaq -0x150(%rbp), %rdi
callq 0x3d940
movq -0x4f0(%rbp), %rdi
movq %rax, %rsi
callq 0x48dc0
jmp 0x110a4b
leaq -0x150(%rbp), %rdi
movq %rdi, -0x508(%rbp)
movl $0x1, %esi
callq 0x3d940
movq -0x508(%rbp), %rdi
movq %rax, -0x500(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x584d0
movq %rax, -0x4f8(%rbp)
jmp 0x110a92
movq -0x500(%rbp), %rsi
movq -0x4f8(%rbp), %rdi
callq 0xa060
jmp 0x110aa7
leaq -0x150(%rbp), %rdi
callq 0x3dfa0
jmp 0x1109a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x110adb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xac88
leaq -0x59(%rbp), %rdi
callq 0xa640
jmp 0x111dea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x111dea
movq -0x4d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movl $0x208, %esi            # imm = 0x208
callq 0xa5e0
jmp 0x111dea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x111dba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x3dfa0
jmp 0x111dba
leaq -0x168(%rbp), %rdi
callq 0x48da0
leaq -0xa8(%rbp), %rdi
callq 0x6c3d0
movq %rax, -0x170(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x6c430
movq %rax, -0x178(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x6c400
testb $0x1, %al
jne 0x110b95
jmp 0x110bd3
leaq -0x170(%rbp), %rdi
callq 0x6c460
movq %rax, %rsi
leaq -0x168(%rbp), %rdi
callq 0x48dc0
jmp 0x110bb2
jmp 0x110bb4
leaq -0x170(%rbp), %rdi
callq 0x71fc0
jmp 0x110b69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x111dae
movq 0x88416(%rip), %rdi     # 0x198ff0
leaq 0x3de1c(%rip), %rsi     # 0x14e9fd
callq 0xa5c0
movq %rax, -0x510(%rbp)
jmp 0x110bef
leaq -0x168(%rbp), %rdi
callq 0x3ffd0
movq -0x510(%rbp), %rdi
movq %rax, %rsi
callq 0xa140
movq %rax, -0x518(%rbp)
jmp 0x110c13
movq -0x518(%rbp), %rdi
leaq 0x2bb53(%rip), %rsi     # 0x13c774
callq 0xa5c0
movq %rax, -0x520(%rbp)
jmp 0x110c2f
movq -0x520(%rbp), %rdi
movq 0x8834b(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0x110c44
movl $0x0, -0x17c(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x48da0
leaq -0x1b0(%rbp), %rdi
callq 0x48da0
movl $0x2710, -0x1b4(%rbp)   # imm = 0x2710
leaq -0x1d8(%rbp), %rdi
callq 0xa820
leaq -0x1f8(%rbp), %rdi
callq 0xa820
leaq 0x8a8e9(%rip), %rsi     # 0x19b578
leaq -0x2c8(%rbp), %rdi
callq 0x7be70
jmp 0x110c9d
leaq 0x2f0ec(%rip), %rdx     # 0x13fd90
leaq -0x2a8(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x3e020
jmp 0x110cb9
leaq 0x8a8d8(%rip), %rdx     # 0x19b598
leaq -0x288(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x3da30
jmp 0x110cd5
leaq 0x3af7b(%rip), %rdx     # 0x14bc57
leaq -0x268(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x3e020
jmp 0x110cf1
leaq 0x388af(%rip), %rdx     # 0x1495a7
leaq -0x248(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x3e020
jmp 0x110d0d
leaq -0x248(%rbp), %rdi
movl $0x10, %esi
callq 0x80f60
movq %rax, -0x528(%rbp)
jmp 0x110d27
leaq -0x248(%rbp), %rdi
callq 0xac88
leaq -0x268(%rbp), %rdi
callq 0xac88
leaq -0x288(%rbp), %rdi
callq 0xac88
leaq -0x2a8(%rbp), %rdi
callq 0xac88
leaq -0x2c8(%rbp), %rdi
callq 0xac88
movq -0x528(%rbp), %rax
movq %rax, -0x228(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0xa0d0
movq %rax, -0x530(%rbp)
jmp 0x110d87
movq -0x530(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0xa740
movb %al, -0x531(%rbp)
jmp 0x110da5
movb -0x531(%rbp), %al
testb $0x1, %al
jne 0x110db4
jmp 0x111ce6
leaq -0x30(%rbp), %rdi
movq %rdi, -0x548(%rbp)
callq 0xa4f0
movq -0x548(%rbp), %rdi
movq %rax, -0x2e0(%rbp)
callq 0xa330
movq %rax, -0x2e8(%rbp)
movb $0xd, -0x2e9(%rbp)
movq -0x2e0(%rbp), %rdi
movq -0x2e8(%rbp), %rsi
leaq -0x2e9(%rbp), %rdx
callq 0xc6570
movq %rax, -0x540(%rbp)
jmp 0x110e08
movq -0x540(%rbp), %rax
movq %rax, -0x2d8(%rbp)
leaq -0x2d0(%rbp), %rdi
leaq -0x2d8(%rbp), %rsi
callq 0xc65c0
leaq -0x30(%rbp), %rdi
movq %rdi, -0x558(%rbp)
callq 0xa330
movq %rax, -0x300(%rbp)
leaq -0x2f8(%rbp), %rdi
leaq -0x300(%rbp), %rsi
callq 0xc65c0
movq -0x558(%rbp), %rdi
movq -0x2d0(%rbp), %rsi
movq -0x2f8(%rbp), %rdx
callq 0xa120
movq %rax, -0x550(%rbp)
jmp 0x110e76
movq -0x550(%rbp), %rax
movq %rax, -0x308(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0xac60
movq %rax, -0x560(%rbp)
jmp 0x110e9a
movq -0x560(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x110f72
leaq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0xac60
movq %rax, -0x568(%rbp)
jmp 0x110ec4
movq -0x568(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x110f72
jmp 0x110d71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x111d7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x110f61
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x110f55
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x110f49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x110f3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x248(%rbp), %rdi
callq 0xac88
leaq -0x268(%rbp), %rdi
callq 0xac88
leaq -0x288(%rbp), %rdi
callq 0xac88
leaq -0x2a8(%rbp), %rdi
callq 0xac88
leaq -0x2c8(%rbp), %rdi
callq 0xac88
jmp 0x111d7e
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0xac60
movq %rax, -0x570(%rbp)
jmp 0x110f88
movq -0x570(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x11139f
leaq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0xac60
movq %rax, -0x578(%rbp)
jmp 0x110fb2
movq -0x578(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x43, %eax
jne 0x11139f
leaq -0x320(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x9, %edx
callq 0x7bbe0
jmp 0x110fdc
leaq -0x1b0(%rbp), %rdi
movq %rdi, -0x588(%rbp)
leaq -0x320(%rbp), %rsi
movq %rsi, -0x590(%rbp)
callq 0x50c30
movq -0x590(%rbp), %rdi
callq 0x3dfa0
movq -0x588(%rbp), %rdi
callq 0x44030
movq %rax, -0x348(%rbp)
leaq -0x348(%rbp), %rdi
movl $0x9, %esi
callq 0x44390
movq -0x588(%rbp), %rdi
movq %rax, -0x340(%rbp)
callq 0x44060
movq %rax, -0x350(%rbp)
leaq -0x351(%rbp), %rdi
movq %rdi, -0x580(%rbp)
callq 0x48e80
movq -0x580(%rbp), %rcx
movq -0x340(%rbp), %rsi
movq -0x350(%rbp), %rdx
leaq -0x338(%rbp), %rdi
callq 0xc6600
jmp 0x11107d
leaq -0x351(%rbp), %rdi
callq 0x40090
movq $0x0, -0x360(%rbp)
movq -0x360(%rbp), %rax
movq %rax, -0x598(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x3ffd0
movq %rax, %rcx
movq -0x598(%rbp), %rax
cmpq %rcx, %rax
je 0x111164
movq -0x360(%rbp), %rsi
leaq -0x338(%rbp), %rdi
callq 0x3d940
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x584d0
movq %rax, -0x5a0(%rbp)
jmp 0x1110ec
leaq -0x138(%rbp), %rdi
leaq -0x360(%rbp), %rsi
callq 0x95260
movq %rax, -0x5a8(%rbp)
jmp 0x111108
movq -0x5a0(%rbp), %rsi
movq -0x5a8(%rbp), %rdi
callq 0xa060
jmp 0x11111d
jmp 0x11111f
movq -0x360(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x360(%rbp)
jmp 0x111094
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x351(%rbp), %rdi
callq 0x40090
jmp 0x111d7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x11138e
leaq -0xa8(%rbp), %rdi
callq 0x6c3d0
movq %rax, -0x368(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x6c430
movq %rax, -0x370(%rbp)
leaq -0x368(%rbp), %rdi
leaq -0x370(%rbp), %rsi
callq 0x6c400
testb $0x1, %al
jne 0x1111a6
jmp 0x111371
leaq -0x368(%rbp), %rdi
callq 0x6c460
movq %rax, %rsi
leaq -0x390(%rbp), %rdi
callq 0xa250
jmp 0x1111c3
leaq -0x368(%rbp), %rdi
callq 0x6c460
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x3a8(%rbp), %rdi
callq 0x3fee0
jmp 0x1111e4
leaq -0x3c0(%rbp), %rdi
leaq -0x338(%rbp), %rsi
leaq -0x3a8(%rbp), %rdx
callq 0x81250
jmp 0x111200
leaq -0x3c0(%rbp), %rdi
callq 0x95340
testb $0x1, %al
jne 0x111215
jmp 0x1112f1
movq 0x87dd4(%rip), %rdi     # 0x198ff0
leaq 0x2b6b8(%rip), %rsi     # 0x13c8db
callq 0xa5c0
movq %rax, -0x5b0(%rbp)
jmp 0x111231
movq -0x5b0(%rbp), %rdi
leaq -0x390(%rbp), %rsi
callq 0xa520
movq %rax, -0x5b8(%rbp)
jmp 0x11124d
movq -0x5b8(%rbp), %rdi
leaq 0x2a1b4(%rip), %rsi     # 0x13b40f
callq 0xa5c0
movq %rax, -0x5c0(%rbp)
jmp 0x111269
movq -0x5c0(%rbp), %rdi
movq 0x87d11(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0x11127e
leaq -0x3c0(%rbp), %rdi
callq 0x95340
xorb $-0x1, %al
testb $0x1, %al
jne 0x111292
jmp 0x111294
jmp 0x1112ef
leaq 0x2b66a(%rip), %rdi     # 0x13c905
leaq 0x3bf82(%rip), %rsi     # 0x14d224
movl $0x68, %edx
leaq 0x3bf88(%rip), %rcx     # 0x14d236
callq 0xa390
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x111363
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x111357
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x3c0(%rbp), %rdi
callq 0x50d40
jmp 0x111357
jmp 0x1112f1
leaq -0x108(%rbp), %rdi
leaq -0x390(%rbp), %rsi
callq 0x95380
movq %rax, -0x5c8(%rbp)
jmp 0x11130d
movq -0x5c8(%rbp), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0x95460
jmp 0x111322
leaq -0x3c0(%rbp), %rdi
callq 0x50d40
leaq -0x3a8(%rbp), %rdi
callq 0x3dfa0
leaq -0x390(%rbp), %rdi
callq 0xac88
leaq -0x368(%rbp), %rdi
callq 0x71fc0
jmp 0x111177
leaq -0x3a8(%rbp), %rdi
callq 0x3dfa0
leaq -0x390(%rbp), %rdi
callq 0xac88
jmp 0x11138e
callq 0xa3a0
movq %rax, -0x208(%rbp)
leaq -0x338(%rbp), %rdi
callq 0x3dfa0
jmp 0x111cdf
leaq -0x338(%rbp), %rdi
callq 0x3dfa0
jmp 0x111d7e
movl -0x17c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17c(%rbp)
cmpl $0x1, -0x17c(%rbp)
jne 0x111517
movq -0x228(%rbp), %rdi
leaq 0x3be86(%rip), %rsi     # 0x14d24f
callq 0xa5c0
movq %rax, -0x5d0(%rbp)
jmp 0x1113d7
movq -0x5d0(%rbp), %rdi
leaq 0x24af9(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x5d8(%rbp)
jmp 0x1113f3
movq -0x5d8(%rbp), %rdi
leaq 0x3be52(%rip), %rsi     # 0x14d253
callq 0xa5c0
movq %rax, -0x5e0(%rbp)
jmp 0x11140f
movq -0x5e0(%rbp), %rdi
leaq 0x24ac1(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x5e8(%rbp)
jmp 0x11142b
movq -0x5e8(%rbp), %rdi
leaq 0x2234f(%rip), %rsi     # 0x133788
callq 0xa5c0
movq %rax, -0x5f0(%rbp)
jmp 0x111447
movq -0x5f0(%rbp), %rdi
leaq 0x24a89(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x5f8(%rbp)
jmp 0x111463
movq -0x5f8(%rbp), %rdi
leaq 0x3b4d2(%rip), %rsi     # 0x14c943
callq 0xa5c0
jmp 0x111478
leaq -0x108(%rbp), %rdi
callq 0x112150
movq %rax, -0x3c8(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x97ee0
movq %rax, -0x3d0(%rbp)
leaq -0x3c8(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
callq 0x112180
testb $0x1, %al
jne 0x1114b7
jmp 0x111500
movq -0x228(%rbp), %rdi
leaq 0x24a19(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x600(%rbp)
jmp 0x1114d3
leaq -0x3c8(%rbp), %rdi
callq 0x1121b0
movq -0x600(%rbp), %rdi
movq %rax, %rsi
callq 0xa520
jmp 0x1114f0
jmp 0x1114f2
leaq -0x3c8(%rbp), %rdi
callq 0x98b80
jmp 0x11148b
movq -0x228(%rbp), %rdi
leaq 0x1e37f(%rip), %rsi     # 0x12f88d
callq 0xa5c0
jmp 0x111515
jmp 0x111517
movl -0x17c(%rbp), %eax
cltd
idivl -0x1b4(%rbp)
cmpl $0x0, %edx
jne 0x1115f8
callq 0xa3a0
movq -0x208(%rbp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x27edf(%rip), %xmm1    # 0x139428
divsd %xmm1, %xmm0
movsd %xmm0, -0x218(%rbp)
movq 0x87a94(%rip), %rdi     # 0x198ff0
leaq 0x2b3e3(%rip), %rsi     # 0x13c946
callq 0xa5c0
movq %rax, -0x608(%rbp)
jmp 0x111571
movq -0x608(%rbp), %rdi
movl -0x17c(%rbp), %esi
callq 0xab20
movq %rax, -0x610(%rbp)
jmp 0x11158c
movq -0x610(%rbp), %rdi
leaq 0x2e5e8(%rip), %rsi     # 0x13fb82
callq 0xa5c0
movq %rax, -0x618(%rbp)
jmp 0x1115a8
movq -0x618(%rbp), %rdi
movsd -0x218(%rbp), %xmm0
callq 0xabd0
movq %rax, -0x620(%rbp)
jmp 0x1115c5
movq -0x620(%rbp), %rdi
leaq 0x31515(%rip), %rsi     # 0x142ae8
callq 0xa5c0
movq %rax, -0x628(%rbp)
jmp 0x1115e1
movq -0x628(%rbp), %rdi
movq 0x87999(%rip), %rsi     # 0x198f88
callq 0xa610
jmp 0x1115f6
jmp 0x1115f8
leaq -0x3e8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0x9, %edx
callq 0x7bbe0
jmp 0x11160f
leaq -0x1b0(%rbp), %rdi
movq %rdi, -0x630(%rbp)
leaq -0x3e8(%rbp), %rsi
movq %rsi, -0x638(%rbp)
callq 0x50c30
movq -0x638(%rbp), %rdi
callq 0x3dfa0
movq -0x630(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0x1d8(%rbp), %rdi
callq 0xa060
jmp 0x11165d
leaq -0x1b0(%rbp), %rdi
movl $0x1, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0x1f8(%rbp), %rdi
callq 0xa060
jmp 0x11167f
leaq -0x408(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0xa250
jmp 0x111694
leaq -0x408(%rbp), %rdi
callq 0x7bab0
movsd %xmm0, -0x640(%rbp)
jmp 0x1116aa
movsd -0x640(%rbp), %xmm0
movsd %xmm0, -0x200(%rbp)
leaq -0x408(%rbp), %rdi
callq 0xac88
leaq -0x1b0(%rbp), %rdi
movq %rdi, -0x650(%rbp)
callq 0x44030
movq %rax, -0x430(%rbp)
leaq -0x430(%rbp), %rdi
movl $0x9, %esi
callq 0x44390
movq -0x650(%rbp), %rdi
movq %rax, -0x428(%rbp)
callq 0x44060
movq %rax, -0x438(%rbp)
leaq -0x439(%rbp), %rdi
movq %rdi, -0x648(%rbp)
callq 0x48e80
movq -0x648(%rbp), %rcx
movq -0x428(%rbp), %rsi
movq -0x438(%rbp), %rdx
leaq -0x420(%rbp), %rdi
callq 0xc6600
jmp 0x111741
leaq -0x439(%rbp), %rdi
callq 0x40090
leaq -0x1b0(%rbp), %rdi
movl $0x3, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0x460(%rbp), %rdi
callq 0xa250
jmp 0x11176f
leaq -0x1b0(%rbp), %rdi
movl $0x4, %esi
callq 0x3d940
movq %rax, %rsi
leaq -0x480(%rbp), %rdi
callq 0xa250
jmp 0x111791
leaq -0x460(%rbp), %rdi
callq 0xa930
cmpq $0x1, %rax
ja 0x1117df
leaq -0x480(%rbp), %rdi
callq 0xa930
cmpq $0x1, %rax
ja 0x1117df
leaq 0x3ca26(%rip), %rsi     # 0x14e1e2
leaq -0x480(%rbp), %rdi
callq 0x2d770
movb %al, -0x651(%rbp)
jmp 0x1117d0
movb -0x651(%rbp), %al
testb $0x1, %al
jne 0x1117df
jmp 0x1118ba
leaq -0x460(%rbp), %rdi
movq %rdi, -0x670(%rbp)
callq 0xa7b0
movq -0x670(%rbp), %rdi
callq 0xac30
leaq -0x480(%rbp), %rdi
movq %rdi, -0x668(%rbp)
callq 0xa7b0
movq -0x668(%rbp), %rdi
callq 0xac30
leaq -0x420(%rbp), %rdi
movq %rdi, -0x660(%rbp)
callq 0x591f0
movq -0x660(%rbp), %rdi
callq 0xc6680
jmp 0x11183e
movl $0x7, -0x484(%rbp)
jmp 0x111c7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x408(%rbp), %rdi
callq 0xac88
jmp 0x111d7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x439(%rbp), %rdi
callq 0x40090
jmp 0x111d7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x111cce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x111cc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x111cb6
callq 0xa3a0
movq %rax, -0x210(%rbp)
movl $0x240, %edi            # imm = 0x240
callq 0xa5d0
movq %rax, -0x678(%rbp)
jmp 0x1118d9
leaq -0x420(%rbp), %rdi
callq 0x3ffd0
movq -0x678(%rbp), %rdi
movl %eax, %edx
leaq -0x108(%rbp), %rsi
callq 0xc66a0
jmp 0x1118fc
movq -0x678(%rbp), %rax
movq %rax, -0x490(%rbp)
movq -0x490(%rbp), %rdi
leaq -0x420(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x7b530
jmp 0x111926
callq 0xa3a0
movq -0x210(%rbp), %rcx
subq %rcx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x27ae6(%rip), %xmm1    # 0x139428
divsd %xmm1, %xmm0
movsd %xmm0, -0x220(%rbp)
movq -0x228(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0xa520
movq %rax, -0x680(%rbp)
jmp 0x11196a
movq -0x680(%rbp), %rdi
leaq 0x24566(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x688(%rbp)
jmp 0x111986
movq -0x688(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0xa520
movq %rax, -0x690(%rbp)
jmp 0x1119a2
movq -0x690(%rbp), %rdi
leaq 0x2452e(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x698(%rbp)
jmp 0x1119be
movq -0x698(%rbp), %rdi
leaq -0x460(%rbp), %rsi
callq 0xa520
movq %rax, -0x6a0(%rbp)
jmp 0x1119da
movq -0x6a0(%rbp), %rdi
leaq 0x244f6(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x6a8(%rbp)
jmp 0x1119f6
movq -0x6a8(%rbp), %rdi
leaq -0x480(%rbp), %rsi
callq 0xa520
jmp 0x111a0b
testb $0x1, 0x89ba6(%rip)     # 0x19b5b8
je 0x111b74
movq -0x490(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x82d90
movl %eax, -0x6ac(%rbp)
jmp 0x111a33
movl -0x6ac(%rbp), %eax
movl %eax, -0x494(%rbp)
cmpl $0x0, -0x494(%rbp)
jne 0x111ab3
xorl %eax, %eax
movl %eax, %esi
leaq -0x1b0(%rbp), %rdi
movq %rdi, -0x6c0(%rbp)
callq 0x3d940
movq -0x6c0(%rbp), %rdi
movq %rax, -0x6b8(%rbp)
movl $0x1, %esi
callq 0x3d940
movq -0x6b8(%rbp), %rdi
movq %rax, %rsi
callq 0x7ac40
jmp 0x111a88
movb $0x0, 0x89b29(%rip)     # 0x19b5b8
jmp 0x111ad7
movq -0x678(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
movl $0x240, %esi            # imm = 0x240
callq 0xa5e0
jmp 0x111cb6
movq -0x490(%rbp), %rdi
movl -0x494(%rbp), %ecx
leaq -0x420(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0x82670
jmp 0x111ad5
jmp 0x111ad7
movq -0x490(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x84460
movq %rax, -0x4a0(%rbp)
movq -0x490(%rbp), %rdi
addq $0x150, %rdi            # imm = 0x150
callq 0x844c0
movq %rax, -0x4a8(%rbp)
leaq -0x4a0(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x84490
testb $0x1, %al
jne 0x111b24
jmp 0x111b6f
movq -0x228(%rbp), %rdi
leaq 0x243ac(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x6c8(%rbp)
jmp 0x111b40
leaq -0x4a0(%rbp), %rdi
callq 0x844f0
movq -0x6c8(%rbp), %rdi
movsd 0x20(%rax), %xmm0
callq 0xabd0
jmp 0x111b5f
jmp 0x111b61
leaq -0x4a0(%rbp), %rdi
callq 0x84510
jmp 0x111af1
jmp 0x111c0e
movq -0x490(%rbp), %rdi
addq $0xe0, %rdi
callq 0x84460
movq %rax, -0x4b0(%rbp)
movq -0x490(%rbp), %rdi
addq $0xe0, %rdi
callq 0x844c0
movq %rax, -0x4b8(%rbp)
leaq -0x4b0(%rbp), %rdi
leaq -0x4b8(%rbp), %rsi
callq 0x84490
testb $0x1, %al
jne 0x111bc1
jmp 0x111c0c
movq -0x228(%rbp), %rdi
leaq 0x2430f(%rip), %rsi     # 0x135ede
callq 0xa5c0
movq %rax, -0x6d0(%rbp)
jmp 0x111bdd
leaq -0x4b0(%rbp), %rdi
callq 0x844f0
movq -0x6d0(%rbp), %rdi
movsd 0x20(%rax), %xmm0
callq 0xabd0
jmp 0x111bfc
jmp 0x111bfe
leaq -0x4b0(%rbp), %rdi
callq 0x84510
jmp 0x111b8e
jmp 0x111c0e
movq -0x228(%rbp), %rdi
leaq 0x1dc71(%rip), %rsi     # 0x12f88d
callq 0xa5c0
jmp 0x111c23
leaq -0x420(%rbp), %rdi
movq %rdi, -0x6d8(%rbp)
callq 0x591f0
movq -0x6d8(%rbp), %rdi
callq 0xc6680
jmp 0x111c44
movq -0x490(%rbp), %rax
movq %rax, -0x6e0(%rbp)
cmpq $0x0, %rax
je 0x111c75
movq -0x6e0(%rbp), %rdi
callq 0xc6bd0
movq -0x6e0(%rbp), %rdi
movl $0x240, %esi            # imm = 0x240
callq 0xa5e0
movl $0x0, -0x484(%rbp)
leaq -0x480(%rbp), %rdi
callq 0xac88
leaq -0x460(%rbp), %rdi
callq 0xac88
leaq -0x420(%rbp), %rdi
callq 0x3dfa0
movl -0x484(%rbp), %eax
testl %eax, %eax
je 0x111cb4
jmp 0x111caf
jmp 0x110d71
jmp 0x111cdf
leaq -0x480(%rbp), %rdi
callq 0xac88
leaq -0x460(%rbp), %rdi
callq 0xac88
leaq -0x420(%rbp), %rdi
callq 0x3dfa0
jmp 0x111d7e
jmp 0x111ce1
jmp 0x110d71
movq -0x228(%rbp), %rdi
callq 0xa3b0
jmp 0x111cf4
movl $0x1, -0x484(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0xac88
leaq -0x1d8(%rbp), %rdi
callq 0xac88
leaq -0x1b0(%rbp), %rdi
callq 0x3dfa0
leaq -0x198(%rbp), %rdi
callq 0x3dfa0
leaq -0x168(%rbp), %rdi
callq 0x3dfa0
leaq -0x138(%rbp), %rdi
callq 0x95b50
leaq -0x108(%rbp), %rdi
callq 0x95b70
leaq -0xd8(%rbp), %rdi
callq 0x58620
leaq -0xa8(%rbp), %rdi
callq 0x58f00
leaq -0x30(%rbp), %rdi
callq 0xac88
xorl %eax, %eax
addq $0x6e0, %rsp            # imm = 0x6E0
popq %rbp
retq
leaq -0x1f8(%rbp), %rdi
callq 0xac88
leaq -0x1d8(%rbp), %rdi
callq 0xac88
leaq -0x1b0(%rbp), %rdi
callq 0x3dfa0
leaq -0x198(%rbp), %rdi
callq 0x3dfa0
leaq -0x168(%rbp), %rdi
callq 0x3dfa0
leaq -0x138(%rbp), %rdi
callq 0x95b50
leaq -0x108(%rbp), %rdi
callq 0x95b70
leaq -0xd8(%rbp), %rdi
callq 0x58620
leaq -0xa8(%rbp), %rdi
callq 0x58f00
leaq -0x30(%rbp), %rdi
callq 0xac88
movq -0x68(%rbp), %rdi
callq 0xab50
nopl (%rax)