// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkstorage.cc
// Function: fracSubstituteAtoms_Maciek(ATOM_NETWORK&, ATOM_NETWORK&, bool, double, int, int&, double&, bool)
bool fracSubstituteAtoms_Maciek(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.50){
        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;
        }
    } // analysis of the input structure completed
    
    // save IDs of Si atoms in SiatomsIDs vector
    vector <int> SiatomsIDs;
    for(int i = 0; i < numAtoms; i++){
        if(origNet.atoms[i].type.compare("Si") == 0){
            SiatomsIDs.push_back(i);
        }
    }
    
    
    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 Si atoms (each of them can be substituted)
    vector<pair<int, int> > subIDs;
    for(int i = 0; i < numSi; i++){
        subIDs.push_back(pair<int,int> (rand(), i));
    }
    
    sort(subIDs.begin(), subIDs.end(), comparePairs); // Sort the pairs by their random values
    
    vector<bool> atomSubs = vector<bool>(numAtoms, false); // Whether atom has been substituted
    
    // Change atoms that should be substituted
    for(numSubstitutions = 0; numSubstitutions < totalSubs; numSubstitutions++){
        atomSubs[SiatomsIDs[subIDs[numSubstitutions].second]]=true;
    } // now atomsSubs points all Si atoms substituted in the intial step
    
    
    // Verify if the random distribution of Al atoms satisfy the condition not to have two neighboring Al atoms (Lowenstein's rule)
    // Fix if neccessary
    int counter=0;
    int problematicAl=-1;
    
    int max_try=10000; // number of swaps when trying to find a configuration satisfying Lowenstein's rule
    
    do{
        problematicAl=-1;
        // Step 1: identify atom with problems
        for(int i = 0; i < numAtoms; i++){
            if(origNet.atoms[i].type.compare("Si") == 0 &&atomSubs[i]==true)
            {
                // find list of 4 neighboring Si/Al atoms
                vector <int> nlist;
                for(int j=0;j<4;j++)
                {
                    if(bonds[bonds[i][j]][0]==i) {nlist.push_back(bonds[bonds[i][j]][1]);} else {nlist.push_back(bonds[bonds[i][j]][0]);};
                }
                
                if(atomSubs[nlist[0]]||atomSubs[nlist[1]]||atomSubs[nlist[2]]||atomSubs[nlist[3]]) // if any of neighbors is Al, move Al from position i
                {
                    problematicAl=i; // Al atom i needs to be this shifted;
                    break;
                }
            }
        }
        
        // Step 2: identify a suitable place for Al atom
        int suitableSi=-1;
        if(problematicAl>-1)
        {
            
            for(int i = 0; i < numAtoms; i++){
                if(origNet.atoms[i].type.compare("Si") == 0 && atomSubs[i]==false)
                {
                    // find list of 4 neighboring Si/Al atoms
                    vector <int> nlist;
                    for(int j=0;j<4;j++)
                    {
                        if(bonds[bonds[i][j]][0]==i) {
                            nlist.push_back(bonds[bonds[i][j]][1]);
                        } else {
                            nlist.push_back(bonds[bonds[i][j]][0]);
                        };
                    }
                    
                    if(!atomSubs[nlist[0]] && !atomSubs[nlist[1]] && 
                       !atomSubs[nlist[2]]&&!atomSubs[nlist[3]]) // if all of neighbors are Si, position i can be used
                    {
                        suitableSi=i; // Si atom i can be replaced with Al;
                        break;
                    }
                }
            }
        } // end of Step 2
        
        // Step 3: Swap 1 & 2
        if(problematicAl>-1&&suitableSi>-1)
        {
            atomSubs[problematicAl]=false;
            atomSubs[suitableSi]=true;
        }else{
            
            if(problematicAl>-1) 
            {
                cerr << "Cannot fix a random Al distribution by swapping Al atoms" << "\n";
                return false;
            }
        }
        // Step 4: increase counter
        counter++;
    }while(problematicAl>-1&&counter<max_try*numSi);
    
    
    if(counter==(max_try*numSi))
    {
        cerr << "Could not fix the initial Al distribution in " << max_try*numSi << "steps\n";
        return false;
    }
    
    
    
    // Now update the original structure according to the generate distribution of Al atoms
    
    // Copy original information
    origNet.copy(&newNet);
    
    
    // Change atoms that should be substituted
    for(int i = 0; i < numAtoms; i++){
        if(atomSubs[i]){
            newNet.atoms[i].type   = "Al";
            newNet.atoms[i].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 $0x208, %rsp            # imm = 0x208
ucomisd 0xf4996(%rip), %xmm0    # 0x14d038
jbe 0x586d0
movq 0x13c945(%rip), %rbx    # 0x194ff0
leaq 0xfa764(%rip), %rsi     # 0x152e16
movl $0x55, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfaf58(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
jmp 0x58718
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movsd %xmm0, 0x70(%rsp)
jbe 0x58724
movq 0x13c909(%rip), %rbx    # 0x194ff0
leaq 0xfa77e(%rip), %rsi     # 0x152e6c
movl $0x53, %edx
movq %rbx, %rdi
callq 0x44e0
movq %rbx, %rdi
movsd 0x70(%rsp), %xmm0
callq 0x46b0
leaq 0xfaf0e(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
xorl %ebx, %ebx
jmp 0x59480
movq %rsi, %r12
movq %rdi, %r14
movq %r9, 0x68(%rsp)
movl %ecx, 0x38(%rsp)
movq %r8, 0x200(%rsp)
movslq 0x110(%rdi), %r13
xorpd %xmm0, %xmm0
leaq 0xa0(%rsp), %rdx
movapd %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x88(%rsp), %rdi
leaq 0x160(%rsp), %r15
movq %r13, %rsi
movq %rdx, 0x30(%rsp)
movq %r15, %rcx
callq 0x6757e
movl %r13d, %ebx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5879a
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl $0x0, 0x40(%rsp)
testl %r13d, %r13d
movq %r12, 0x28(%rsp)
movq %rbx, 0x8(%rsp)
movq %r13, 0x60(%rsp)
jle 0x58dcd
movl $0x80, %eax
addq %rax, 0x30(%rsp)
leaq 0x1b0(%rsp), %rbx
leaq 0x1d0(%rsp), %r12
addq %rax, %r15
xorl %eax, %eax
cltq
movq 0x2f0(%r14), %r13
imulq $0x98, %rax, %rbp
movups (%r13,%rbp), %xmm0
movupd 0x10(%r13,%rbp), %xmm1
movups 0x20(%r13,%rbp), %xmm2
movups 0x30(%r13,%rbp), %xmm3
movaps %xmm3, 0xd0(%rsp)
movaps %xmm2, 0xc0(%rsp)
movapd %xmm1, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x40(%r13,%rbp), %rsi
movq 0x48(%r13,%rbp), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0xf3ce
addq %rbp, %r13
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x60(%r13), %rsi
movq 0x68(%r13), %rdx
addq %rsi, %rdx
leaq 0x100(%rsp), %rdi
callq 0xf3ce
movb 0x90(%r13), %al
movq 0x30(%rsp), %rcx
movb %al, 0x10(%rcx)
movupd 0x80(%r13), %xmm0
movupd %xmm0, (%rcx)
movl 0x40(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
movq 0x8(%rsp), %r13
cmpl %r13d, %eax
jge 0x58ab7
cltq
movq 0x2f0(%r14), %r13
imulq $0x98, %rax, %rbp
movups (%r13,%rbp), %xmm0
movups 0x10(%r13,%rbp), %xmm1
movups 0x20(%r13,%rbp), %xmm2
movups 0x30(%r13,%rbp), %xmm3
movaps %xmm3, 0x190(%rsp)
movaps %xmm2, 0x180(%rsp)
movaps %xmm1, 0x170(%rsp)
movaps %xmm0, 0x160(%rsp)
movq %rbx, 0x1a0(%rsp)
movq 0x40(%r13,%rbp), %rsi
movq 0x48(%r13,%rbp), %rdx
addq %rsi, %rdx
leaq 0x1a0(%rsp), %rdi
callq 0xf3ce
addq %rbp, %r13
movq %r12, 0x1c0(%rsp)
movq 0x60(%r13), %rsi
movq 0x68(%r13), %rdx
addq %rsi, %rdx
leaq 0x1c0(%rsp), %rdi
callq 0xf3ce
movb 0x90(%r13), %al
movb %al, 0x10(%r15)
movups 0x80(%r13), %xmm0
movups %xmm0, (%r15)
movsd 0xb8(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm1
movsd 0xc8(%rsp), %xmm2
movsd 0x178(%rsp), %xmm3
movsd 0x180(%rsp), %xmm4
movsd 0x188(%rsp), %xmm5
movq %r14, %rdi
callq 0x5339c
movq 0x8(%rsp), %r13
movsd 0xf9dd5(%rip), %xmm1    # 0x152770
ucomisd %xmm0, %xmm1
jbe 0x58a6e
movq 0xe8(%rsp), %r13
movq 0x1a8(%rsp), %rbp
cmpq %r13, %rbp
movq %r13, %rdx
cmovbq %rbp, %rdx
testq %rdx, %rdx
je 0x589e7
movq 0x1a0(%rsp), %rsi
movq 0xe0(%rsp), %rdi
callq 0x4480
cmpq %rbp, %r13
jne 0x589f0
testl %eax, %eax
jne 0x589f0
jmp 0x58c84
cmpq %rbp, %r13
je 0x58c84
movslq 0x40(%rsp), %rcx
movq 0x88(%rsp), %rax
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x58a24
movl 0x10(%rsp), %ecx
movl %ecx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
movq 0x8(%rsp), %r13
jmp 0x58a3f
leaq 0x10(%rsp), %rdx
callq 0xf864
movq 0x8(%rsp), %r13
movl 0x10(%rsp), %ecx
movq 0x88(%rsp), %rax
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x58a64
movl 0x40(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x58a6e
leaq 0x40(%rsp), %rdx
callq 0xf864
movq 0x1c0(%rsp), %rdi
cmpq %r12, %rdi
je 0x58a8b
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x1a0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x58aa8
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x4470
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
jmp 0x588a3
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x58adc
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x58b01
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4470
movl 0x40(%rsp), %eax
incl %eax
movl %eax, 0x40(%rsp)
cmpl %r13d, %eax
jl 0x587d9
testl %r13d, %r13d
movq 0x28(%rsp), %r12
movq 0x60(%rsp), %r13
jle 0x58dcd
xorl %ebx, %ebx
movl $0x8, %r12d
movl $0x40, %r13d
leaq 0xf4ce9(%rip), %r15     # 0x14d825
xorl %ebp, %ebp
movq 0x2f0(%r14), %rdi
addq %r13, %rdi
movq %r15, %rsi
callq 0x4170
testl %eax, %eax
je 0x58b8e
movq 0x2f0(%r14), %rdi
addq %r13, %rdi
leaq 0xf4cb5(%rip), %rsi     # 0x14d81a
callq 0x4170
testl %eax, %eax
jne 0x596fe
movq 0x88(%rsp), %rax
movq (%rax,%r12), %rcx
subq -0x8(%rax,%r12), %rcx
cmpq $0x8, %rcx
je 0x58bab
jmp 0x5974a
movq 0x88(%rsp), %rax
movq (%rax,%r12), %rcx
subq -0x8(%rax,%r12), %rcx
cmpq $0x10, %rcx
jne 0x597c4
incl %ebp
incq %rbx
addq $0x18, %r12
addq $0x98, %r13
cmpq %rbx, 0x8(%rsp)
jne 0x58b3e
xorpd %xmm0, %xmm0
movapd %xmm0, 0x160(%rsp)
movq $0x0, 0x170(%rsp)
movl $0x0, 0xa0(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x5985f
xorl %eax, %eax
leaq 0xf4c29(%rip), %rbx     # 0x14d825
leaq 0x160(%rsp), %r15
leaq 0xa0(%rsp), %r13
movq 0x28(%rsp), %r12
cltq
movq 0x2f0(%r14), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
movq %rbx, %rsi
callq 0x4170
testl %eax, %eax
jne 0x58c69
movq 0x168(%rsp), %rsi
cmpq 0x170(%rsp), %rsi
je 0x58c5e
movl 0xa0(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x168(%rsp)
jmp 0x58c69
movq %r15, %rdi
movq %r13, %rdx
callq 0xf864
movl 0xa0(%rsp), %eax
incl %eax
movl %eax, 0xa0(%rsp)
cmpl 0x8(%rsp), %eax
jl 0x58c11
jmp 0x59864
movq 0x13c365(%rip), %rdi    # 0x194ff0
leaq 0xfa22e(%rip), %rsi     # 0x152ec0
movl $0x63, %edx
callq 0x44e0
movq 0x13c34d(%rip), %rdi    # 0x194ff0
leaq 0xfa974(%rip), %rsi     # 0x15361e
movl $0x1, %edx
callq 0x44e0
movq 0x13c335(%rip), %rdi    # 0x194ff0
leaq 0xf9e62(%rip), %rsi     # 0x152b24
movl $0x12, %edx
callq 0x44e0
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
movq 0x13c30d(%rip), %rdi    # 0x194ff0
callq 0x44e0
movq %rax, %r14
leaq 0xf9e45(%rip), %rsi     # 0x152b37
movl $0xf, %edx
movq %rax, %rdi
callq 0x44e0
movl 0x40(%rsp), %esi
movq %r14, %rdi
callq 0x4750
movq %rax, %r14
leaq 0xfbac7(%rip), %rsi     # 0x1547dc
movl $0x5, %edx
movq %rax, %rdi
callq 0x44e0
movl 0x10(%rsp), %esi
movq %r14, %rdi
callq 0x4750
leaq 0xfa8e9(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x1c0(%rsp), %rdi
cmpq %r12, %rdi
je 0x58d5f
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x1a0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x58d7c
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x58da1
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x58dc6
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4470
xorl %ebx, %ebx
jmp 0x59473
xorpd %xmm0, %xmm0
movapd %xmm0, 0x160(%rsp)
movq $0x0, 0x170(%rsp)
xorl %ebp, %ebp
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd 0x70(%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0xf4231(%rip), %xmm0    # 0x14d038
callq 0x4700
movapd %xmm0, 0x70(%rsp)
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
divsd 0x30(%rsp), %xmm0
movq 0x68(%rsp), %rax
movsd %xmm0, (%rax)
movl 0x38(%rsp), %edi
callq 0x4410
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testl %ebp, %ebp
jle 0x58ed3
xorl %r12d, %r12d
leaq 0x40(%rsp), %rbx
leaq 0xa0(%rsp), %r15
callq 0x4150
movl %eax, 0xa0(%rsp)
movl %r12d, 0xa4(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x146a0
incl %r12d
cmpl %r12d, %ebp
jne 0x58e5d
movq 0x40(%rsp), %rbx
movq 0x48(%rsp), %r15
cmpq %r15, %rbx
movq 0x28(%rsp), %r12
je 0x58ed3
movq %r15, %rax
subq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x1d30(%rip), %rcx     # 0x57186
movq %rbx, %rdi
movq %r15, %rsi
callq 0x68c5b
leaq -0x1d42(%rip), %rdx     # 0x57186
movq %rbx, %rdi
movq %r15, %rsi
callq 0x68d26
leaq 0x10(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0xa0(%rsp), %rdi
leaq 0x3f(%rsp), %rcx
movq %r13, %rsi
callq 0x37f36
cvttsd2si 0x70(%rsp), %ecx
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
movq 0x200(%rsp), %r15
movl $0x0, (%r15)
testl %ecx, %ecx
jle 0x58f77
movq 0x40(%rsp), %rax
movq 0x160(%rsp), %rdx
movq 0xa0(%rsp), %rsi
movl %ecx, %edi
xorl %r8d, %r8d
leaq 0x3f(%r13), %r9
movslq 0x4(%rax,%r8,8), %rcx
movslq (%rdx,%rcx,4), %rcx
leal 0x3f(%rcx), %r10d
testq %rcx, %rcx
cmovnsl %ecx, %r10d
sarl $0x6, %r10d
movslq %r10d, %r10
movq %rcx, %r11
andq %r9, %r11
xorl %ebx, %ebx
cmpq %r13, %r11
setbe %bl
movl $0x1, %r11d
shlq %cl, %r11
leaq (%rsi,%r10,8), %rcx
orq %r11, -0x8(%rcx,%rbx,8)
incq %r8
movl %r8d, (%r15)
cmpq %r8, %rdi
jne 0x58f31
imull $0x2710, %ebp, %eax     # imm = 0x2710
cmpl $0x2, %eax
movl $0x1, %ecx
movl %eax, 0x38(%rsp)
cmovgel %eax, %ecx
movl %ecx, 0x68(%rsp)
movq $0x0, 0x70(%rsp)
leaq 0xf4885(%rip), %r15     # 0x14d825
movq %r13, %rax
leaq 0x10(%rsp), %r13
addq $0x3f, %rax
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x59494
xorl %ebp, %ebp
movq 0x2f0(%r14), %rax
imulq $0x98, %rbp, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
movq %r15, %rsi
callq 0x4170
testl %eax, %eax
jne 0x5917d
movq 0xa0(%rsp), %rax
movl %ebp, %ecx
shrl $0x6, %ecx
movq (%rax,%rcx,8), %rax
btq %rbp, %rax
jae 0x5917d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq (,%rbp,2), %rbx
addq %rbp, %rbx
xorl %r15d, %r15d
movq 0x88(%rsp), %rax
movq (%rax,%rbx,8), %rcx
movslq (%rcx,%r15,4), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdx
movl (%rdx), %eax
cmpq %rax, %rbp
jne 0x59055
addq $0x4, %rdx
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x5906e
movl (%rdx), %eax
movl %eax, (%rsi)
jmp 0x59063
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x5906e
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x59076
movq %r13, %rdi
callq 0xf864
incq %r15
cmpq $0x4, %r15
jne 0x59020
movq 0x10(%rsp), %rdi
movslq (%rdi), %rcx
leal 0x3f(%rcx), %edx
testq %rcx, %rcx
cmovnsl %ecx, %edx
movq 0xa0(%rsp), %rax
sarl $0x6, %edx
movslq %edx, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
movq 0x30(%rsp), %r10
andq %r10, %rsi
xorl %r8d, %r8d
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
cmpq %r9, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jb 0x59192
movslq 0x4(%rdi), %rcx
leal 0x3f(%rcx), %edx
testq %rcx, %rcx
cmovnsl %ecx, %edx
sarl $0x6, %edx
movslq %edx, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
andq %r10, %rsi
xorl %r8d, %r8d
cmpq %r9, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jb 0x59192
movslq 0x8(%rdi), %rcx
leal 0x3f(%rcx), %edx
testq %rcx, %rcx
cmovnsl %ecx, %edx
sarl $0x6, %edx
movslq %edx, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
andq %r10, %rsi
xorl %r8d, %r8d
cmpq %r9, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jb 0x59192
movslq 0xc(%rdi), %rbx
leal 0x3f(%rbx), %ecx
testq %rbx, %rbx
cmovnsl %ebx, %ecx
sarl $0x6, %ecx
movq %rbx, %rdx
andq %r10, %rdx
xorl %esi, %esi
cmpq %r9, %rdx
movslq %ecx, %rcx
setbe %sil
leaq (%rax,%rcx,8), %rax
movq -0x8(%rax,%rsi,8), %r15
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
btq %rbx, %r15
leaq 0xf46aa(%rip), %r15     # 0x14d825
jb 0x591a6
incq %rbp
cmpq 0x8(%rsp), %rbp
jne 0x58fbe
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x591a6
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0xf467f(%rip), %r15     # 0x14d825
testl %ebp, %ebp
js 0x59494
cmpl $0x0, 0x8(%rsp)
jle 0x593e4
xorl %ebx, %ebx
movq 0x2f0(%r14), %rax
imulq $0x98, %rbx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
movq %r15, %rsi
callq 0x4170
testl %eax, %eax
jne 0x59371
movq 0xa0(%rsp), %rax
movl %ebx, %r12d
shrl $0x6, %r12d
movq (%rax,%r12,8), %rax
btq %rbx, %rax
jb 0x59371
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
xorl %r15d, %r15d
movq 0x88(%rsp), %rax
leaq (%rbx,%rbx,2), %rcx
movq (%rax,%rcx,8), %rcx
movslq (%rcx,%r15,4), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdx
movl (%rdx), %eax
cmpq %rax, %rbx
jne 0x5924d
addq $0x4, %rdx
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x59266
movl (%rdx), %eax
movl %eax, (%rsi)
jmp 0x5925b
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x59266
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x5926e
movq %r13, %rdi
callq 0xf864
incq %r15
cmpq $0x4, %r15
jne 0x59214
movq 0x10(%rsp), %rdi
movslq (%rdi), %rcx
leal 0x3f(%rcx), %edx
testq %rcx, %rcx
cmovnsl %ecx, %edx
movq 0xa0(%rsp), %rax
sarl $0x6, %edx
movslq %edx, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
movq 0x30(%rsp), %r10
andq %r10, %rsi
xorl %r8d, %r8d
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
cmpq %r9, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jb 0x5935d
movslq 0x4(%rdi), %rcx
leal 0x3f(%rcx), %edx
testq %rcx, %rcx
cmovnsl %ecx, %edx
sarl $0x6, %edx
movslq %edx, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
andq %r10, %rsi
xorl %r8d, %r8d
cmpq %r9, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jb 0x5935d
movslq 0x8(%rdi), %rcx
leal 0x3f(%rcx), %edx
testq %rcx, %rcx
cmovnsl %ecx, %edx
sarl $0x6, %edx
movslq %edx, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
andq %r10, %rsi
xorl %r8d, %r8d
cmpq %r9, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jb 0x5935d
movslq 0xc(%rdi), %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 %r10, %rdx
xorl %esi, %esi
cmpq %r9, %rdx
setbe %sil
movq -0x8(%rax,%rsi,8), %rax
btq %rcx, %rax
jae 0x59381
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0xf44b4(%rip), %r15     # 0x14d825
incq %rbx
cmpq 0x8(%rsp), %rbx
jne 0x591bb
jmp 0x593e4
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xa0(%rsp), %rax
movl %ebp, %edx
shrl $0x6, %edx
movq $-0x2, %rsi
movl %ebp, %ecx
rolq %cl, %rsi
andq %rsi, (%rax,%rdx,8)
movl $0x1, %edx
movl %ebx, %ecx
shlq %cl, %rdx
orq %rdx, (%rax,%r12,8)
movq 0x70(%rsp), %rax
incl %eax
movq %rax, 0x70(%rsp)
cmpl 0x68(%rsp), %eax
movq 0x28(%rsp), %r12
leaq 0xf4450(%rip), %r15     # 0x14d825
jne 0x58fb1
movl 0x68(%rsp), %eax
jmp 0x5949b
movq 0x13bc05(%rip), %rdi    # 0x194ff0
leaq 0xf9d8f(%rip), %rsi     # 0x153181
movl $0x38, %edx
callq 0x44e0
movq 0x13bbed(%rip), %rdi    # 0x194ff0
leaq 0xfa214(%rip), %rsi     # 0x15361e
movl $0x1, %edx
callq 0x44e0
xorl %ebx, %ebx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5943f
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq $0x0, 0xa0(%rsp)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x59456
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x59473
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x88(%rsp), %rdi
callq 0xf066
movl %ebx, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x70(%rsp), %rax
incl %eax
movl 0x38(%rsp), %ebx
cmpl %ebx, %eax
movq 0x8(%rsp), %r15
jne 0x594e7
movq 0x13bb41(%rip), %rdi    # 0x194ff0
leaq 0xf9d04(%rip), %rsi     # 0x1531ba
movl $0x2d, %edx
callq 0x44e0
movq 0x13bb29(%rip), %rdi    # 0x194ff0
movl %ebx, %esi
callq 0x4750
leaq 0xf9d13(%rip), %rsi     # 0x1531e8
movl $0x6, %edx
movq %rax, %rdi
callq 0x44e0
jmp 0x59414
movq %r14, %rdi
movq %r12, %rsi
callq 0x52620
movb $0x1, %bl
testl %r15d, %r15d
jle 0x59416
movl $0x48, %r12d
xorl %r15d, %r15d
leaq 0x140(%rsp), %rbp
movzbl 0x240(%rsp), %eax
movl %eax, 0x30(%rsp)
movq 0xa0(%rsp), %rax
movl %r15d, %ecx
shrl $0x6, %ecx
movq (%rax,%rcx,8), %rax
btq %r15, %rax
jae 0x595cb
movq 0x28(%rsp), %rax
movq 0x2f0(%rax), %rax
leaq (%rax,%r12), %rdi
addq $-0x8, %rdi
movq 0x8(%rdi), %rdx
movl $0x2, %r8d
xorl %esi, %esi
leaq 0xf9c21(%rip), %r13     # 0x15317e
movq %r13, %rcx
callq 0x4670
leaq 0x150(%rsp), %rax
movq %rax, 0x140(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
leaq 0xf9bfe(%rip), %rdx     # 0x153180
callq 0x22538
movq %rbp, %rdi
movl 0x30(%rsp), %esi
callq 0x21d5e
movq 0x28(%rsp), %rax
movq 0x2f0(%rax), %rax
movsd %xmm0, -0x18(%rax,%r12)
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x595cb
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x4470
incq %r15
addq $0x98, %r12
cmpq %r15, 0x60(%rsp)
jne 0x5951a
movq 0x8(%rsp), %rax
testl %eax, %eax
jle 0x59416
shlq $0x3, %rax
leaq (%rax,%rax,2), %r15
movl $0x40, %ebp
movq $0x0, 0x8(%rsp)
leaq 0xf4210(%rip), %r12     # 0x14d81a
xorl %r13d, %r13d
movq 0x2f0(%r14), %rdi
addq %rbp, %rdi
movq %r12, %rsi
callq 0x4170
testl %eax, %eax
jne 0x596e5
movq 0x88(%rsp), %rcx
movq (%rcx,%r13), %rax
cmpq %rax, 0x8(%rcx,%r13)
je 0x5986e
movslq (%rax), %rax
movq 0x28(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
leaq 0xf9b1b(%rip), %rsi     # 0x15317e
callq 0x4170
testl %eax, %eax
je 0x596bd
movq 0x88(%rsp), %rcx
movq (%rcx,%r13), %rax
movq 0x8(%rcx,%r13), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq $0x2, %rdx
jb 0x59872
movslq 0x4(%rax), %rax
movq 0x28(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
leaq 0xf9aca(%rip), %rsi     # 0x15317e
callq 0x4170
testl %eax, %eax
jne 0x596e5
movq 0x28(%rsp), %rax
movq 0x2f0(%rax), %rdi
movq 0x8(%rdi,%rbp), %rdx
addq %rbp, %rdi
movl $0x4, %r8d
xorl %esi, %esi
leaq 0xf9a9c(%rip), %rcx     # 0x15317c
callq 0x4670
addq $0x18, %r13
addq $0x98, %rbp
cmpq %r13, %r15
jne 0x5960d
jmp 0x59416
movq 0x13b8eb(%rip), %rdi    # 0x194ff0
leaq 0xf98ab(%rip), %rsi     # 0x152fb7
movl $0x5c, %edx
callq 0x44e0
movq 0x13b8d3(%rip), %r14    # 0x194ff0
leaq 0xf9efa(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %r14, %rdi
callq 0x44e0
leaq 0xf9468(%rip), %rsi     # 0x152ba0
movl $0x12, %edx
movq %r14, %rdi
callq 0x44e0
jmp 0x5983c
movq 0x13b89f(%rip), %rdi    # 0x194ff0
leaq 0xf9816(%rip), %rsi     # 0x152f6e
movl $0x48, %edx
callq 0x44e0
movq 0x88(%rsp), %rax
movq (%rax,%r12), %rsi
subq -0x8(%rax,%r12), %rsi
sarq $0x2, %rsi
movq 0x13b872(%rip), %rdi    # 0x194ff0
callq 0x42b0
movq %rax, %r14
leaq 0xf9464(%rip), %rsi     # 0x152bf1
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xf9e7d(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %r14, %rdi
callq 0x44e0
leaq 0xf93eb(%rip), %rsi     # 0x152ba0
movl $0x12, %edx
movq %r14, %rdi
callq 0x44e0
jmp 0x5983c
movq 0x13b825(%rip), %rdi    # 0x194ff0
leaq 0xf9752(%rip), %rsi     # 0x152f24
movl $0x49, %edx
callq 0x44e0
movq 0x88(%rsp), %rax
movq (%rax,%r12), %rsi
subq -0x8(%rax,%r12), %rsi
sarq $0x2, %rsi
movq 0x13b7f8(%rip), %rdi    # 0x194ff0
callq 0x42b0
movq %rax, %r14
leaq 0xf937f(%rip), %rsi     # 0x152b86
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xf9e03(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %r14, %rdi
callq 0x44e0
leaq 0xf9371(%rip), %rsi     # 0x152ba0
movl $0x12, %edx
movq %r14, %rdi
callq 0x44e0
movq %r14, %rdi
movl %ebx, %esi
callq 0x4750
leaq 0xf9dd1(%rip), %rsi     # 0x15361e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
jmp 0x58dc6
movq 0x28(%rsp), %r12
movq 0x60(%rsp), %r13
jmp 0x58de8
xorl %edx, %edx
jmp 0x5987c
movl $0x1, %eax
movq %rax, 0x8(%rsp)
leaq 0xf3e72(%rip), %rdi     # 0x14d6f5
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x598d3
jmp 0x598d3
movq %rax, %r14
jmp 0x599b2
jmp 0x598d3
movq %rax, %r14
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x5995e
movq 0x150(%rsp), %rsi
incq %rsi
jmp 0x59959
jmp 0x598d3
jmp 0x598d3
jmp 0x59930
jmp 0x5993d
jmp 0x5993d
movq %rax, %r14
jmp 0x5995e
movq %rax, %r14
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x59a22
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x59a22
movq %rax, %r14
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x59a15
movq 0xf0(%rsp), %rsi
incq %rsi
jmp 0x599ca
movq %rax, %r14
jmp 0x59a15
jmp 0x599f8
movq %rax, %r14
jmp 0x5999b
jmp 0x59944
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5995e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x5999b
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0xa0(%rsp)
movl %eax, 0xa8(%rsp)
movq %rax, 0xb0(%rsp)
movl %eax, 0xb8(%rsp)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x599b2
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x59a15
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x59a15
movq %rax, %r14
jmp 0x59a08
movq %rax, %r14
movq 0x1a0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x59a08
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x59a08
movq %rax, %r14
leaq 0x160(%rsp), %rdi
callq 0x2f5e8
leaq 0xa0(%rsp), %rdi
callq 0x2f5e8
leaq 0x88(%rsp), %rdi
callq 0xf066
movq %r14, %rdi
callq 0x4780