// File: millanek[P]Dsuite/Dsuite_common.cpp
// Function: assignTreeLevelsAndLinkToTaxa(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<int, std::allocator<int>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, std::vector<int, std::allocator<int>>>>>&, std::vector<int, std::allocator<int>>&)
void assignTreeLevelsAndLinkToTaxa(string& treeLine, std::map<string,std::vector<int>>& taxaToLoc, std::vector<int>& levels) {
    // First take care of any branch lengths
    std::regex branchLengths(":.*?(?=,|\\))");
    treeLine = std::regex_replace(treeLine,branchLengths,"");
    //std::cerr << line << std::endl;

    // Now process the tree
    levels.assign(treeLine.length(),0); int currentLevel = 0;
    std::vector<string> treeTaxonNames;
    string currentTaxonName = "";
    int lastBegin = 0;
    for (int i = 0; i < treeLine.length(); ++i) {
        if (treeLine[i] == '(') {
            currentLevel++; levels[i] = currentLevel;
        } else if (treeLine[i] == ')') {
            currentLevel--; levels[i] = currentLevel;
            if (currentTaxonName != "") {
                if (taxaToLoc.count(currentTaxonName) == 1) { duplicateTreeValueError(currentTaxonName); }
                treeTaxonNames.push_back(currentTaxonName);
                taxaToLoc[currentTaxonName].push_back(lastBegin);
                taxaToLoc[currentTaxonName].push_back(i-1);
                currentTaxonName = "";
            }
        } else if (treeLine[i] == ',') {
            levels[i] = currentLevel;
            if (currentTaxonName != "") {
                treeTaxonNames.push_back(currentTaxonName);
                taxaToLoc[currentTaxonName].push_back(lastBegin);
                taxaToLoc[currentTaxonName].push_back(i-1);
                currentTaxonName = "";
            }
        } else {
            if (currentTaxonName == "")
                lastBegin = i;
            levels[i] = currentLevel;
            currentTaxonName += treeLine[i];
        }
    }
    //print_vector(treeTaxonNames, std::cout,'\n');
    //print_vector(treeLevels, std::cout,' ');
    //for (std::map<string,std::vector<int>>::iterator i = treeTaxonNamesToLoc.begin(); i != treeTaxonNamesToLoc.end(); i++) {
    //    std::cout << i->first << "\t" << i->second[0] << "\t" << i->second[1] << "\t" << treeLevels[i->second[0]] << "\t" << treeLevels[i->second[1]] << std::endl;
    //}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0xb2fb(%rip), %rsi      # 0x8b389
leaq -0x38(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
movl $0x10, %edx
callq 0x49de0
movq -0xc8(%rbp), %rdx
movq -0x8(%rbp), %rsi
leaq 0xb2b4(%rip), %rcx      # 0x8b369
leaq -0x58(%rbp), %rdi
xorl %r8d, %r8d
callq 0x49e80
jmp 0x800c3
movq -0x8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movq %rsi, -0xd8(%rbp)
callq 0x86f0
movq -0xd8(%rbp), %rdi
callq 0x8c08
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x88b0
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
movl $0x0, -0x68(%rbp)
leaq -0x68(%rbp), %rdx
callq 0x287c0
jmp 0x80113
movl $0x0, -0x6c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x11d80
leaq -0xa9(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x8a60
movq -0xe0(%rbp), %rdx
leaq 0xb222(%rip), %rsi      # 0x8b369
leaq -0xa8(%rbp), %rdi
callq 0x9a00
jmp 0x80155
leaq -0xa9(%rbp), %rdi
callq 0x8610
movl $0x0, -0xb0(%rbp)
movl $0x0, -0xb4(%rbp)
movslq -0xb4(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x88b0
movq %rax, %rcx
movq -0xe8(%rbp), %rax
cmpq %rcx, %rax
jae 0x80544
movq -0x8(%rbp), %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8bc0
movq %rax, -0xf0(%rbp)
jmp 0x801b8
movq -0xf0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x28, %eax
jne 0x80241
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0xf4(%rbp)
movq -0x18(%rbp), %rdi
movslq -0xb4(%rbp), %rsi
callq 0x115a0
movl -0xf4(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x8052e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x8057a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa9(%rbp), %rdi
callq 0x8610
jmp 0x8056e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x8c08
jmp 0x8056e
movq -0x8(%rbp), %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8bc0
movq %rax, -0x100(%rbp)
jmp 0x8025a
movq -0x100(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x29, %eax
jne 0x80391
movl -0x6c(%rbp), %eax
decl %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x108(%rbp)
movq -0x18(%rbp), %rdi
movslq -0xb4(%rbp), %rsi
callq 0x115a0
movl -0x108(%rbp), %ecx
movl %ecx, (%rax)
leaq 0xb0cc(%rip), %rsi      # 0x8b369
leaq -0xa8(%rbp), %rdi
callq 0x22410
movb %al, -0x101(%rbp)
jmp 0x802b1
movb -0x101(%rbp), %al
testb $0x1, %al
jne 0x802c0
jmp 0x8038c
movq -0x10(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x80c40
movq %rax, -0x110(%rbp)
jmp 0x802d9
movq -0x110(%rbp), %rax
cmpq $0x1, %rax
jne 0x802f6
leaq -0xa8(%rbp), %rdi
callq 0x7ff40
jmp 0x802f4
jmp 0x802f6
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x11d10
jmp 0x8030b
movq -0x10(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x116a0
movq %rax, -0x118(%rbp)
jmp 0x80324
movq -0x118(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x368d0
jmp 0x80339
movq -0x10(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x116a0
movq %rax, -0x120(%rbp)
jmp 0x80352
movq -0x120(%rbp), %rdi
movl -0xb4(%rbp), %eax
decl %eax
movl %eax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rsi
callq 0x11780
jmp 0x80375
leaq 0xafed(%rip), %rsi      # 0x8b369
leaq -0xa8(%rbp), %rdi
callq 0x87c0
jmp 0x8038a
jmp 0x8038c
jmp 0x8052c
movq -0x8(%rbp), %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8bc0
movq %rax, -0x128(%rbp)
jmp 0x803aa
movq -0x128(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x804a3
movl -0x6c(%rbp), %eax
movl %eax, -0x130(%rbp)
movq -0x18(%rbp), %rdi
movslq -0xb4(%rbp), %rsi
callq 0x115a0
movl -0x130(%rbp), %ecx
movl %ecx, (%rax)
leaq 0xaf84(%rip), %rsi      # 0x8b369
leaq -0xa8(%rbp), %rdi
callq 0x22410
movb %al, -0x129(%rbp)
jmp 0x803f9
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x80408
jmp 0x8049e
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x11d10
jmp 0x8041d
movq -0x10(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x116a0
movq %rax, -0x138(%rbp)
jmp 0x80436
movq -0x138(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x368d0
jmp 0x8044b
movq -0x10(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x116a0
movq %rax, -0x140(%rbp)
jmp 0x80464
movq -0x140(%rbp), %rdi
movl -0xb4(%rbp), %eax
decl %eax
movl %eax, -0xbc(%rbp)
leaq -0xbc(%rbp), %rsi
callq 0x11780
jmp 0x80487
leaq 0xaedb(%rip), %rsi      # 0x8b369
leaq -0xa8(%rbp), %rdi
callq 0x87c0
jmp 0x8049c
jmp 0x8049e
jmp 0x8052a
leaq 0xaebf(%rip), %rsi      # 0x8b369
leaq -0xa8(%rbp), %rdi
callq 0x9ab0
movb %al, -0x141(%rbp)
jmp 0x804be
movb -0x141(%rbp), %al
testb $0x1, %al
jne 0x804ca
jmp 0x804d6
movl -0xb4(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x154(%rbp)
movq -0x18(%rbp), %rdi
movslq -0xb4(%rbp), %rsi
callq 0x115a0
movl -0x154(%rbp), %ecx
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movslq -0xb4(%rbp), %rsi
callq 0x8bc0
movq %rax, -0x150(%rbp)
jmp 0x80510
movq -0x150(%rbp), %rax
movsbl (%rax), %esi
leaq -0xa8(%rbp), %rdi
callq 0x8380
jmp 0x80528
jmp 0x8052a
jmp 0x8052c
jmp 0x8052e
jmp 0x80530
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x80175
leaq -0xa8(%rbp), %rdi
callq 0x8c08
leaq -0x88(%rbp), %rdi
callq 0x10760
leaq -0x38(%rbp), %rdi
callq 0x4a5c0
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x88(%rbp), %rdi
callq 0x10760
leaq -0x38(%rbp), %rdi
callq 0x4a5c0
movq -0x60(%rbp), %rdi
callq 0x8a50
nopl (%rax)