// File: millanek[P]Dsuite/Dsuite_utils.cpp
// Function: GeneralSetCountsWithSplits::getBasicCountsWithSplitsNew(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::map<unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<unsigned long>, std::allocator<std::pair<unsigned long const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>> const&)
void GeneralSetCountsWithSplits::getBasicCountsWithSplitsNew(const std::vector<std::string>& genotypes, const std::map<size_t, string>& posToSpeciesMap) {
    
    // Go through the genotypes - only biallelic markers are allowed
    for (std::vector<std::string>::size_type i = 0; i != genotypes.size(); i++) {
        bool speciesDefined = true;
        std::string species; try { species = posToSpeciesMap.at(i); } catch (const std::out_of_range& oor) {
            speciesDefined = false;
        }
        
        if (speciesDefined) {
            string onlyGenotypeCalls = split(genotypes[i], ':')[0];   // The string with 0/0, 0/1, 1/0, 1/1, or e.g. 0/0/1/1 for a tetraploid
            if (onlyGenotypeCalls[0] == '.') {
                continue;   // Ignore missing data
            }
            // Find ploidy
            int l = (int)onlyGenotypeCalls.length();
            int numGTs = (l/2)+1;
            setAlleleCounts[species] += numGTs;
            
            // Go through the genotypes and fill in the data structure "GeneralSetCountsWithSplits"
            for (std::vector<std::string>::size_type j = 0; j <= l; j = j+2) {
               // std::cerr << "genotypes[i][j]: " << genotypes[i][j] << std::endl;
                setGenotypes[species].push_back(genotypes[i][j] - '0');
                if (genotypes[i][j] == '1') {
                    overall++; individualsWithVariant[i]++;
                    setAltCounts[species]++;
                }
            }
            double individualAF = (double)individualsWithVariant[i]/numGTs;
            
            /* std::cerr << "onlyGenotypeCalls: " << onlyGenotypeCalls << std::endl;
            std::cerr << "individualsWithVariant[i]: " << individualsWithVariant[i] << std::endl;
            std::cerr << "numGTs: " << numGTs << std::endl;
            std::cerr << "individualAF: " << individualAF << std::endl;
            */
            setIndividualAFs[species].push_back(individualAF);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10740
movq %rax, %rcx
movq -0xd0(%rbp), %rax
cmpq %rcx, %rax
je 0xe47f
movb $0x1, -0x21(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x87d0
movq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x10a70
movq %rax, -0xd8(%rbp)
jmp 0xe134
movq -0xd8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x8070
jmp 0xe146
jmp 0xe17e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0xe474
movq -0x50(%rbp), %rdi
callq 0x8220
movq %rax, -0x60(%rbp)
movb $0x0, -0x21(%rbp)
callq 0x8950
jmp 0xe17c
jmp 0xe17e
testb $0x1, -0x21(%rbp)
je 0xe440
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x10720
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
movl $0x3a, %edx
callq 0xaef0
jmp 0xe1ab
xorl %eax, %eax
movl %eax, %esi
leaq -0x98(%rbp), %rdi
callq 0x10b10
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
callq 0x8250
jmp 0xe1c9
leaq -0x98(%rbp), %rdi
callq 0x10760
xorl %eax, %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x8bc0
movq %rax, -0xe0(%rbp)
jmp 0xe1eb
movq -0xe0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0xe251
movl $0x4, -0x9c(%rbp)
jmp 0xe429
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xe474
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10760
jmp 0xe474
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x8c08
jmp 0xe474
leaq -0x80(%rbp), %rdi
callq 0x88b0
movq -0xc8(%rbp), %rdi
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %ecx, %eax
sarl %eax
incl %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xec(%rbp)
addq $0xc8, %rdi
leaq -0x48(%rbp), %rsi
callq 0x115c0
movq %rax, -0xe8(%rbp)
jmp 0xe2a3
movq -0xe8(%rbp), %rax
movl -0xec(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
movq $0x0, -0xb0(%rbp)
movq -0xb0(%rbp), %rax
movslq -0xa0(%rbp), %rcx
cmpq %rcx, %rax
ja 0xe3be
movq -0xc8(%rbp), %rdi
addq $0x8, %rdi
leaq -0x48(%rbp), %rsi
callq 0x116a0
movq %rax, -0xf8(%rbp)
jmp 0xe2f3
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x10720
movq %rax, %rdi
movq -0xb0(%rbp), %rsi
callq 0x8640
movq -0xf8(%rbp), %rdi
movsbl (%rax), %eax
addl $-0x30, %eax
movl %eax, -0xb4(%rbp)
leaq -0xb4(%rbp), %rsi
callq 0x11780
jmp 0xe330
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x10720
movq %rax, %rdi
movq -0xb0(%rbp), %rsi
callq 0x8640
movsbl (%rax), %eax
cmpl $0x31, %eax
jne 0xe3a5
movq -0xc8(%rbp), %rdi
movl (%rdi), %eax
incl %eax
movl %eax, (%rdi)
addq $0x2c8, %rdi            # imm = 0x2C8
movq -0x20(%rbp), %rsi
callq 0x115a0
movq -0xc8(%rbp), %rdi
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
addq $0x98, %rdi
leaq -0x48(%rbp), %rsi
callq 0x115c0
movq %rax, -0x100(%rbp)
jmp 0xe397
movq -0x100(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0xe3a7
movq -0xb0(%rbp), %rax
addq $0x2, %rax
movq %rax, -0xb0(%rbp)
jmp 0xe2bf
movq -0xc8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movq -0x20(%rbp), %rsi
callq 0x115a0
movq -0xc8(%rbp), %rdi
cvtsi2sdl (%rax), %xmm0
cvtsi2sdl -0xa4(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xc0(%rbp)
addq $0x38, %rdi
leaq -0x48(%rbp), %rsi
callq 0x10850
movq %rax, -0x108(%rbp)
jmp 0xe40a
movq -0x108(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x10f70
jmp 0xe41f
movl $0x0, -0x9c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x8c08
movl -0x9c(%rbp), %eax
testl %eax, %eax
jne 0xe44a
jmp 0xe43e
jmp 0xe440
movl $0x0, -0x9c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x8c08
movl -0x9c(%rbp), %eax
testl %eax, %eax
je 0xe461
jmp 0xe45f
jmp 0xe463
jmp 0xe463
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xe0ea
leaq -0x48(%rbp), %rdi
callq 0x8c08
jmp 0xe488
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x8a50
nopw %cs:(%rax,%rax)