// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkstorage.cc
// Function: fracSubstituteAtoms(ATOM_NETWORK*, ATOM_NETWORK*, bool, double, int, int*, double*, bool)
bool fracSubstituteAtoms(ATOM_NETWORK *origNet, ATOM_NETWORK *newNet,
                         bool substituteSeed, double frac, int randSeed,
                         int *numSubstitutions, double *fracSub, bool radial){
    int numAtoms = origNet->numAtoms;
    double max_bond_length = 1.95;
    
    if(frac > 0.5){
        cerr << "Fractional atomic network substitution failed because the fraction can not exceed 0.5" << "\n";
        return false;
    }
    if(frac < 0.0){
        cerr << "Fractional atomic network substitution failed because of invalid negative fraction " << frac << "\n";
        return false;
    }
    
    vector< vector<int> > bonds = vector< vector<int> >(numAtoms, vector<int>());
    for(int i = 0; i < numAtoms; i++){
        ATOM atom_one = origNet->atoms[i];
        for(int j = i + 1; j < numAtoms; j++){
            ATOM atom_two = origNet->atoms[j];
            if(origNet->calcDistance(atom_one, atom_two) < max_bond_length){
                if(atom_one.type.compare(atom_two.type) == 0){
                    cerr << "Fractional atomic network substitution aborted because atoms of same type are bonded to one another" << "\n"
                    << "Occurred for type " << atom_one.type << " between atoms " << i << " and " << j << "\n";
                    return false;
                }
                bonds[i].push_back(j);
                bonds[j].push_back(i);
            }
        }
    }
    
    int numSi = 0;
    
    for(int i = 0; i < numAtoms; i++){
        if(origNet->atoms[i].type.compare("Si") == 0){
            if(bonds[i].size() != 4){
                cerr << "Fractional atomic network substitution aborted because Si atom "
                "bonded to " << bonds[i].size() << " other atoms instead of 4" << "\n"
                << "Occurred for atom " << i << "\n";
                return false;
            }
            numSi++;
        }
        else if(origNet->atoms[i].type.compare("O") == 0){
            if(bonds[i].size() != 2){
                cerr << "Fractional atomic network substitution aborted because O atom "
                "bonded to " << bonds[i].size() << " other atoms instead of 2" << "\n"
                << "Occurred for atom " << i << "\n";
                return false;
            }
        }
        else{
            cerr << "Fractional atomic network substitution aborted because atom type "
            "other than Si or O detected" << "\n"
            << "Occurred for atom " << i << "\n";
            return false;
        }
    }
    
    int firstSiID = -1;
    for(int i = 0; i < numAtoms; i++){
        if(origNet->atoms[i].type.compare("Si") == 0){
            firstSiID = i;
            break;
        }
    }
    
    if(firstSiID == -1){
        cerr << "Error: Fractional atomic network substitution failed because "
        "structure does not contain any Si atoms \n";
        return false;
    }
    
    vector<bool> atomProc = vector<bool>(numAtoms, false); // Whether atom has been processed
    vector<bool> atomSubs = vector<bool>(numAtoms, false); // Whether atom has been substituted
    int numProc = 0; // Number of processed atoms
    
    vector< pair<int, bool> > atomsToProcess; // Stack of atom/substituion info
    vector<int> fromIDs; // Stack of where each atom/subst came from
    
    pair<int, bool> seed(firstSiID, substituteSeed);
    atomsToProcess.push_back(seed);  // Seed with the first Si atom and not substituting it
    fromIDs.push_back(-1); // Starting node
    
    while(atomsToProcess.size() != 0){
        pair<int, bool> atomInfo = atomsToProcess.back(); atomsToProcess.pop_back();
        int id = atomInfo.first; bool subst = atomInfo.second;
        int fromID = fromIDs.back(); fromIDs.pop_back();
        
        // Atom previously processed.
        // Ensure that atom substitution agrees with previous results for Si atoms
        if(atomProc[id] ){
            if((origNet->atoms[id].type.compare("Si") == 0) && (atomSubs[id] != subst)){
                cerr << "Fractional atomic network substitution aborted because every other "
                "Si atom substitution criteria failed" << "\n";
                return false;
            }
        }
        // First time atom is processed
        else {
            numProc++;
            // Mark atom as processed
            atomProc[id] = true;
            
            // If oxygen, should not be substituted but reverse substituion state for next set of Si atoms
            if(origNet->atoms[id].type.compare("O") == 0){
                atomSubs[id] = false;
                subst = !subst;
            }
            // If silicon, pass on substitution state to oxygen atoms, who will then reverse it
            // Record substitution status
            else if(origNet->atoms[id].type.compare("Si") == 0){
                atomSubs[id] = subst;
            }
            // Invalid type
            else {
                cerr << "Fractional atomic network substitution aborted because atom type "
                "other than Si or O detected" << "\n"
                << "Occurred for atom " << id << "\n";
                return false;
            }
            
            // Added bonded atoms to stack with appropriate subsitution state
            for(unsigned int j = 0; j < bonds[id].size(); j++){
                if(bonds[id][j] != fromID){
                    atomsToProcess.push_back(pair<int, bool>(bonds[id][j], subst));
                    fromIDs.push_back(id);
                }
            }
        }
    }
    
    if(numProc != numAtoms){
        cerr << "Fractional atom network substituion failed because not all atoms "
        "are interconnected" << "\n" << "Visited " << numProc << " out of "
        << numAtoms << " atoms " << "\n";
        return false;
    }
    
    // Perform final consistency check
    for(int i = 0; i < numAtoms; i++){
        // Just check pair of atoms bonded to each oxygen
        if(origNet->atoms[i].type.compare("O") == 0){
            if(atomSubs[bonds[i][0]] && atomSubs[bonds[i][1]]){
                cerr << "Fractional atom network substitution failed final consistency check."
                << "\n" << "Oxygen atom #" << i << " is bound to atoms " <<  bonds[i][0]
                << " and " << bonds[i][1] << " which are of same type. " << "\n"
                << "Algorithmic issue likely." << "\n"
                << "Please contact the source code provider" << "\n";
                return false;
            }
        }
    }
    
    // Copy original information
    origNet->copy(newNet);
    
    int totalSubs = nearestInt(frac*numSi); // How many substituions to actually perform
    *fracSub = (1.0*totalSubs)/numSi;        // Store the actual substitution fraction
    
    srand(randSeed); // Seed random number generator
    
    // Record all originally substituted atoms
    vector<pair<int, int> > subIDs;
    for(int i = 0; i < numAtoms; i++){
        if(atomSubs[i]){
            subIDs.push_back(pair<int,int> (rand(), i));
        }
    }
    
    sort(subIDs.begin(), subIDs.end(), comparePairs); // Sort the pairs by their random values
    
    // Change atoms that should be substituted
    for(*numSubstitutions = 0; *numSubstitutions < totalSubs; (*numSubstitutions)++){
        int id = subIDs[*numSubstitutions].second;
        newNet->atoms[id].type   = "Al";
        newNet->atoms[id].radius = lookupRadius("Al", radial);
    }
    
    
    // Change Oxygen type if O atom connected to Al
    for(int i=0; i < numAtoms; i++){
        if(origNet->atoms[i].type.compare("O") == 0)
        {
            if(newNet->atoms[(bonds[i].at(0))].type.compare("Al") == 0 || newNet->atoms[(
                                                                                         bonds[i].at(1))].type.compare("Al") == 0)
            {
                newNet->atoms[i].type   = "O_Al";
            };
        };
    };
    
    
    
    // Successful substitution
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
ucomisd 0xf5e93(%rip), %xmm0    # 0x14d038
jbe 0x571d3
movq 0x13de42(%rip), %rbx    # 0x194ff0
leaq 0xfbc61(%rip), %rsi     # 0x152e16
movl $0x55, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfc455(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
jmp 0x57221
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movsd %xmm0, 0xb8(%rsp)
jbe 0x5722d
movq 0x13de03(%rip), %rbx    # 0x194ff0
leaq 0xfbc78(%rip), %rsi     # 0x152e6c
movl $0x53, %edx
movq %rbx, %rdi
callq 0x44e0
movq %rbx, %rdi
movsd 0xb8(%rsp), %xmm0
callq 0x46b0
leaq 0xfc405(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
xorl %ebx, %ebx
jmp 0x57872
movq %r9, %r13
movq %r8, %r14
movl %ecx, %r12d
movq %rsi, %rbx
movq %rdi, %r15
movl %edx, 0xa4(%rsp)
movl 0x110(%rdi), %eax
movq %rax, 0x10(%rsp)
movslq %eax, %rsi
xorpd %xmm0, %xmm0
leaq 0xc0(%rsp), %rdx
movapd %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x68(%rsp), %rdi
leaq 0x160(%rsp), %rbp
movq %rsi, 0x48(%rsp)
movq %rdx, 0x8(%rsp)
movq %rbp, %rcx
callq 0x6757e
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x572a5
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl $0x0, 0x50(%rsp)
cmpl $0x0, 0x10(%rsp)
jle 0x57707
movq %r13, 0x1f8(%rsp)
movl %r12d, 0xa0(%rsp)
movq %r14, 0xb0(%rsp)
movq %rbx, 0x40(%rsp)
movl $0x80, %eax
addq %rax, 0x8(%rsp)
leaq 0x1b0(%rsp), %r13
leaq 0x1d0(%rsp), %rbx
addq %rax, %rbp
xorl %eax, %eax
cltq
movq 0x2f0(%r15), %r12
imulq $0x98, %rax, %r14
movups (%r12,%r14), %xmm0
movupd 0x10(%r12,%r14), %xmm1
movups 0x20(%r12,%r14), %xmm2
movups 0x30(%r12,%r14), %xmm3
movaps %xmm3, 0xf0(%rsp)
movaps %xmm2, 0xe0(%rsp)
movapd %xmm1, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x40(%r12,%r14), %rsi
movq 0x48(%r12,%r14), %rdx
addq %rsi, %rdx
leaq 0x100(%rsp), %rdi
callq 0xf3ce
addq %r14, %r12
leaq 0x130(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x60(%r12), %rsi
movq 0x68(%r12), %rdx
addq %rsi, %rdx
leaq 0x120(%rsp), %rdi
callq 0xf3ce
movb 0x90(%r12), %al
movq 0x8(%rsp), %rcx
movb %al, 0x10(%rcx)
movupd 0x80(%r12), %xmm0
movupd %xmm0, (%rcx)
movl 0x50(%rsp), %eax
incl %eax
movl %eax, 0x20(%rsp)
cmpl 0x10(%rsp), %eax
jge 0x575b8
cltq
movq 0x2f0(%r15), %r12
imulq $0x98, %rax, %r14
movups (%r12,%r14), %xmm0
movups 0x10(%r12,%r14), %xmm1
movups 0x20(%r12,%r14), %xmm2
movups 0x30(%r12,%r14), %xmm3
movaps %xmm3, 0x190(%rsp)
movaps %xmm2, 0x180(%rsp)
movaps %xmm1, 0x170(%rsp)
movaps %xmm0, 0x160(%rsp)
movq %r13, 0x1a0(%rsp)
movq 0x40(%r12,%r14), %rsi
movq 0x48(%r12,%r14), %rdx
addq %rsi, %rdx
leaq 0x1a0(%rsp), %rdi
callq 0xf3ce
addq %r14, %r12
movq %rbx, 0x1c0(%rsp)
movq 0x60(%r12), %rsi
movq 0x68(%r12), %rdx
addq %rsi, %rdx
leaq 0x1c0(%rsp), %rdi
callq 0xf3ce
movb 0x90(%r12), %al
movb %al, 0x10(%rbp)
movups 0x80(%r12), %xmm0
movups %xmm0, (%rbp)
movsd 0xd8(%rsp), %xmm0
movsd 0xe0(%rsp), %xmm1
movsd 0xe8(%rsp), %xmm2
movsd 0x178(%rsp), %xmm3
movsd 0x180(%rsp), %xmm4
movsd 0x188(%rsp), %xmm5
movq %r15, %rdi
callq 0x5339c
movsd 0xfb2be(%rip), %xmm1    # 0x152770
ucomisd %xmm0, %xmm1
jbe 0x57575
movq 0x108(%rsp), %r14
movq 0x1a8(%rsp), %r12
cmpq %r14, %r12
movq %r14, %rdx
cmovbq %r12, %rdx
testq %rdx, %rdx
je 0x574fe
movq 0x1a0(%rsp), %rsi
movq 0x100(%rsp), %rdi
callq 0x4480
cmpq %r12, %r14
jne 0x57507
testl %eax, %eax
jne 0x57507
jmp 0x57724
cmpq %r12, %r14
je 0x57724
movslq 0x50(%rsp), %rcx
movq 0x68(%rsp), %rax
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x57533
movl 0x20(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x57546
leaq 0x20(%rsp), %rdx
callq 0xf864
movl 0x20(%rsp), %ecx
movq 0x68(%rsp), %rax
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5756b
movl 0x50(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x57575
leaq 0x50(%rsp), %rdx
callq 0xf864
movq 0x1c0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x57592
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x1a0(%rsp), %rdi
cmpq %r13, %rdi
je 0x575af
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x4470
movl 0x20(%rsp), %eax
jmp 0x573b6
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x575dd
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x57602
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x4470
movl 0x50(%rsp), %eax
incl %eax
movl %eax, 0x50(%rsp)
cmpl 0x10(%rsp), %eax
jl 0x572f4
cmpl $0x0, 0x10(%rsp)
jle 0x57707
xorl %r14d, %r14d
movl $0x8, %ebx
movl $0x40, %ebp
leaq 0xf61f0(%rip), %r12     # 0x14d825
xorl %r13d, %r13d
movq 0x2f0(%r15), %rdi
addq %rbp, %rdi
movq %r12, %rsi
callq 0x4170
testl %eax, %eax
je 0x57685
movq 0x2f0(%r15), %rdi
addq %rbp, %rdi
leaq 0xf61bb(%rip), %rsi     # 0x14d81a
callq 0x4170
testl %eax, %eax
jne 0x57886
movq 0x68(%rsp), %rax
movq (%rax,%rbx), %rcx
subq -0x8(%rax,%rbx), %rcx
cmpq $0x8, %rcx
je 0x576a0
jmp 0x578d2
movq 0x68(%rsp), %rax
movq (%rax,%rbx), %rcx
subq -0x8(%rax,%rbx), %rcx
cmpq $0x10, %rcx
jne 0x57949
incl %r13d
incq %r14
addq $0x18, %rbx
addq $0x98, %rbp
cmpq %r14, 0x48(%rsp)
jne 0x57638
cmpl $0x0, 0x10(%rsp)
jle 0x57707
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0xa8(%rsp)
movl $0x40, %r12d
xorl %ebx, %ebx
leaq 0xf6149(%rip), %r14     # 0x14d825
movq 0x2f0(%r15), %rdi
addq %r12, %rdi
movq %r14, %rsi
callq 0x4170
testl %eax, %eax
je 0x579e2
incq %rbx
addq $0x98, %r12
cmpq %rbx, 0x10(%rsp)
jne 0x576dc
movq 0x13d8e2(%rip), %rdi    # 0x194ff0
leaq 0xfb8ff(%rip), %rsi     # 0x153014
movl $0x66, %edx
callq 0x44e0
jmp 0x57866
movq 0x13d8c5(%rip), %rdi    # 0x194ff0
leaq 0xfb78e(%rip), %rsi     # 0x152ec0
movl $0x63, %edx
callq 0x44e0
movq 0x13d8ad(%rip), %rdi    # 0x194ff0
leaq 0xfbed4(%rip), %rsi     # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x13d895(%rip), %rdi    # 0x194ff0
leaq 0xfb3c2(%rip), %rsi     # 0x152b24
movl $0x12, %edx
callq 0x44e0
movq 0x100(%rsp), %rsi
movq 0x108(%rsp), %rdx
movq 0x13d86d(%rip), %rdi    # 0x194ff0
callq 0x44e0
movq %rax, %r14
leaq 0xfb3a5(%rip), %rsi     # 0x152b37
movl $0xf, %edx
movq %rax, %rdi
callq 0x44e0
movl 0x50(%rsp), %esi
movq %r14, %rdi
callq 0x4750
movq %rax, %r14
leaq 0xfd027(%rip), %rsi     # 0x1547dc
movl $0x5, %edx
movq %rax, %rdi
callq 0x44e0
movl 0x20(%rsp), %esi
movq %r14, %rdi
callq 0x4750
leaq 0xfbe49(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x1c0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x577ff
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x1a0(%rsp), %rdi
cmpq %r13, %rdi
je 0x5781c
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x57841
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x57866
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x4470
xorl %ebx, %ebx
leaq 0x68(%rsp), %rdi
callq 0xf066
movl %ebx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x13d763(%rip), %rdi    # 0x194ff0
leaq 0xfb723(%rip), %rsi     # 0x152fb7
movl $0x5c, %edx
callq 0x44e0
movq 0x13d74b(%rip), %rbx    # 0x194ff0
leaq 0xfbd72(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfb2e0(%rip), %rsi     # 0x152ba0
movl $0x12, %edx
movq %rbx, %rdi
callq 0x44e0
jmp 0x579be
movq 0x13d717(%rip), %rdi    # 0x194ff0
leaq 0xfb68e(%rip), %rsi     # 0x152f6e
movl $0x48, %edx
callq 0x44e0
movq 0x68(%rsp), %rax
movq (%rax,%rbx), %rsi
subq -0x8(%rax,%rbx), %rsi
sarq $0x2, %rsi
movq 0x13d6ed(%rip), %rdi    # 0x194ff0
callq 0x42b0
movq %rax, %rbx
leaq 0xfb2df(%rip), %rsi     # 0x152bf1
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfbcf8(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfb266(%rip), %rsi     # 0x152ba0
movl $0x12, %edx
movq %rbx, %rdi
callq 0x44e0
jmp 0x579be
movq 0x13d6a0(%rip), %rdi    # 0x194ff0
leaq 0xfb5cd(%rip), %rsi     # 0x152f24
movl $0x49, %edx
callq 0x44e0
movq 0x68(%rsp), %rax
movq (%rax,%rbx), %rsi
subq -0x8(%rax,%rbx), %rsi
sarq $0x2, %rsi
movq 0x13d676(%rip), %rdi    # 0x194ff0
callq 0x42b0
movq %rax, %rbx
leaq 0xfb1fd(%rip), %rsi     # 0x152b86
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfbc81(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfb1ef(%rip), %rsi     # 0x152ba0
movl $0x12, %edx
movq %rbx, %rdi
callq 0x44e0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4750
leaq 0xfbc4e(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
jmp 0x57866
leaq 0x160(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0xc0(%rsp), %rdi
leaq 0x50(%rsp), %rcx
movq 0x48(%rsp), %r14
movq %r14, %rsi
callq 0x37f36
leaq 0x50(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x160(%rsp), %rdi
leaq 0x20(%rsp), %rcx
movq %r14, %rsi
callq 0x37f36
xorl %eax, %eax
leaq 0x50(%rsp), %rdi
movq %rax, 0x10(%rdi)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rdi)
movq %rax, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
leaq 0x220(%rsp), %rdx
movl %ebx, (%rdx)
movl 0xa4(%rsp), %eax
movb %al, 0x4(%rdx)
xorl %esi, %esi
callq 0x689f8
movq 0x28(%rsp), %rsi
movl $0xffffffff, 0x80(%rsp) # imm = 0xFFFFFFFF
cmpq 0x30(%rsp), %rsi
je 0x57a85
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x57a97
leaq 0x20(%rsp), %rdi
leaq 0x80(%rsp), %rdx
callq 0x14198
movabsq $-0x8000000000000000, %rbx # imm = 0x8000000000000000
movq 0x58(%rsp), %rax
cmpq 0x50(%rsp), %rax
je 0x57d85
movq $0x0, 0x48(%rsp)
leaq 0x3f(%rbx), %rcx
movq %rcx, 0x8(%rsp)
leaq 0x50(%rsp), %r13
leaq 0x80(%rsp), %rbp
leaq -0x8(%rax), %rsi
movslq -0x8(%rax), %rcx
movb -0x4(%rax), %r12b
movq 0x28(%rsp), %rax
leaq -0x4(%rax), %rdx
leal 0x3f(%rcx), %edi
testq %rcx, %rcx
movq %rsi, 0x58(%rsp)
cmovnsl %ecx, %edi
sarl $0x6, %edi
movslq %edi, %rsi
shlq $0x3, %rsi
addq 0xc0(%rsp), %rsi
movl %ecx, 0x18(%rsp)
movq %rcx, %r8
andq 0x8(%rsp), %r8
xorl %edi, %edi
cmpq %rbx, %r8
setbe %dil
movl $0x1, %r8d
shlq %cl, %r8
movl -0x4(%rax), %r14d
movq %rdx, 0x28(%rsp)
movq -0x8(%rsi,%rdi,8), %rax
btq %rcx, %rax
jae 0x57bae
movq 0x2f0(%r15), %rax
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
leaq 0xf5cd1(%rip), %rsi     # 0x14d825
callq 0x4170
testl %eax, %eax
jne 0x57d73
movslq 0x18(%rsp), %rax
leal 0x3f(%rax), %ecx
testq %rax, %rax
cmovnsl %eax, %ecx
sarl $0x6, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq 0x160(%rsp), %rcx
movq %rax, %rdx
andq 0x8(%rsp), %rdx
xorl %esi, %esi
cmpq %rbx, %rdx
setbe %sil
movq -0x8(%rcx,%rsi,8), %rcx
btq %rax, %rcx
setae %al
xorb %r12b, %al
testb $0x1, %al
jne 0x57d73
jmp 0x58237
movl %r12d, %ebx
andb $0x1, %bl
leaq -0x8(,%rdi,8), %rdx
orq %r8, %rax
movq %rax, (%rsi,%rdx)
movq 0x2f0(%r15), %rax
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
leaq 0xf5c3a(%rip), %rsi     # 0x14d81a
callq 0x4170
movl 0x18(%rsp), %edx
movslq %edx, %rcx
testl %eax, %eax
je 0x57c74
movq 0x2f0(%r15), %rax
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
leaq 0xf5c14(%rip), %rsi     # 0x14d825
callq 0x4170
testl %eax, %eax
jne 0x58254
movslq 0x18(%rsp), %rcx
leal 0x3f(%rcx), %eax
testq %rcx, %rcx
cmovnsl %ecx, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0x160(%rsp), %rax
movq %rcx, %rdx
andq 0x8(%rsp), %rdx
xorl %esi, %esi
movabsq $-0x8000000000000000, %rdi # imm = 0x8000000000000000
cmpq %rdi, %rdx
setbe %sil
leaq -0x8(,%rsi,8), %rdx
movl $0x1, %esi
shlq %cl, %rsi
testb $0x1, %r12b
je 0x57cbc
orq %rsi, (%rax,%rdx)
jmp 0x57cc3
leal 0x3f(%rcx), %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0x160(%rsp), %rax
movq %rcx, %rsi
andq 0x8(%rsp), %rsi
xorl %edi, %edi
movabsq $-0x8000000000000000, %r8 # imm = 0x8000000000000000
cmpq %r8, %rsi
setbe %dil
movq $-0x2, %rsi
rolq %cl, %rsi
andq %rsi, -0x8(%rax,%rdi,8)
xorb $0x1, %bl
jmp 0x57cc5
notq %rsi
andq %rsi, (%rax,%rdx)
movl %ecx, %edx
movq 0x48(%rsp), %rax
incl %eax
movq %rax, 0x48(%rsp)
movq 0x68(%rsp), %rsi
leaq (%rcx,%rcx,2), %rcx
movq (%rsi,%rcx,8), %rax
cmpq %rax, 0x8(%rsi,%rcx,8)
je 0x57d69
movl $0x1, %r12d
xorl %ecx, %ecx
movl (%rax,%rcx,4), %eax
cmpl %r14d, %eax
je 0x57d42
movl %eax, 0x80(%rsp)
movb %bl, 0x84(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x68b3e
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x57d2f
movl 0x18(%rsp), %edx
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x57d42
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0xf864
movl 0x18(%rsp), %edx
movl %r12d, %ecx
movslq %edx, %rax
movq 0x68(%rsp), %rsi
leaq (%rax,%rax,2), %rdi
movq (%rsi,%rdi,8), %rax
movq 0x8(%rsi,%rdi,8), %rsi
subq %rax, %rsi
sarq $0x2, %rsi
incl %r12d
cmpq %rcx, %rsi
ja 0x57cf1
movabsq $-0x8000000000000000, %rbx # imm = 0x8000000000000000
movq 0x58(%rsp), %rax
cmpq 0x50(%rsp), %rax
jne 0x57ad0
jmp 0x57d8e
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %r14
cmpl 0x10(%rsp), %r14d
jne 0x5818c
movq %rbx, %rax
movl $0x40, %ebx
xorl %r13d, %r13d
leaq 0xf5a6a(%rip), %r12     # 0x14d81a
leaq 0x3f(%rax), %rbp
xorl %r14d, %r14d
movq 0x2f0(%r15), %rdi
addq %rbx, %rdi
movq %r12, %rsi
callq 0x4170
testl %eax, %eax
jne 0x57e5c
movq 0x68(%rsp), %rax
movq (%rax,%r13), %rcx
movslq (%rcx), %rdx
leal 0x3f(%rdx), %esi
testq %rdx, %rdx
cmovnsl %edx, %esi
movq 0x160(%rsp), %rax
sarl $0x6, %esi
movslq %esi, %rsi
leaq (%rax,%rsi,8), %rsi
movq %rdx, %rdi
andq %rbp, %rdi
xorl %r8d, %r8d
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
cmpq %r9, %rdi
setbe %r8b
movq -0x8(%rsi,%r8,8), %rsi
btq %rdx, %rsi
jae 0x57e5c
movslq 0x4(%rcx), %rcx
leal 0x3f(%rcx), %edx
testq %rcx, %rcx
cmovnsl %ecx, %edx
sarl $0x6, %edx
movslq %edx, %rdx
leaq (%rax,%rdx,8), %rax
movq %rcx, %rdx
andq %rbp, %rdx
xorl %esi, %esi
movabsq $-0x8000000000000000, %rdi # imm = 0x8000000000000000
cmpq %rdi, %rdx
setbe %sil
movq -0x8(%rax,%rsi,8), %rax
btq %rcx, %rax
jb 0x582c8
incq %r14
addq $0x18, %r13
addq $0x98, %rbx
cmpq %r14, 0x10(%rsp)
jne 0x57db7
movq %r15, %rdi
movq 0x40(%rsp), %rsi
callq 0x52620
movq 0xb0(%rsp), %r13
movsd 0xb8(%rsp), %xmm0
mulsd 0xa8(%rsp), %xmm0
addsd 0xf5194(%rip), %xmm0    # 0x14d038
callq 0x4700
cvttsd2si %xmm0, %eax
movl %eax, 0x8(%rsp)
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
divsd 0xa8(%rsp), %xmm0
movq 0x1f8(%rsp), %rax
movsd %xmm0, (%rax)
movl 0xa0(%rsp), %edi
callq 0x4410
xorpd %xmm0, %xmm0
leaq 0x80(%rsp), %r14
movapd %xmm0, (%r14)
movq $0x0, 0x10(%r14)
xorl %ebx, %ebx
leaq 0x18(%rsp), %r12
movq 0x160(%rsp), %rax
movl %ebx, %ecx
shrl $0x6, %ecx
movq (%rax,%rcx,8), %rax
btq %rbx, %rax
jae 0x57f29
callq 0x4150
movl %eax, 0x18(%rsp)
movl %ebx, 0x1c(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x146a0
incl %ebx
cmpl %ebx, 0x10(%rsp)
jne 0x57efa
movq 0x80(%rsp), %r14
movq 0x88(%rsp), %r12
cmpq %r12, %r14
je 0x57f81
movq %r12, %rax
subq %r14, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xdde(%rip), %rcx      # 0x57186
movq %r14, %rdi
movq %r12, %rsi
callq 0x68c5b
leaq -0xdf0(%rip), %rdx      # 0x57186
movq %r14, %rdi
movq %r12, %rsi
callq 0x68d26
movl $0x0, (%r13)
cmpl $0x0, 0x8(%rsp)
movq 0x40(%rsp), %rdx
jle 0x58063
xorl %eax, %eax
leaq 0x210(%rsp), %r12
leaq 0xfb1d4(%rip), %r14     # 0x15317e
leaq 0x200(%rsp), %r13
movzbl 0x260(%rsp), %ebp
cltq
movq 0x80(%rsp), %rcx
movslq 0x4(%rcx,%rax,8), %rax
movq 0x2f0(%rdx), %rcx
imulq $0x98, %rax, %rbx
leaq (%rcx,%rbx), %rdi
addq $0x40, %rdi
movq 0x8(%rdi), %rdx
movl $0x2, %r8d
xorl %esi, %esi
movq %r14, %rcx
callq 0x4670
movq %r12, 0x200(%rsp)
movq %r13, %rdi
movq %r14, %rsi
leaq 0xfb178(%rip), %rdx     # 0x153180
callq 0x22538
movq %r13, %rdi
movl %ebp, %esi
callq 0x21d5e
movq 0x40(%rsp), %rax
movq 0x2f0(%rax), %rax
movsd %xmm0, 0x30(%rax,%rbx)
movq 0x200(%rsp), %rdi
cmpq %r12, %rdi
je 0x58046
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xb0(%rsp), %rcx
movl (%rcx), %eax
incl %eax
movl %eax, (%rcx)
cmpl 0x8(%rsp), %eax
movq 0x40(%rsp), %rdx
jl 0x57fba
movl $0x8, %ebx
movl $0x40, %r14d
leaq 0xf57a5(%rip), %r12     # 0x14d81a
movq $0x0, 0x8(%rsp)
leaq 0xfb0f9(%rip), %r13     # 0x15317e
leaq 0xfb0f0(%rip), %rbp     # 0x15317c
movq 0x2f0(%r15), %rdi
addq %r14, %rdi
movq %r12, %rsi
callq 0x4170
testl %eax, %eax
jne 0x58152
movq 0x68(%rsp), %rcx
movq -0x8(%rcx,%rbx), %rax
cmpq %rax, (%rcx,%rbx)
je 0x58490
movslq (%rax), %rax
movq 0x40(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
movq %r13, %rsi
callq 0x4170
testl %eax, %eax
je 0x5812e
movq 0x68(%rsp), %rcx
movq -0x8(%rcx,%rbx), %rax
movq (%rcx,%rbx), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq $0x2, %rdx
jb 0x58494
movslq 0x4(%rax), %rax
movq 0x40(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
movq %r13, %rsi
callq 0x4170
testl %eax, %eax
jne 0x58152
movq 0x40(%rsp), %rax
movq 0x2f0(%rax), %rdi
movq 0x8(%rdi,%r14), %rdx
addq %r14, %rdi
movl $0x4, %r8d
xorl %esi, %esi
movq %rbp, %rcx
callq 0x4670
addq $0x18, %rbx
addq $0x98, %r14
decq 0x10(%rsp)
jne 0x5808c
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x58185
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movb $0x1, %bl
jmp 0x583f1
movq 0x13ce5d(%rip), %rdi    # 0x194ff0
leaq 0xfaf49(%rip), %rsi     # 0x1530e3
movl $0x53, %edx
callq 0x44e0
movq 0x13ce45(%rip), %rdi    # 0x194ff0
leaq 0xfb46c(%rip), %rsi     # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x13ce2d(%rip), %rdi    # 0x194ff0
leaq 0xfab8b(%rip), %rsi     # 0x152d55
movl $0x8, %edx
callq 0x44e0
movq 0x13ce15(%rip), %rdi    # 0x194ff0
movl %r14d, %esi
callq 0x4750
movq %rax, %r14
leaq 0xf9a17(%rip), %rsi     # 0x151c04
movl $0x8, %edx
movq %rax, %rdi
callq 0x44e0
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x4750
movq %rax, %rbx
leaq 0xfa92e(%rip), %rsi     # 0x152b3f
movl $0x7, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfb3f9(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
jmp 0x583ef
movq 0x13cdb2(%rip), %rbx    # 0x194ff0
leaq 0xfae36(%rip), %rsi     # 0x15307b
movl $0x67, %edx
movq %rbx, %rdi
callq 0x44e0
jmp 0x582af
movq 0x13cd95(%rip), %rdi    # 0x194ff0
leaq 0xfad55(%rip), %rsi     # 0x152fb7
movl $0x5c, %edx
callq 0x44e0
movq 0x13cd7d(%rip), %rdi    # 0x194ff0
leaq 0xfb3a4(%rip), %rsi     # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x13cd65(%rip), %rdi    # 0x194ff0
leaq 0xfa90e(%rip), %rsi     # 0x152ba0
movl $0x12, %edx
callq 0x44e0
movl 0x18(%rsp), %esi
movq 0x13cd49(%rip), %rdi    # 0x194ff0
callq 0x4750
movq %rax, %rbx
leaq 0xfb368(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
jmp 0x583ef
movq 0x13cd21(%rip), %rdi    # 0x194ff0
leaq 0xfae61(%rip), %rsi     # 0x153137
movl $0x44, %edx
callq 0x44e0
movq 0x13cd09(%rip), %rdi    # 0x194ff0
leaq 0xfb330(%rip), %rsi     # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x13ccf1(%rip), %rdi    # 0x194ff0
leaq 0xfaa92(%rip), %rsi     # 0x152d98
movl $0xd, %edx
callq 0x44e0
movq 0x13ccd9(%rip), %rdi    # 0x194ff0
movl %r14d, %esi
callq 0x4750
movq %rax, %rbx
leaq 0xfaa7d(%rip), %rsi     # 0x152da6
movl $0x13, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq (%rax,%r13), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4750
movq %rax, %rbx
leaq 0xfc489(%rip), %rsi     # 0x1547dc
movl $0x5, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x68(%rsp), %rax
movq (%rax,%r13), %rax
movl 0x4(%rax), %esi
movq %rbx, %rdi
callq 0x4750
movq %rax, %rbx
leaq 0xfaa3c(%rip), %rsi     # 0x152dba
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfb28c(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfaa2e(%rip), %rsi     # 0x152dd4
movl $0x19, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfb264(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfaa20(%rip), %rsi     # 0x152dee
movl $0x27, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfb23c(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
xorl %ebx, %ebx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x58408
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x5841f
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x58453
movq 0x180(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq $0x0, 0x160(%rsp)
movl $0x0, 0x168(%rsp)
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x57868
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq $0x0, 0xc0(%rsp)
movl $0x0, 0xc8(%rsp)
jmp 0x57868
xorl %edx, %edx
jmp 0x5849e
movl $0x1, %eax
movq %rax, 0x8(%rsp)
leaq 0xf5250(%rip), %rdi     # 0x14d6f5
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x5851b
jmp 0x584f2
jmp 0x5851b
movq %rax, %rbx
jmp 0x58580
jmp 0x58618
jmp 0x5851b
jmp 0x584f2
jmp 0x5851b
jmp 0x584f2
movq %rax, %rbx
movq 0x200(%rsp), %rdi
cmpq %r12, %rdi
je 0x584f5
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x584f5
jmp 0x584f2
jmp 0x584f2
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x5851e
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x5851e
jmp 0x5851b
jmp 0x58618
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x58535
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x5854c
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x58580
movq 0x180(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq $0x0, 0x160(%rsp)
movl $0x0, 0x168(%rsp)
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x58663
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0xc0(%rsp)
movl %eax, 0xc8(%rsp)
movq %rax, 0xd0(%rsp)
movl %eax, 0xd8(%rsp)
jmp 0x58663
jmp 0x58618
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x5866d
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x5866d
movq %rax, %rbx
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x58663
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x58663
movq %rax, %rbx
jmp 0x58663
jmp 0x58646
movq %rax, %rbx
jmp 0x58656
movq %rax, %rbx
movq 0x1a0(%rsp), %rdi
cmpq %r13, %rdi
je 0x58656
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x58656
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0x2f5e8
leaq 0xc0(%rsp), %rdi
callq 0x2f5e8
leaq 0x68(%rsp), %rdi
callq 0xf066
movq %rbx, %rdi
callq 0x4780