// File: /workspace/github_cpp_makefile_star2_O3/millanek[P]evo/process_vcf_search_sex.cpp
// Function: sexSearchMain(int, char**)
int sexSearchMain(int argc, char** argv) {
    parseSexSearchOptions(argc, argv);
    string fileRoot = stripExtension(opt::vcfFile);
    
    std::cerr << "Looking for the X and Y sex determining sequences using data from: " << opt::vcfFile << std::endl;
    std::cerr << "and male/female status defined in: " << opt::genderFile << std::endl;
    std::cerr << "The window width is: " << opt::window << " variants" << std::endl;
    
    // Open connections to read from the vcf and reference genome files
    std::ifstream* vcfFile = new std::ifstream(opt::vcfFile.c_str());
    std::ifstream* genderFile = new std::ifstream(opt::genderFile.c_str());
    
    string pValFileName = "sex_t_pvals_w" + numToString(opt::window) + ".txt";
    std::ofstream* pValFile = new std::ofstream(pValFileName.c_str());
    
    string maleString; string femaleString;
    getline(*genderFile, maleString);
    getline(*genderFile, femaleString);
    std::vector<string> males = split(maleString, ',');
    std::vector<string> females = split(femaleString, ',');
    std::sort(males.begin(),males.end());
    std::sort(females.begin(),females.end());
    
    
    // Prepare an object for output files
    
    string line;
    string currentScaffoldNum = "";
    string currentScaffoldReference;
    std::vector<string> sampleNames;
    string thisScaffoldName;
    std::vector<size_t> maleLoci;
    std::vector<size_t> femaleLoci;
    std::vector<SetDepths> setDepthsVector;
    std::vector<double> set1MeanDepths;
    std::vector<double> set2MeanDepths;
    unsigned int processedVariantCounter = 0;
    unsigned int regionStart = 1;
    std::vector<int> YlikeCounts;
    std::vector<int> nonZeroYlikeCounts;
    
    while (getline(*vcfFile, line)) {
        if (line[0] == '#' && line[1] == '#') {
            continue;
        } else if (line[0] == '#' && line[1] == 'C') {
            std::vector<std::string> fields = split(line, '\t');
            if (opt::sampleNameFile.empty()) {
                for (std::vector<std::string>::size_type i = NUM_NON_GENOTYPE_COLUMNS; i != fields.size(); i++) {
                    sampleNames.push_back(fields[i]);
                }
            } else {
                sampleNames = readSampleNamesFromTextFile(opt::sampleNameFile);
            }
            maleLoci = locateSet(sampleNames, males);
            femaleLoci = locateSet(sampleNames, females);
        } else {
            processedVariantCounter++;
            std::vector<std::string> fields = split(line, '\t');
            
            SetDepths depths = getSetVariantDepths(fields,maleLoci,femaleLoci);
            setDepthsVector.push_back(depths);
            set1MeanDepths.push_back(depths.set1_mean_depth);
            set2MeanDepths.push_back(depths.set2_mean_depth);
            
            if (processedVariantCounter % opt::window == 0) {
                int Ylike = 0;
                for (std::vector<SetDepths>::size_type i = 0; i != setDepthsVector.size(); i++) {
                    // Could this be a Y region
                    if(setDepthsVector[i].set1_mean_depth > 2 && setDepthsVector[i].set2_mean_depth <= 1) {
                        Ylike++;
                    }
                }
                
                // std::cerr << "Region: " << fields[0] << "\t" << regionStart << "-" << fields[1] << "processed" << std::endl;
                // std::cerr << Ylike << " Ylike variants" << std::endl;
                YlikeCounts.push_back(Ylike);
                if (Ylike > (opt::window/2)) {
                    std::cout << "Putative Y region: " << fields[0] << "\t" << regionStart << "-" << fields[1] << std::endl;
                }
                if (Ylike > 0) {
                    nonZeroYlikeCounts.push_back(Ylike);
                    std::cerr << "Region: " << fields[0] << "\t" << regionStart << "-" << fields[1] << "processed" << std::endl;
                    std::cerr << Ylike << " Ylike variants" << std::endl;
                }
                
                
               /* if (regionStart == 182909) {
                   // std::cerr << "Here " << set1MeanDepths.size() << "\t" << set1MeanDepths[50] << std::endl;
                  //  print_vector_stream(set1MeanDepths, std::cerr, '\n');
                  //  std::cerr << "Here " << set2MeanDepths.size() << std::endl;
                  //  print_vector_stream(depths.set1Depths, std::cerr, '\n');
                    //std::cerr << "Here " << set2MeanDepths.size() << std::endl;
                    //print_vector_stream(set2MeanDepths, std::cerr, '\n');
                    //std::cerr << "Here " << set2MeanDepths.size() << std::endl;
                    //print_vector_stream(depths.set2Depths, std::cerr, '\n');
                }
                */
                // alternative hypothesis: true difference in means is greater than 5
                double pval_t = two_sample_t(set1MeanDepths,set2MeanDepths);
                
                if (pval_t < 0.001) {
                    string loc = fields[0] + "\t" + numToString(regionStart) + "\t" + fields[1];
                    *pValFile << loc << "\t" << pval_t << "\t" << vector_average(set1MeanDepths) << "\t" << vector_average(set2MeanDepths) << std::endl;
                }
                
                //std::cerr << "Region: " << fields[0] << "\t" << regionStart << "-" << fields[1] << "processed" << std::endl;
                regionStart = atoi(fields[1].c_str());
                setDepthsVector.clear();
                set1MeanDepths.clear(); set2MeanDepths.clear();
                
            }
            if (processedVariantCounter % 100000 == 0)
                std::cerr << processedVariantCounter << " variants processed" << std::endl;
        }
    }
    
    std::ofstream* YlikeCountsDistribution = new std::ofstream("YlikeCounts.txt");
    print_vector(YlikeCounts, *YlikeCountsDistribution, '\n');
    std::ofstream* nonZeroYlikeCountsDistribution = new std::ofstream("nonZeroYlikeCounts.txt");
    print_vector(YlikeCounts, *nonZeroYlikeCountsDistribution, '\n');
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
callq 0x81a18
leaq 0x835dd(%rip), %rsi     # 0x103790
leaq 0x3b8(%rsp), %rdi
callq 0x4d82f
movq 0x81e21(%rip), %rdi     # 0x101fe8
leaq 0x57852(%rip), %rsi     # 0xd7a20
movl $0x43, %edx
callq 0x84e0
movq 0x835b1(%rip), %rsi     # 0x103790
movq 0x835b2(%rip), %rdx     # 0x103798
movq 0x81dfb(%rip), %rdi     # 0x101fe8
callq 0x84e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %rbx, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x81dc5(%rip), %rdi     # 0x101fe8
leaq 0x5783a(%rip), %rsi     # 0xd7a64
movl $0x23, %edx
callq 0x84e0
movq 0x83575(%rip), %rsi     # 0x1037b0
movq 0x83576(%rip), %rdx     # 0x1037b8
movq 0x81d9f(%rip), %rdi     # 0x101fe8
callq 0x84e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %rbx, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x81d69(%rip), %rdi     # 0x101fe8
leaq 0x57802(%rip), %rsi     # 0xd7a88
movl $0x15, %edx
callq 0x84e0
movl 0x822e6(%rip), %esi     # 0x10257c
movq 0x81d4b(%rip), %rdi     # 0x101fe8
callq 0x8810
movq %rax, %rbx
leaq 0x57823(%rip), %rsi     # 0xd7acf
movl $0x9, %edx
movq %rax, %rdi
callq 0x84e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %rbx, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movl $0x208, %edi            # imm = 0x208
callq 0x8470
movq %rax, %rbx
movq 0x8349c(%rip), %rsi     # 0x103790
movq %rax, %rdi
movl $0x8, %edx
callq 0x8860
movl $0x208, %edi            # imm = 0x208
callq 0x8470
movq %rax, %r15
movq 0x8349b(%rip), %rsi     # 0x1037b0
movq %rax, %rdi
movl $0x8, %edx
callq 0x8860
movl 0x82254(%rip), %esi     # 0x10257c
leaq 0x110(%rsp), %rdi
callq 0x2e7e2
leaq 0x57762(%rip), %rcx     # 0xd7a9e
leaq 0x110(%rsp), %rdi
movl $0xd, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x84d0
leaq 0x80(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x80381
movq %rdx, 0x70(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x80(%rsp)
jmp 0x8038b
movupd (%rcx), %xmm0
movupd %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq 0x70(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x5cd97(%rip), %rsi     # 0xdd145
callq 0x88c0
leaq 0x220(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x803e3
movq %rdx, 0x210(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x220(%rsp)
jmp 0x803eb
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x218(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x80420
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x120(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x80441
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x8480
movl $0x200, %edi            # imm = 0x200
callq 0x8470
movq %rax, %r12
movq 0x210(%rsp), %rsi
movq %rax, %rdi
movl $0x10, %edx
callq 0x84c0
movq %r14, 0x110(%rsp)
xorl %eax, %eax
movq %rax, 0x118(%rsp)
movb %al, 0x120(%rsp)
leaq 0x2b0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
leaq 0x110(%rsp), %rsi
movq %r15, %rdi
callq 0x8870
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
leaq 0x2a0(%rsp), %rsi
movq %r15, %rdi
callq 0x8870
leaq 0x348(%rsp), %rdi
leaq 0x110(%rsp), %rsi
movl $0x2c, %edx
callq 0x4d650
leaq 0x330(%rsp), %rdi
leaq 0x2a0(%rsp), %rsi
movl $0x2c, %edx
callq 0x4d650
movq 0x348(%rsp), %r14
movq 0x350(%rsp), %r15
cmpq %r15, %r14
je 0x80552
movq %r15, %rax
subq %r14, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x5fd9c
movq %r14, %rdi
movq %r15, %rsi
callq 0x5fe70
movq 0x330(%rsp), %r14
movq 0x338(%rsp), %r15
cmpq %r15, %r14
je 0x80594
movq %r15, %rax
subq %r14, %rax
sarq $0x5, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x5fd9c
movq %r14, %rdi
movq %r15, %rsi
callq 0x5fe70
movq %r12, 0x2c0(%rsp)
leaq 0x290(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x320(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x4d405(%rip), %rdx     # 0xcd9cb
leaq 0x310(%rsp), %rdi
movq %rdx, %rsi
callq 0x28a52
leaq 0x390(%rsp), %rax
movq %rax, -0x10(%rax)
xorl %r15d, %r15d
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq 0x170(%rsp), %rax
movq %r15, 0x10(%rax)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rax)
leaq 0x370(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
leaq 0x150(%rsp), %rax
movq %r15, 0x10(%rax)
movapd %xmm0, (%rax)
leaq 0x1c0(%rsp), %rax
movq %r15, 0x10(%rax)
movapd %xmm0, (%rax)
leaq 0x230(%rsp), %rax
movq %r15, 0x10(%rax)
movapd %xmm0, (%rax)
leaq 0x50(%rsp), %rax
movq %r15, 0x10(%rax)
movapd %xmm0, (%rax)
leaq 0x30(%rsp), %rax
movq %r15, 0x10(%rax)
movapd %xmm0, (%rax)
leaq 0x130(%rsp), %rax
movq %r15, 0x10(%rax)
movapd %xmm0, (%rax)
leaq 0x1a0(%rsp), %rax
movq %r15, 0x10(%rax)
movapd %xmm0, (%rax)
movl $0x1, 0xc(%rsp)
leaq 0x280(%rsp), %r14
movq $0x0, 0x1e0(%rsp)
movq $0x0, 0x1e8(%rsp)
xorl %ebp, %ebp
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x8870
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x81275
movq 0x280(%rsp), %rax
cmpb $0x23, (%rax)
jne 0x807a6
movzbl 0x1(%rax), %eax
cmpl $0x23, %eax
je 0x806a7
cmpl $0x43, %eax
jne 0x807a6
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movl $0x9, %edx
callq 0x4d650
cmpq $0x0, 0x830c0(%rip)     # 0x1037d8
je 0x808ca
leaq 0xb0(%rsp), %r15
movq %r15, %rdi
leaq 0x830a0(%rip), %rsi     # 0x1037d0
callq 0x4fe41
movq 0x180(%rsp), %rax
movapd 0xb0(%rsp), %xmm0
movq 0xc0(%rsp), %rcx
movq %rcx, 0x180(%rsp)
movapd 0x170(%rsp), %xmm1
movapd %xmm0, 0x170(%rsp)
movapd %xmm1, 0x70(%rsp)
movq %rax, 0x80(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0xb0(%rsp)
movq $0x0, 0xc0(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x2e784
movq %r15, %rdi
callq 0x2e784
jmp 0x80918
leaq 0x188(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movl $0x9, %edx
callq 0x4d650
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
leaq 0x150(%rsp), %rdx
leaq 0x1c0(%rsp), %rcx
callq 0x7fff0
leaq 0x230(%rsp), %rdi
movq %r12, %rsi
callq 0x81e1c
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x80812
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x58(%rsp)
jmp 0x80824
leaq 0x50(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x79b8e
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x80848
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x8085a
leaq 0x30(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x79b8e
incl %ebp
movl %ebp, %eax
xorl %edx, %edx
divl 0x81d16(%rip)           # 0x10257c
testl %edx, %edx
jne 0x811cf
movq 0x230(%rsp), %rax
movq 0x238(%rsp), %rcx
movl $0x0, 0x8(%rsp)
subq %rax, %rcx
je 0x80a4b
sarq $0x6, %rcx
addq $0x38, %rax
xorl %edx, %edx
movsd -0x8(%rax), %xmm0
ucomisd 0x5527a(%rip), %xmm0    # 0xd5b20
jbe 0x808bc
movsd 0x4be60(%rip), %xmm0    # 0xcc710
ucomisd (%rax), %xmm0
jb 0x808bc
incl %edx
movl %edx, 0x8(%rsp)
addq $0x40, %rax
decq %rcx
jne 0x80899
jmp 0x80a4d
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
cmpq $0x120, %rax            # imm = 0x120
je 0x80918
movl $0x9, %r15d
movl $0x120, %r12d           # imm = 0x120
addq %r12, %rsi
leaq 0x170(%rsp), %rdi
callq 0x3133c
incq %r15
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %r12
cmpq %rax, %r15
jne 0x808eb
leaq 0x70(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x348(%rsp), %rdx
callq 0x5038c
movq 0x150(%rsp), %rdi
movq 0x160(%rsp), %rsi
movq 0x70(%rsp), %r15
movq %r15, 0x150(%rsp)
movupd 0x78(%rsp), %xmm0
movupd %xmm0, 0x158(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
testq %rdi, %rdi
je 0x8099b
subq %rdi, %rsi
callq 0x8480
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x8099b
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
leaq 0x70(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x330(%rsp), %rdx
callq 0x5038c
movq 0x1c0(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rax
movq %rdx, 0x1e8(%rsp)
movq %rdx, 0x1c0(%rsp)
movq %rax, 0x1c8(%rsp)
movq 0x80(%rsp), %rcx
movq %rcx, 0x1e0(%rsp)
movq %rcx, 0x1d0(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
testq %rdi, %rdi
je 0x80a3c
subq %rdi, %rsi
callq 0x8480
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x80a3c
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
leaq 0x10(%rsp), %rdi
callq 0x2e784
jmp 0x806a7
xorl %edx, %edx
movq 0x138(%rsp), %rsi
cmpq 0x140(%rsp), %rsi
je 0x80a6f
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x138(%rsp)
jmp 0x80a81
leaq 0x130(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x48c2e
movl 0x8(%rsp), %eax
movl 0x81af1(%rip), %ecx     # 0x10257c
movl %ecx, %edx
shrl $0x1f, %edx
addl %ecx, %edx
sarl %edx
movl 0xc(%rsp), %r12d
cmpl %edx, %eax
jle 0x80b53
movl $0x13, %edx
movq 0x8150b(%rip), %rdi     # 0x101fb8
leaq 0x56ff8(%rip), %rsi     # 0xd7aac
callq 0x84e0
movq 0x188(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x814e9(%rip), %rdi     # 0x101fb8
callq 0x84e0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4cee4(%rip), %rsi     # 0xcd9ca
callq 0x84e0
movq %r13, %rdi
movq %r12, %rsi
callq 0x82f0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4c5b0(%rip), %rsi     # 0xcd0b8
callq 0x84e0
movq 0x188(%rsp), %rax
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
movq %r13, %rdi
callq 0x84e0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r13, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movl 0x8(%rsp), %eax
testl %eax, %eax
jle 0x80ca1
movq 0x1a8(%rsp), %rsi
cmpq 0x1b0(%rsp), %rsi
je 0x80b7d
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x1a8(%rsp)
jmp 0x80b8f
leaq 0x1a0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x48c2e
movl $0x8, %edx
movq 0x8144d(%rip), %rdi     # 0x101fe8
leaq 0x56f1e(%rip), %rsi     # 0xd7ac0
callq 0x84e0
movq 0x188(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x8142b(%rip), %rdi     # 0x101fe8
callq 0x84e0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4cdf6(%rip), %rsi     # 0xcd9ca
callq 0x84e0
movq %r13, %rdi
movq %r12, %rsi
callq 0x82f0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4c4c2(%rip), %rsi     # 0xcd0b8
callq 0x84e0
movq 0x188(%rsp), %rax
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
movq %r12, %rdi
callq 0x84e0
movq %rax, %r12
movl $0x9, %edx
movq %rax, %rdi
leaq 0x56ebe(%rip), %rsi     # 0xd7ae3
callq 0x84e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r12, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movl 0x8(%rsp), %esi
movq 0x8138b(%rip), %rdi     # 0x101fe8
callq 0x8810
movq %rax, %r12
movl $0xf, %edx
movq %rax, %rdi
leaq 0x56e55(%rip), %rsi     # 0xd7ac9
callq 0x84e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r12, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
leaq 0x2f8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x37978
leaq 0x3a0(%rsp), %r12
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x37978
xorpd %xmm0, %xmm0
leaq 0x2f8(%rsp), %rdi
movq %r12, %rsi
callq 0x81e45
movsd %xmm0, 0x1d8(%rsp)
movq 0x3a0(%rsp), %rdi
testq %rdi, %rdi
je 0x80d02
movq 0x3b0(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x2f8(%rsp), %rdi
testq %rdi, %rdi
je 0x80d1f
movq 0x308(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movsd 0x56989(%rip), %xmm0    # 0xd76b0
ucomisd 0x1d8(%rsp), %xmm0
jbe 0x81183
movq 0x188(%rsp), %rax
leaq 0xe0(%rsp), %rcx
movq %rcx, 0xd0(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xd0(%rsp), %r12
movq %r12, %rdi
callq 0x2ba06
movq %r12, %rdi
leaq 0x4cc58(%rip), %rsi     # 0xcd9ca
callq 0x88c0
leaq 0x1f0(%rsp), %rdi
movl 0xc(%rsp), %esi
callq 0x82253
movq 0xd0(%rsp), %rcx
movl $0xf, %edi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rcx
je 0x80daa
movq 0xe0(%rsp), %rdi
movq 0xd8(%rsp), %r8
movq 0x1f0(%rsp), %rsi
movq 0x1f8(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x80dea
movl $0xf, %edi
leaq 0x200(%rsp), %r9
cmpq %r9, %rsi
je 0x80de5
movq 0x200(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x80df9
leaq 0xd0(%rsp), %rdi
callq 0x8180
jmp 0x80e0a
leaq 0x1f0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x84d0
leaq 0x100(%rsp), %rsi
movq %rsi, 0xf0(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x80e3b
movq %rdx, 0xf0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x100(%rsp)
jmp 0x80e43
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0xf8(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0xf0(%rsp), %rdi
leaq 0x4cb58(%rip), %rsi     # 0xcd9ca
callq 0x88c0
leaq 0xc0(%rsp), %rsi
movq %rsi, 0xb0(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x80eab
movq %rdx, 0xb0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xc0(%rsp)
jmp 0x80eb3
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0xb8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x188(%rsp), %rax
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
leaq 0xb0(%rsp), %rdi
callq 0x8180
leaq 0x20(%rsp), %rsi
movq %rsi, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x80f13
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x80f1b
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x80f58
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x80f7d
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x1f0(%rsp), %rdi
leaq 0x200(%rsp), %rax
cmpq %rax, %rdi
je 0x80fa2
movq 0x200(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x80fc7
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x2c0(%rsp), %rdi
callq 0x84e0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4c9da(%rip), %rsi     # 0xcd9ca
callq 0x84e0
movq %r12, %rdi
movsd 0x1d8(%rsp), %xmm0
callq 0x8730
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4c9b2(%rip), %rsi     # 0xcd9ca
callq 0x84e0
leaq 0x268(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x37978
movq 0x268(%rsp), %rcx
movq 0x270(%rsp), %rdx
movq %rdx, %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %rcx, %rdx
je 0x8106e
cmpq $0x1, %rax
movq %rax, %rdx
adcq $0x0, %rdx
xorpd %xmm0, %xmm0
xorl %esi, %esi
addsd (%rcx,%rsi,8), %xmm0
incq %rsi
cmpq %rsi, %rdx
jne 0x8105f
jmp 0x81072
xorpd %xmm0, %xmm0
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq %r12, %rdi
callq 0x8730
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x4c935(%rip), %rsi     # 0xcd9ca
callq 0x84e0
leaq 0x250(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x37978
movq 0x250(%rsp), %rcx
movq 0x258(%rsp), %rdx
movq %rdx, %rax
subq %rcx, %rax
sarq $0x3, %rax
cmpq %rcx, %rdx
je 0x810eb
cmpq $0x1, %rax
movq %rax, %rdx
adcq $0x0, %rdx
xorpd %xmm0, %xmm0
xorl %esi, %esi
addsd (%rcx,%rsi,8), %xmm0
incq %rsi
cmpq %rsi, %rdx
jne 0x810dc
jmp 0x810ef
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movq %r12, %rdi
callq 0x8730
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r12, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x250(%rsp), %rdi
testq %rdi, %rdi
je 0x8114a
movq 0x260(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x268(%rsp), %rdi
testq %rdi, %rdi
je 0x81167
movq 0x278(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x81183
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x188(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0x86e0
movl %eax, 0xc(%rsp)
movq 0x230(%rsp), %rsi
leaq 0x230(%rsp), %rdi
callq 0x86f02
movq 0x50(%rsp), %rax
cmpq %rax, 0x58(%rsp)
je 0x811be
movq %rax, 0x58(%rsp)
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x811cf
movq %rax, 0x38(%rsp)
imull $0xbcbe61d, %ebp, %eax  # imm = 0xBCBE61D
rorl $0x5, %eax
cmpl $0xa7c5, %eax           # imm = 0xA7C5
ja 0x8122c
movl %ebp, %esi
movq 0x80e00(%rip), %rdi     # 0x101fe8
callq 0x82f0
movq %rax, %r12
movl $0x13, %edx
movq %rax, %rdi
leaq 0x568da(%rip), %rsi     # 0xd7ad9
callq 0x84e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x8450
movsbl %al, %esi
movq %r12, %rdi
callq 0x8040
movq %rax, %rdi
callq 0x8300
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x81249
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x81263
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
leaq 0x188(%rsp), %rdi
callq 0x2e784
jmp 0x806a7
movl $0x200, %edi            # imm = 0x200
leaq 0x120(%rsp), %r14
callq 0x8470
movq %rax, %rbx
leaq 0x56863(%rip), %rsi     # 0xd7af4
movq %rax, %rdi
movl $0x10, %edx
callq 0x84c0
leaq 0x2e0(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x32ee6
leaq 0x2e0(%rsp), %rdi
movq %rbx, %rsi
movl $0xa, %edx
movl $0x1, %ecx
callq 0x3e6d2
movq 0x2e0(%rsp), %rdi
testq %rdi, %rdi
je 0x812ea
movq 0x2f0(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movl $0x200, %edi            # imm = 0x200
callq 0x8470
movq %rax, %rbx
leaq 0x567ef(%rip), %rsi     # 0xd7aed
movq %rax, %rdi
movl $0x10, %edx
callq 0x84c0
leaq 0x2c8(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x32ee6
leaq 0x2c8(%rsp), %rdi
movq %rbx, %rsi
movl $0xa, %edx
movl $0x1, %ecx
callq 0x3e6d2
movq 0x2c8(%rsp), %rdi
testq %rdi, %rdi
je 0x81357
movq 0x2d8(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x1a0(%rsp), %rdi
testq %rdi, %rdi
je 0x81374
movq 0x1b0(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x81391
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x813a8
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x813bf
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
leaq 0x230(%rsp), %rdi
callq 0x82336
movq 0x1e8(%rsp), %rdi
testq %rdi, %rdi
je 0x813f1
movq 0x1e0(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x150(%rsp), %r15
testq %r15, %r15
je 0x81409
movq 0x160(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x8480
movq 0x360(%rsp), %rdi
leaq 0x370(%rsp), %rax
cmpq %rax, %rdi
je 0x8142e
movq 0x370(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x170(%rsp), %rdi
callq 0x2e784
movq 0x380(%rsp), %rdi
leaq 0x390(%rsp), %rax
cmpq %rax, %rdi
je 0x81460
movq 0x390(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x310(%rsp), %rdi
leaq 0x320(%rsp), %rax
cmpq %rax, %rdi
je 0x81485
movq 0x320(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x280(%rsp), %rdi
leaq 0x290(%rsp), %rax
cmpq %rax, %rdi
je 0x814aa
movq 0x290(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x330(%rsp), %rdi
callq 0x2e784
leaq 0x348(%rsp), %rdi
callq 0x2e784
movq 0x2a0(%rsp), %rdi
leaq 0x2b0(%rsp), %rax
cmpq %rax, %rdi
je 0x814e9
movq 0x2b0(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x110(%rsp), %rdi
cmpq %r14, %rdi
je 0x81506
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x210(%rsp), %rdi
leaq 0x220(%rsp), %rax
cmpq %rax, %rdi
je 0x8152b
movq 0x220(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x3c8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8154c
movq 0x3c8(%rsp), %rsi
incq %rsi
callq 0x8480
xorl %eax, %eax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x815e0
movq %rax, %r14
jmp 0x81594
movq %rax, %r14
jmp 0x815b9
movq %rax, %r14
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x81594
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x815b9
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x1f0(%rsp), %rdi
leaq 0x200(%rsp), %rax
cmpq %rax, %rdi
je 0x815e3
movq 0x200(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x815e3
movq %rax, %r14
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x817f2
movq 0xe0(%rsp), %rsi
jmp 0x817be
jmp 0x817ef
jmp 0x817e3
movq %rax, %r14
movq 0x3a0(%rsp), %rdi
testq %rdi, %rdi
je 0x81638
movq 0x3b0(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
jmp 0x81638
movq %rax, %r14
movq 0x2f8(%rsp), %rdi
testq %rdi, %rdi
je 0x817f2
movq 0x308(%rsp), %rsi
subq %rdi, %rsi
jmp 0x817c1
jmp 0x817ef
jmp 0x817e3
jmp 0x817e3
jmp 0x81813
movq %rax, %r14
movq 0x2c8(%rsp), %rdi
testq %rdi, %rdi
je 0x81816
movq 0x2d8(%rsp), %rsi
jmp 0x816a9
jmp 0x816ae
movq %rax, %r14
movq 0x2e0(%rsp), %rdi
testq %rdi, %rdi
je 0x81816
movq 0x2f0(%rsp), %rsi
subq %rdi, %rsi
jmp 0x816b9
movq %rax, %r14
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x8480
jmp 0x81816
movq %rax, %r14
jmp 0x81941
movq %rax, %r14
jmp 0x81973
jmp 0x817db
movq %rax, %r14
movl $0x200, %esi            # imm = 0x200
movq %r12, %rdi
jmp 0x819c5
movq %rax, %r14
jmp 0x819ca
movq %rax, %r14
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x81712
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x81712
movq %rax, %r14
leaq 0x120(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x819ef
movq 0x120(%rsp), %rsi
jmp 0x819e7
jmp 0x8180b
movq %rax, %r14
movl $0x208, %esi            # imm = 0x208
movq %r15, %rdi
jmp 0x819ea
jmp 0x8180b
movq %rax, %r14
movl $0x208, %esi            # imm = 0x208
movq %rbx, %rdi
jmp 0x819ea
jmp 0x8180b
movq %rax, %r14
jmp 0x81788
movq %rax, %r14
movq 0x250(%rsp), %rdi
testq %rdi, %rdi
je 0x81788
movq 0x260(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x268(%rsp), %rdi
testq %rdi, %rdi
je 0x817aa
movq 0x278(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
jmp 0x817aa
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x817f2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x8480
jmp 0x817f2
jmp 0x81813
movq %rax, %r14
jmp 0x817fc
jmp 0x81813
jmp 0x81813
movq %rax, %r14
jmp 0x81966
movq %rax, %r14
jmp 0x81980
movq %rax, %r14
leaq 0x10(%rsp), %rdi
jmp 0x81804
jmp 0x817ef
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x81dec
leaq 0x188(%rsp), %rdi
callq 0x2e784
jmp 0x81816
movq %rax, %r14
jmp 0x819ef
movq %rax, %r14
movq 0x1a0(%rsp), %rdi
testq %rdi, %rdi
je 0x81833
movq 0x1b0(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x130(%rsp), %rdi
testq %rdi, %rdi
je 0x81850
movq 0x140(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x81867
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x8187e
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
leaq 0x230(%rsp), %rdi
callq 0x82336
movq 0x1c0(%rsp), %rdi
testq %rdi, %rdi
je 0x818a8
movq 0x1d0(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x818c5
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x8480
movq 0x360(%rsp), %rdi
leaq 0x370(%rsp), %rax
cmpq %rax, %rdi
je 0x818ea
movq 0x370(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x170(%rsp), %rdi
callq 0x2e784
movq 0x380(%rsp), %rdi
leaq 0x390(%rsp), %rax
cmpq %rax, %rdi
je 0x8191c
movq 0x390(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x310(%rsp), %rdi
leaq 0x320(%rsp), %rax
cmpq %rax, %rdi
je 0x81941
movq 0x320(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x280(%rsp), %rdi
leaq 0x290(%rsp), %rax
cmpq %rax, %rdi
je 0x81966
movq 0x290(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x330(%rsp), %rdi
callq 0x2e784
leaq 0x348(%rsp), %rdi
callq 0x2e784
movq 0x2a0(%rsp), %rdi
leaq 0x2b0(%rsp), %rax
cmpq %rax, %rdi
je 0x819a5
movq 0x2b0(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x819ca
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x8480
movq 0x210(%rsp), %rdi
leaq 0x220(%rsp), %rax
cmpq %rax, %rdi
je 0x819ef
movq 0x220(%rsp), %rsi
incq %rsi
callq 0x8480
leaq 0x3c8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x81a10
movq 0x3c8(%rsp), %rsi
incq %rsi
callq 0x8480
movq %r14, %rdi
callq 0x8840