// File: /workspace/github_cpp_makefile_star2_O1/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 $0x238, %rsp            # imm = 0x238
movq %rsi, 0x58(%rsp)
ucomisd 0xf7a8e(%rip), %xmm0    # 0x14f038
jbe 0x575d8
movq 0x13fa3d(%rip), %rbx    # 0x196ff0
leaq 0xfd76c(%rip), %rsi     # 0x154d26
movl $0x55, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfdf60(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
jmp 0x57626
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movsd %xmm0, 0xc8(%rsp)
jbe 0x57632
movq 0x13f9fe(%rip), %rbx    # 0x196ff0
leaq 0xfd783(%rip), %rsi     # 0x154d7c
movl $0x53, %edx
movq %rbx, %rdi
callq 0x44e0
movq %rbx, %rdi
movsd 0xc8(%rsp), %xmm0
callq 0x46b0
leaq 0xfdf10(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
xorl %ebx, %ebx
jmp 0x587c2
movq %r8, %rbx
movq %rdi, %r14
movl %edx, 0x50(%rsp)
movq %r9, 0x230(%rsp)
movl %ecx, 0xbc(%rsp)
movslq 0x110(%rdi), %rsi
xorpd %xmm0, %xmm0
leaq 0xd0(%rsp), %rdx
movapd %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x78(%rsp), %rdi
leaq 0x170(%rsp), %r13
movq %rsi, (%rsp)
movq %rdx, 0x60(%rsp)
movq %r13, %rcx
callq 0x67eb0
movq %rbx, 0xc0(%rsp)
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x576ad
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl $0x0, 0x30(%rsp)
cmpl $0x0, (%rsp)
jle 0x579ec
movl $0x80, %eax
addq %rax, 0x60(%rsp)
leaq 0x1c0(%rsp), %r12
leaq 0x1e0(%rsp), %r15
addq %rax, %r13
xorl %eax, %eax
cltq
movq 0x2f0(%r14), %rbx
imulq $0x98, %rax, %rbp
movups (%rbx,%rbp), %xmm0
movupd 0x10(%rbx,%rbp), %xmm1
movups 0x20(%rbx,%rbp), %xmm2
movups 0x30(%rbx,%rbp), %xmm3
movaps %xmm3, 0x100(%rsp)
movaps %xmm2, 0xf0(%rsp)
movapd %xmm1, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
leaq 0x120(%rsp), %rax
movq %rax, 0x110(%rsp)
movq 0x40(%rbx,%rbp), %rsi
movq 0x48(%rbx,%rbp), %rdx
addq %rsi, %rdx
leaq 0x110(%rsp), %rdi
callq 0xf32a
addq %rbp, %rbx
leaq 0x140(%rsp), %rax
movq %rax, 0x130(%rsp)
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
addq %rsi, %rdx
leaq 0x130(%rsp), %rdi
callq 0xf32a
movb 0x90(%rbx), %al
movq 0x60(%rsp), %rcx
movb %al, 0x10(%rcx)
movupd 0x80(%rbx), %xmm0
movupd %xmm0, (%rcx)
movl 0x30(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl (%rsp), %eax
jge 0x5798f
cltq
movq 0x2f0(%r14), %rbx
imulq $0x98, %rax, %rbp
movups (%rbx,%rbp), %xmm0
movups 0x10(%rbx,%rbp), %xmm1
movups 0x20(%rbx,%rbp), %xmm2
movups 0x30(%rbx,%rbp), %xmm3
movaps %xmm3, 0x1a0(%rsp)
movaps %xmm2, 0x190(%rsp)
movaps %xmm1, 0x180(%rsp)
movaps %xmm0, 0x170(%rsp)
movq %r12, 0x1b0(%rsp)
movq 0x40(%rbx,%rbp), %rsi
movq 0x48(%rbx,%rbp), %rdx
addq %rsi, %rdx
leaq 0x1b0(%rsp), %rdi
callq 0xf32a
addq %rbp, %rbx
movq %r15, 0x1d0(%rsp)
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
addq %rsi, %rdx
leaq 0x1d0(%rsp), %rdi
callq 0xf32a
movb 0x90(%rbx), %al
movb %al, 0x10(%r13)
movups 0x80(%rbx), %xmm0
movups %xmm0, (%r13)
movsd 0xe8(%rsp), %xmm0
movsd 0xf0(%rsp), %xmm1
movsd 0xf8(%rsp), %xmm2
movsd 0x188(%rsp), %xmm3
movsd 0x190(%rsp), %xmm4
movsd 0x198(%rsp), %xmm5
movq %r14, %rdi
callq 0x5369a
movsd 0xfce3f(%rip), %xmm1    # 0x1546c8
ucomisd %xmm0, %xmm1
jbe 0x5794c
movq 0x118(%rsp), %rbx
movq 0x1b8(%rsp), %rbp
cmpq %rbx, %rbp
movq %rbx, %rdx
cmovbq %rbp, %rdx
testq %rdx, %rdx
je 0x578ce
movq 0x1b0(%rsp), %rsi
movq 0x110(%rsp), %rdi
callq 0x4480
testl %eax, %eax
sete %al
jmp 0x578d0
movb $0x1, %al
cmpq %rbp, %rbx
setne %cl
xorb $0x1, %al
orb %cl, %al
je 0x57aa6
movslq 0x30(%rsp), %rax
movq 0x78(%rsp), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x5790c
movl 0x10(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x57916
leaq 0x10(%rsp), %rdx
callq 0xf7b4
movslq 0x10(%rsp), %rax
movq 0x78(%rsp), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x57942
movl 0x30(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x5794c
leaq 0x30(%rsp), %rdx
callq 0xf7b4
movq 0x1d0(%rsp), %rdi
cmpq %r15, %rdi
je 0x57969
movq 0x1e0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x1b0(%rsp), %rdi
cmpq %r12, %rdi
je 0x57986
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x4470
movl 0x10(%rsp), %eax
jmp 0x57796
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x579b4
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x579d9
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x4470
movl 0x30(%rsp), %eax
incl %eax
movl %eax, 0x30(%rsp)
cmpl (%rsp), %eax
jl 0x576de
movq (%rsp), %r13
testl %r13d, %r13d
jle 0x57bf1
xorl %ebx, %ebx
movl $0x8, %r15d
movl $0x40, %ebp
leaq 0xf7dc8(%rip), %r12     # 0x14f7d5
xorl %r13d, %r13d
movq 0x2f0(%r14), %rdi
addq %rbp, %rdi
movq %r12, %rsi
callq 0x4170
testl %eax, %eax
je 0x57a5d
movq 0x2f0(%r14), %rdi
addq %rbp, %rdi
leaq 0xf7d93(%rip), %rsi     # 0x14f7ca
callq 0x4170
testl %eax, %eax
jne 0x57cf7
movq 0x78(%rsp), %rax
movq (%rax,%r15), %rcx
subq -0x8(%rax,%r15), %rcx
cmpq $0x8, %rcx
je 0x57a78
jmp 0x57d43
movq 0x78(%rsp), %rax
movq (%rax,%r15), %rcx
subq -0x8(%rax,%r15), %rcx
cmpq $0x10, %rcx
jne 0x58723
incl %r13d
incq %rbx
addq $0x18, %r15
addq $0x98, %rbp
cmpq %rbx, (%rsp)
jne 0x57a10
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0xa8(%rsp)
movq (%rsp), %r13
jmp 0x57bfe
movq 0x13f543(%rip), %rdi    # 0x196ff0
leaq 0xfd31c(%rip), %rsi     # 0x154dd0
movl $0x63, %edx
callq 0x44e0
movq 0x13f52b(%rip), %rdi    # 0x196ff0
leaq 0xfda62(%rip), %rsi     # 0x15552e
movl $0x1, %edx
callq 0x44e0
movq 0x13f513(%rip), %rdi    # 0x196ff0
leaq 0xfcf50(%rip), %rsi     # 0x154a34
movl $0x12, %edx
callq 0x44e0
movq 0x110(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x13f4eb(%rip), %rdi    # 0x196ff0
callq 0x44e0
movq %rax, %rbx
leaq 0xfcf33(%rip), %rsi     # 0x154a47
movl $0xf, %edx
movq %rax, %rdi
callq 0x44e0
movl 0x30(%rsp), %esi
movq %rbx, %rdi
callq 0x4750
movq %rax, %rbx
leaq 0xfeb8d(%rip), %rsi     # 0x1566c4
movl $0x5, %edx
movq %rax, %rdi
callq 0x44e0
movl 0x10(%rsp), %esi
movq %rbx, %rdi
callq 0x4750
leaq 0xfd9d7(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x1d0(%rsp), %rdi
cmpq %r15, %rdi
je 0x57b81
movq 0x1e0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x1b0(%rsp), %rdi
cmpq %r12, %rdi
je 0x57b9e
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x57bc3
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x587b6
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x587b6
xorpd %xmm0, %xmm0
movsd %xmm0, 0xa8(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %r13d, %r13d
jle 0x57c42
movl $0x40, %r12d
xorl %r15d, %r15d
leaq 0xf7bbd(%rip), %rbx     # 0x14f7d5
movq 0x2f0(%r14), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x4170
testl %eax, %eax
je 0x57c3f
incq %r15
addq $0x98, %r12
cmpq %r15, %r13
jne 0x57c18
jmp 0x57c42
movl %r15d, %ebp
cmpl $-0x1, %ebp
je 0x57cda
leaq 0x170(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0xd0(%rsp), %rdi
leaq 0x30(%rsp), %rcx
movq %r13, %rsi
callq 0x383b0
leaq 0x30(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x170(%rsp), %rdi
leaq 0x10(%rsp), %rcx
movq %r13, %rsi
callq 0x383b0
xorl %eax, %eax
movq %rax, 0x40(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq %rax, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
movl %ebp, 0xb0(%rsp)
movl 0x50(%rsp), %eax
movb %al, 0xb4(%rsp)
movq 0x38(%rsp), %rsi
testq %rsi, %rsi
je 0x57dbd
movq 0xb0(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x38(%rsp)
jmp 0x57dcf
movq 0x13f30f(%rip), %rdi    # 0x196ff0
leaq 0xfd23c(%rip), %rsi     # 0x154f24
movl $0x66, %edx
callq 0x44e0
jmp 0x587b6
movq 0x13f2f2(%rip), %rdi    # 0x196ff0
leaq 0xfd1c2(%rip), %rsi     # 0x154ec7
movl $0x5c, %edx
callq 0x44e0
movq 0x13f2da(%rip), %r14    # 0x196ff0
leaq 0xfd811(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %r14, %rdi
callq 0x44e0
leaq 0xfcd7f(%rip), %rsi     # 0x154ab0
movl $0x12, %edx
movq %r14, %rdi
callq 0x44e0
jmp 0x58798
movq 0x13f2a6(%rip), %rdi    # 0x196ff0
leaq 0xfd12d(%rip), %rsi     # 0x154e7e
movl $0x48, %edx
callq 0x44e0
movq 0x78(%rsp), %rax
movq (%rax,%r15), %rsi
subq -0x8(%rax,%r15), %rsi
sarq $0x2, %rsi
movq 0x13f27c(%rip), %rdi    # 0x196ff0
callq 0x42b0
movq %rax, %r14
leaq 0xfcd7e(%rip), %rsi     # 0x154b01
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfd797(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %r14, %rdi
callq 0x44e0
leaq 0xfcd05(%rip), %rsi     # 0x154ab0
movl $0x12, %edx
movq %r14, %rdi
callq 0x44e0
jmp 0x58798
leaq 0x30(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
callq 0x69398
movl $0xffffffff, 0x90(%rsp) # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x57df7
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x57e09
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x1422c
movabsq $-0x8000000000000000, %rbx # imm = 0x8000000000000000
movq $0x0, 0x50(%rsp)
leaq 0x3f(%rbx), %rax
movq %rax, 0x60(%rsp)
movq 0x13f1c4(%rip), %rbp    # 0x196ff0
movq 0x38(%rsp), %rax
cmpq 0x30(%rsp), %rax
je 0x581a2
leaq -0x8(%rax), %rdx
movslq -0x8(%rax), %rcx
movb -0x4(%rax), %r13b
movq %rdx, 0x38(%rsp)
movl %ecx, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movl -0x4(%rdi), %r15d
addq $-0x4, %rdi
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0xd0(%rsp), %rax
movq %rcx, %rsi
andq 0x60(%rsp), %rsi
xorl %edx, %edx
cmpq %rbx, %rsi
setbe %dl
movl $0x1, %esi
shlq %cl, %rsi
movq %rdi, 0x18(%rsp)
movq -0x8(%rax,%rdx,8), %rdi
btq %rcx, %rdi
jae 0x57f1b
movq 0x2f0(%r14), %rax
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
leaq 0xf7917(%rip), %rsi     # 0x14f7d5
callq 0x4170
movb $0x1, %r12b
testl %eax, %eax
jne 0x57f12
movslq 0x8(%rsp), %rax
leaq 0x3f(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
sarq $0x6, %rcx
shlq $0x3, %rcx
addq 0x170(%rsp), %rcx
movq %rax, %rdx
andq 0x60(%rsp), %rdx
xorl %esi, %esi
cmpq %rbx, %rdx
setbe %sil
movq -0x8(%rcx,%rsi,8), %rcx
btq %rax, %rcx
setae %al
xorb %r13b, %al
testb $0x1, %al
je 0x5804b
movq (%rsp), %r13
jmp 0x58194
movq %rbx, %rbp
movl %r13d, %ebx
andb $0x1, %bl
leaq -0x8(,%rdx,8), %rdx
movq 0x50(%rsp), %r8
incl %r8d
movq %r8, 0x50(%rsp)
orq %rsi, %rdi
movq %rdi, (%rax,%rdx)
movq 0x2f0(%r14), %rax
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
leaq 0xf786d(%rip), %rsi     # 0x14f7ca
callq 0x4170
movslq 0x8(%rsp), %rcx
testl %eax, %eax
je 0x58008
movq 0x2f0(%r14), %rax
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
leaq 0xf7849(%rip), %rsi     # 0x14f7d5
callq 0x4170
testl %eax, %eax
je 0x5807f
movl $0x5c, %edx
movq 0x13f04b(%rip), %r15    # 0x196ff0
movq %r15, %rdi
leaq 0xfcf18(%rip), %rsi     # 0x154ec7
callq 0x44e0
movq (%rsp), %r13
movq %rbp, %rbx
movq %r15, %rbp
movl $0x1, %edx
movq %r15, %rdi
leaq 0xfd561(%rip), %rsi     # 0x15552e
callq 0x44e0
movl $0x12, %edx
movq %rbp, %rdi
leaq 0xfcacf(%rip), %rsi     # 0x154ab0
callq 0x44e0
movl 0x8(%rsp), %esi
movq %rbp, %rdi
callq 0x4750
movl $0x1, %edx
movq %rax, %rdi
leaq 0xfd52d(%rip), %rsi     # 0x15552e
callq 0x44e0
jmp 0x58077
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x170(%rsp), %rax
movq %rcx, %rdx
andq 0x60(%rsp), %rdx
xorl %esi, %esi
cmpq %rbp, %rdx
setbe %sil
movq $-0x2, %rdx
rolq %cl, %rdx
andq %rdx, -0x8(%rax,%rsi,8)
xorb $0x1, %bl
jmp 0x580d3
movl $0x67, %edx
movq %rbp, %rdi
leaq 0xfcf31(%rip), %rsi     # 0x154f8b
callq 0x44e0
movq (%rsp), %r13
movl $0x1, %edx
movq %rbp, %rdi
leaq 0xfd4bc(%rip), %rsi     # 0x15552e
callq 0x44e0
xorl %r12d, %r12d
jmp 0x58194
movslq 0x8(%rsp), %rcx
leaq 0x3f(%rcx), %rax
testq %rcx, %rcx
cmovnsq %rcx, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x170(%rsp), %rax
movq %rcx, %rdx
andq 0x60(%rsp), %rdx
xorl %esi, %esi
cmpq %rbp, %rdx
setbe %sil
leaq -0x8(,%rsi,8), %rdx
movl $0x1, %esi
shlq %cl, %rsi
testb $0x1, %r13b
je 0x580cc
orq %rsi, (%rax,%rdx)
jmp 0x580d3
notq %rsi
andq %rsi, (%rax,%rdx)
movslq 0x8(%rsp), %rax
movq 0x78(%rsp), %rcx
leaq (%rax,%rax,2), %rdx
movq (%rcx,%rdx,8), %rax
movb $0x1, %r12b
cmpq %rax, 0x8(%rcx,%rdx,8)
je 0x58186
leaq (%rcx,%rdx,8), %rcx
movl $0x1, %r13d
xorl %edx, %edx
cmpl %r15d, (%rax,%rdx,4)
je 0x58157
movq (%rcx), %rax
movl (%rax,%rdx,4), %eax
movl %eax, 0x90(%rsp)
movb %bl, 0x94(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x694de
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x58148
movl 0x8(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x58157
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xf7b4
movl %r13d, %edx
movslq 0x8(%rsp), %rax
movq 0x78(%rsp), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rsi
subq %rax, %rsi
sarq $0x2, %rsi
incl %r13d
cmpq %rdx, %rsi
ja 0x580ff
movq (%rsp), %r13
movq %rbp, %rbx
movq 0x13ee5c(%rip), %rbp    # 0x196ff0
testb %r12b, %r12b
jne 0x57e2c
jmp 0x58660
cmpl %r13d, 0x50(%rsp)
jne 0x585ba
testl %r13d, %r13d
jle 0x5827f
movq %rbx, %rbp
movq (%rsp), %rax
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %r13
xorl %ebx, %ebx
movl $0x40, %r12d
xorl %r15d, %r15d
movq 0x2f0(%r14), %rdi
addq %r12, %rdi
leaq 0xf75e5(%rip), %rsi     # 0x14f7ca
callq 0x4170
testl %eax, %eax
jne 0x58269
movq 0x78(%rsp), %rax
movq (%rax,%r15), %rcx
movslq (%rcx), %rdx
movq 0x170(%rsp), %rax
leaq 0x3f(%rdx), %rsi
testq %rdx, %rdx
cmovnsq %rdx, %rsi
sarq $0x6, %rsi
leaq (%rax,%rsi,8), %rsi
movq %rdx, %rdi
andq 0x60(%rsp), %rdi
xorl %r8d, %r8d
cmpq %rbp, %rdi
setbe %r8b
movq -0x8(%rsi,%r8,8), %rsi
btq %rdx, %rsi
jae 0x58269
movslq 0x4(%rcx), %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
leaq (%rax,%rdx,8), %rax
movq %rcx, %rdx
andq 0x60(%rsp), %rdx
xorl %esi, %esi
cmpq %rbp, %rdx
setbe %sil
movq -0x8(%rax,%rsi,8), %rax
btq %rcx, %rax
jb 0x587d6
addq $0x18, %r15
incl %ebx
addq $0x98, %r12
cmpq %r15, %r13
jne 0x581d4
movq %r14, %rdi
movq 0x58(%rsp), %rsi
callq 0x528f4
movq (%rsp), %r13
movsd 0xc8(%rsp), %xmm0
mulsd 0xa8(%rsp), %xmm0
addsd 0xf6d8e(%rip), %xmm0    # 0x14f038
callq 0x4700
movapd %xmm0, 0x60(%rsp)
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
divsd 0xa8(%rsp), %xmm0
movq 0x230(%rsp), %rax
movsd %xmm0, (%rax)
movl 0xbc(%rsp), %edi
callq 0x4410
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movq $0x0, 0xa0(%rsp)
testl %r13d, %r13d
jle 0x58346
xorl %r15d, %r15d
leaq 0x90(%rsp), %rbx
leaq 0x8(%rsp), %r12
movq 0x170(%rsp), %rax
movq %r15, %rcx
shrq $0x6, %rcx
movq (%rax,%rcx,8), %rax
btq %r15, %rax
jae 0x5833e
callq 0x4150
movl %eax, 0x8(%rsp)
movl %r15d, 0xc(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1474e
incq %r15
cmpq %r15, %r13
jne 0x5830c
movq 0x90(%rsp), %rbx
movq 0x98(%rsp), %r12
cmpq %r12, %rbx
je 0x58396
movq %r12, %rax
subq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xdf3(%rip), %rcx      # 0x57586
movq %rbx, %rdi
movq %r12, %rsi
callq 0x695f3
leaq -0xe05(%rip), %rdx      # 0x57586
movq %rbx, %rdi
movq %r12, %rsi
callq 0x696be
cvttsd2si 0x60(%rsp), %r15d
movq 0xc0(%rsp), %rax
movl $0x0, (%rax)
testl %r15d, %r15d
jle 0x58486
xorl %eax, %eax
leaq 0xfccd1(%rip), %rbx     # 0x15508e
leaq 0x210(%rsp), %r13
movzbl 0x270(%rsp), %ebp
cltq
movq 0x90(%rsp), %rcx
movslq 0x4(%rcx,%rax,8), %rax
movq 0x58(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %r12
leaq (%rcx,%r12), %rdi
addq $0x40, %rdi
movq 0x8(%rdi), %rdx
movl $0x2, %r8d
xorl %esi, %esi
movq %rbx, %rcx
callq 0x4670
leaq 0x220(%rsp), %rax
movq %rax, 0x210(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
leaq 0xfcc68(%rip), %rdx     # 0x155090
callq 0x2263c
movq %r13, %rdi
movl %ebp, %esi
callq 0x21e42
movq 0x58(%rsp), %rax
movq 0x2f0(%rax), %rax
movsd %xmm0, 0x30(%rax,%r12)
movq 0x210(%rsp), %rdi
leaq 0x220(%rsp), %rax
cmpq %rax, %rdi
je 0x5846f
movq 0x220(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xc0(%rsp), %rcx
movl (%rcx), %eax
incl %eax
movl %eax, (%rcx)
cmpl %r15d, %eax
jl 0x583cd
movq (%rsp), %rax
testl %eax, %eax
jle 0x58596
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbp
movl $0x40, %ebx
movq $0x0, (%rsp)
leaq 0xf731c(%rip), %r15     # 0x14f7ca
leaq 0xfcbd9(%rip), %r12     # 0x15508e
xorl %r13d, %r13d
movq 0x2f0(%r14), %rdi
addq %rbx, %rdi
movq %r15, %rsi
callq 0x4170
testl %eax, %eax
jne 0x58582
movq 0x78(%rsp), %rcx
movq (%rcx,%r13), %rax
cmpq %rax, 0x8(%rcx,%r13)
je 0x58901
movslq (%rax), %rax
movq 0x58(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
movq %r12, %rsi
callq 0x4170
testl %eax, %eax
je 0x5855a
movq 0x78(%rsp), %rcx
movq (%rcx,%r13), %rax
movq 0x8(%rcx,%r13), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq $0x2, %rdx
jb 0x58905
movslq 0x4(%rax), %rax
movq 0x58(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
movq %r12, %rsi
callq 0x4170
testl %eax, %eax
jne 0x58582
movq 0x58(%rsp), %rax
movq 0x2f0(%rax), %rdi
movq 0x8(%rdi,%rbx), %rdx
addq %rbx, %rdi
movl $0x4, %r8d
xorl %esi, %esi
leaq 0xfcb0f(%rip), %rcx     # 0x15508c
callq 0x4670
addq $0x18, %r13
addq $0x98, %rbx
cmpq %r13, %rbp
jne 0x584b8
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x585b3
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movb $0x1, %bl
jmp 0x58662
movq 0x13ea2f(%rip), %rdi    # 0x196ff0
leaq 0xfca2b(%rip), %rsi     # 0x154ff3
movl $0x53, %edx
callq 0x44e0
movq 0x13ea17(%rip), %rdi    # 0x196ff0
leaq 0xfcf4e(%rip), %rsi     # 0x15552e
movl $0x1, %edx
callq 0x44e0
movq 0x13e9ff(%rip), %rdi    # 0x196ff0
leaq 0xfc66d(%rip), %rsi     # 0x154c65
movl $0x8, %edx
callq 0x44e0
movq 0x13e9e7(%rip), %rdi    # 0x196ff0
movq 0x50(%rsp), %rsi
callq 0x4750
movq %rax, %rbx
leaq 0xfb537(%rip), %rsi     # 0x153b54
movl $0x8, %edx
movq %rax, %rdi
callq 0x44e0
movq %rbx, %rdi
movl %r13d, %esi
callq 0x4750
movq %rax, %rbx
leaq 0xfc410(%rip), %rsi     # 0x154a4f
movl $0x7, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfcedb(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x58679
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x58690
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x170(%rsp), %rdi
testq %rdi, %rdi
je 0x586d5
movq 0x190(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0x170(%rsp)
movl %eax, 0x178(%rsp)
movq %rax, 0x180(%rsp)
movl %eax, 0x188(%rsp)
movq %rax, 0x190(%rsp)
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x587b8
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0xd0(%rsp)
movl %eax, 0xd8(%rsp)
movq %rax, 0xe0(%rsp)
movl %eax, 0xe8(%rsp)
movq %rax, 0xf0(%rsp)
jmp 0x587b8
movq 0x13e8c6(%rip), %rdi    # 0x196ff0
leaq 0xfc703(%rip), %rsi     # 0x154e34
movl $0x49, %edx
callq 0x44e0
movq 0x78(%rsp), %rax
movq (%rax,%r15), %rsi
subq -0x8(%rax,%r15), %rsi
sarq $0x2, %rsi
movq 0x13e89c(%rip), %rdi    # 0x196ff0
callq 0x42b0
movq %rax, %r14
leaq 0xfc333(%rip), %rsi     # 0x154a96
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfcdb7(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %r14, %rdi
callq 0x44e0
leaq 0xfc325(%rip), %rsi     # 0x154ab0
movl $0x12, %edx
movq %r14, %rdi
callq 0x44e0
movq %r14, %rdi
movl %ebx, %esi
callq 0x4750
leaq 0xfcd85(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
xorl %ebx, %ebx
leaq 0x78(%rsp), %rdi
callq 0xefda
movl %ebx, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x13e813(%rip), %rdi    # 0x196ff0
leaq 0xfc863(%rip), %rsi     # 0x155047
movl $0x44, %edx
callq 0x44e0
movq 0x13e7fb(%rip), %rdi    # 0x196ff0
leaq 0xfcd32(%rip), %rsi     # 0x15552e
movl $0x1, %edx
callq 0x44e0
movq 0x13e7e3(%rip), %rdi    # 0x196ff0
leaq 0xfc494(%rip), %rsi     # 0x154ca8
movl $0xd, %edx
callq 0x44e0
movq 0x13e7cb(%rip), %rdi    # 0x196ff0
movl %ebx, %esi
callq 0x4750
movq %rax, %rbx
leaq 0xfc480(%rip), %rsi     # 0x154cb6
movl $0x13, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x78(%rsp), %rax
movq (%rax,%r15), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x4750
movq %rax, %rbx
leaq 0xfde64(%rip), %rsi     # 0x1566c4
movl $0x5, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x78(%rsp), %rax
movq (%rax,%r15), %rax
movl 0x4(%rax), %esi
movq %rbx, %rdi
callq 0x4750
movq %rax, %rbx
leaq 0xfc43f(%rip), %rsi     # 0x154cca
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfcc8f(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfc431(%rip), %rsi     # 0x154ce4
movl $0x19, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfcc67(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfc423(%rip), %rsi     # 0x154cfe
movl $0x27, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfcc3f(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
jmp 0x58660
xorl %edx, %edx
jmp 0x5890e
movl $0x1, %eax
movq %rax, (%rsp)
leaq 0xf6d90(%rip), %rdi     # 0x14f6a5
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x5894b
jmp 0x58a0b
jmp 0x58a0b
jmp 0x589fe
movq %rax, %rbx
jmp 0x58a81
jmp 0x589fe
jmp 0x5894b
jmp 0x58a0b
jmp 0x5894b
jmp 0x5894b
jmp 0x5894b
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x58a0e
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x58a0e
movq %rax, %rbx
movq 0x210(%rsp), %rdi
leaq 0x220(%rsp), %rax
cmpq %rax, %rdi
je 0x5894e
movq 0x220(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x5894e
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x58b16
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x58b16
jmp 0x589fe
jmp 0x58a0b
jmp 0x58a0b
movq %rax, %rbx
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x58b0c
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x58b0c
movq %rax, %rbx
jmp 0x58b0c
jmp 0x58aef
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x58a25
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x58a3c
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x170(%rsp), %rdi
testq %rdi, %rdi
je 0x58a81
movq 0x190(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0x170(%rsp)
movl %eax, 0x178(%rsp)
movq %rax, 0x180(%rsp)
movl %eax, 0x188(%rsp)
movq %rax, 0x190(%rsp)
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x58b0c
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0xd0(%rsp)
movl %eax, 0xd8(%rsp)
movq %rax, 0xe0(%rsp)
movl %eax, 0xe8(%rsp)
movq %rax, 0xf0(%rsp)
jmp 0x58b0c
movq %rax, %rbx
jmp 0x58aff
movq %rax, %rbx
movq 0x1b0(%rsp), %rdi
cmpq %r12, %rdi
je 0x58aff
movq 0x1c0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x58aff
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x2f814
leaq 0xd0(%rsp), %rdi
callq 0x2f814
leaq 0x78(%rsp), %rdi
callq 0xefda
movq %rbx, %rdi
callq 0x4780