// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1f8, %rsp            # imm = 0x1F8
ucomisd 0xf64ed(%rip), %xmm0    # 0x14f038
jbe 0x58b79
movq 0x13e49c(%rip), %rbx    # 0x196ff0
leaq 0xfc1cb(%rip), %rsi     # 0x154d26
movl $0x55, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0xfc9bf(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
jmp 0x58bc7
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movsd %xmm0, 0x80(%rsp)
jbe 0x58bd3
movq 0x13e45d(%rip), %rbx    # 0x196ff0
leaq 0xfc1e2(%rip), %rsi     # 0x154d7c
movl $0x53, %edx
movq %rbx, %rdi
callq 0x44e0
movq %rbx, %rdi
movsd 0x80(%rsp), %xmm0
callq 0x46b0
leaq 0xfc96f(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
xorl %ebx, %ebx
jmp 0x59ce5
movq %r8, %r13
movq %rsi, %r12
movq %rdi, %r14
movq %r9, 0x58(%rsp)
movl %ecx, 0x60(%rsp)
movslq 0x110(%rdi), %r15
xorpd %xmm0, %xmm0
leaq 0xa0(%rsp), %rdx
movapd %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
leaq 0x68(%rsp), %rdi
leaq 0x160(%rsp), %rbx
movq %r15, %rsi
movq %rdx, 0x8(%rsp)
movq %rbx, %rcx
callq 0x67eb0
movq %r13, 0x98(%rsp)
movq %r12, 0x38(%rsp)
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x58c4b
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl $0x0, 0x40(%rsp)
testl %r15d, %r15d
jle 0x58fa2
movl $0x80, %eax
addq %rax, 0x8(%rsp)
leaq 0x1d0(%rsp), %r13
addq %rax, %rbx
xorl %eax, %eax
cltq
movq 0x2f0(%r14), %r12
imulq $0x98, %rax, %rbp
movups (%r12,%rbp), %xmm0
movupd 0x10(%r12,%rbp), %xmm1
movups 0x20(%r12,%rbp), %xmm2
movups 0x30(%r12,%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(%r12,%rbp), %rsi
movq 0x48(%r12,%rbp), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0xf32a
addq %rbp, %r12
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x60(%r12), %rsi
movq 0x68(%r12), %rdx
addq %rsi, %rdx
leaq 0x100(%rsp), %rdi
callq 0xf32a
movb 0x90(%r12), %al
movq 0x8(%rsp), %rcx
movb %al, 0x10(%rcx)
movupd 0x80(%r12), %xmm0
movupd %xmm0, (%rcx)
movl 0x40(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl %r15d, %eax
jge 0x58f45
cltq
movq 0x2f0(%r14), %r12
imulq $0x98, %rax, %rbp
movups (%r12,%rbp), %xmm0
movups 0x10(%r12,%rbp), %xmm1
movups 0x20(%r12,%rbp), %xmm2
movups 0x30(%r12,%rbp), %xmm3
movaps %xmm3, 0x190(%rsp)
movaps %xmm2, 0x180(%rsp)
movaps %xmm1, 0x170(%rsp)
movaps %xmm0, 0x160(%rsp)
leaq 0x1b0(%rsp), %rax
movq %rax, 0x1a0(%rsp)
movq 0x40(%r12,%rbp), %rsi
movq 0x48(%r12,%rbp), %rdx
addq %rsi, %rdx
leaq 0x1a0(%rsp), %rdi
callq 0xf32a
addq %rbp, %r12
movq %r13, 0x1c0(%rsp)
movq 0x60(%r12), %rsi
movq 0x68(%r12), %rdx
addq %rsi, %rdx
leaq 0x1c0(%rsp), %rdi
callq 0xf32a
movb 0x90(%r12), %al
movb %al, 0x10(%rbx)
movups 0x80(%r12), %xmm0
movups %xmm0, (%rbx)
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 0x5369a
movsd 0xfb891(%rip), %xmm1    # 0x1546c8
ucomisd %xmm0, %xmm1
jbe 0x58efa
movq 0xe8(%rsp), %r12
movq 0x1a8(%rsp), %rbp
cmpq %r12, %rbp
movq %r12, %rdx
cmovbq %rbp, %rdx
testq %rdx, %rdx
je 0x58e7c
movq 0x1a0(%rsp), %rsi
movq 0xe0(%rsp), %rdi
callq 0x4480
testl %eax, %eax
sete %al
jmp 0x58e7e
movb $0x1, %al
cmpq %rbp, %r12
setne %cl
xorb $0x1, %al
orb %cl, %al
je 0x5903e
movslq 0x40(%rsp), %rax
movq 0x68(%rsp), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x58eba
movl 0x10(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x58ec4
leaq 0x10(%rsp), %rdx
callq 0xf7b4
movslq 0x10(%rsp), %rax
movq 0x68(%rsp), %rcx
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x58ef0
movl 0x40(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x58efa
leaq 0x40(%rsp), %rdx
callq 0xf7b4
movq 0x1c0(%rsp), %rdi
cmpq %r13, %rdi
je 0x58f17
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x1a0(%rsp), %rdi
leaq 0x1b0(%rsp), %rax
cmpq %rax, %rdi
je 0x58f3c
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x4470
movl 0x10(%rsp), %eax
jmp 0x58d35
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x58f6a
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x58f8f
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4470
movl 0x40(%rsp), %eax
incl %eax
movl %eax, 0x40(%rsp)
cmpl %r15d, %eax
jl 0x58c73
testl %r15d, %r15d
jle 0x59191
xorl %ebx, %ebx
movl $0x8, %r13d
movl $0x40, %r12d
xorl %ebp, %ebp
movq 0x2f0(%r14), %rdi
addq %r12, %rdi
leaq 0xf6809(%rip), %rsi     # 0x14f7d5
callq 0x4170
testl %eax, %eax
je 0x5900c
movq 0x2f0(%r14), %rdi
addq %r12, %rdi
leaq 0xf67e4(%rip), %rsi     # 0x14f7ca
callq 0x4170
testl %eax, %eax
jne 0x59976
movq 0x68(%rsp), %rax
movq (%rax,%r13), %rcx
subq -0x8(%rax,%r13), %rcx
cmpq $0x8, %rcx
je 0x59026
jmp 0x59bcf
movq 0x68(%rsp), %rax
movq (%rax,%r13), %rcx
subq -0x8(%rax,%r13), %rcx
cmpq $0x10, %rcx
jne 0x59c46
incl %ebp
incq %rbx
addq $0x18, %r13
addq $0x98, %r12
cmpq %rbx, %r15
jne 0x58fbb
jmp 0x59193
movq 0x13dfab(%rip), %rdi    # 0x196ff0
leaq 0xfbd84(%rip), %rsi     # 0x154dd0
movl $0x63, %edx
callq 0x44e0
movq 0x13df93(%rip), %rdi    # 0x196ff0
leaq 0xfc4ca(%rip), %rsi     # 0x15552e
movl $0x1, %edx
callq 0x44e0
movq 0x13df7b(%rip), %rdi    # 0x196ff0
leaq 0xfb9b8(%rip), %rsi     # 0x154a34
movl $0x12, %edx
callq 0x44e0
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
movq 0x13df53(%rip), %rdi    # 0x196ff0
callq 0x44e0
movq %rax, %rbx
leaq 0xfb99b(%rip), %rsi     # 0x154a47
movl $0xf, %edx
movq %rax, %rdi
callq 0x44e0
movl 0x40(%rsp), %esi
movq %rbx, %rdi
callq 0x4750
movq %rax, %rbx
leaq 0xfd5f5(%rip), %rsi     # 0x1566c4
movl $0x5, %edx
movq %rax, %rdi
callq 0x44e0
movl 0x10(%rsp), %esi
movq %rbx, %rdi
callq 0x4750
leaq 0xfc43f(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
movq 0x1c0(%rsp), %rdi
cmpq %r13, %rdi
je 0x59119
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x1a0(%rsp), %rdi
leaq 0x1b0(%rsp), %rax
cmpq %rax, %rdi
je 0x5913e
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x59163
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x59cd9
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x59cd9
xorl %ebp, %ebp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x160(%rsp)
movq $0x0, 0x170(%rsp)
movl $0x0, 0xa0(%rsp)
testl %r15d, %r15d
jle 0x59246
xorl %eax, %eax
leaq 0xf660c(%rip), %rbx     # 0x14f7d5
leaq 0x160(%rsp), %r12
leaq 0xa0(%rsp), %r13
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 0x59231
movq 0x168(%rsp), %rsi
cmpq 0x170(%rsp), %rsi
je 0x59226
movl 0xa0(%rsp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x168(%rsp)
jmp 0x59231
movq %r12, %rdi
movq %r13, %rdx
callq 0xf7b4
movl 0xa0(%rsp), %eax
incl %eax
movl %eax, 0xa0(%rsp)
cmpl %r15d, %eax
jl 0x591d9
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x80(%rsp), %xmm0
mulsd %xmm1, %xmm0
addsd 0xf5dd0(%rip), %xmm0    # 0x14f038
callq 0x4700
movapd %xmm0, 0x80(%rsp)
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
divsd 0x8(%rsp), %xmm0
movq 0x58(%rsp), %rax
movsd %xmm0, (%rax)
movl 0x60(%rsp), %edi
callq 0x4410
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testl %ebp, %ebp
jle 0x592e4
xorl %r13d, %r13d
leaq 0x40(%rsp), %rbx
leaq 0xa0(%rsp), %r12
callq 0x4150
movl %eax, 0xa0(%rsp)
movl %r13d, 0xa4(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1474e
incl %r13d
cmpl %r13d, %ebp
jne 0x592bd
movq 0x40(%rsp), %rbx
movq 0x48(%rsp), %r12
cmpq %r12, %rbx
je 0x5932e
movq %r12, %rax
subq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x1d8b(%rip), %rcx     # 0x57586
movq %rbx, %rdi
movq %r12, %rsi
callq 0x695f3
leaq -0x1d9d(%rip), %rdx     # 0x57586
movq %rbx, %rdi
movq %r12, %rsi
callq 0x696be
leaq 0x10(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0xa0(%rsp), %rdi
leaq 0x37(%rsp), %rcx
movq %r15, 0x60(%rsp)
movq %r15, %rsi
callq 0x383b0
movq 0x98(%rsp), %r12
cvttsd2si 0x80(%rsp), %ecx
movabsq $-0x8000000000000000, %r15 # imm = 0x8000000000000000
movl $0x0, (%r12)
testl %ecx, %ecx
jle 0x593d9
movq 0x40(%rsp), %rax
movq 0x160(%rsp), %rdx
movq 0xa0(%rsp), %rsi
movl %ecx, %edi
xorl %r8d, %r8d
leaq 0x3f(%r15), %r9
movslq 0x4(%rax,%r8,8), %rcx
movslq (%rdx,%rcx,4), %rcx
leaq 0x3f(%rcx), %r10
testq %rcx, %rcx
cmovnsq %rcx, %r10
sarq $0x6, %r10
movq %rcx, %r11
andq %r9, %r11
xorl %ebx, %ebx
cmpq %r15, %r11
setbe %bl
movl $0x1, %r11d
shlq %cl, %r11
leaq (%rsi,%r10,8), %rcx
orq %r11, -0x8(%rcx,%rbx,8)
incq %r8
movl %r8d, (%r12)
cmpq %r8, %rdi
jne 0x59395
imull $0x2710, %ebp, %eax     # imm = 0x2710
movl %eax, 0x30(%rsp)
xorl %ebx, %ebx
leaq 0x10(%rsp), %r13
leaq 0x3f(%r15), %rax
movq %rax, 0x80(%rsp)
movq %r15, %r12
movq 0x60(%rsp), %r15
movq %rbx, 0x98(%rsp)
movl $0xffffffff, 0x58(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
testl %r15d, %r15d
leaq 0xf63b5(%rip), %rbx     # 0x14f7d5
jle 0x5961d
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq 0x2f0(%r14), %rax
imulq $0x98, %rbp, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
movq %rbx, %rsi
callq 0x4170
testl %eax, %eax
jne 0x595d0
movq 0xa0(%rsp), %rax
movq %rbp, %rcx
shrq $0x6, %rcx
movq (%rax,%rcx,8), %rax
btq %rbp, %rax
jae 0x595d0
movq %r12, %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq (,%rbp,2), %rbx
addq %rbp, %rbx
xorl %r12d, %r12d
movq 0x68(%rsp), %rax
movq (%rax,%rbx,8), %rcx
movslq (%rcx,%r12,4), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdx
movl (%rdx), %eax
cmpq %rax, %rbp
jne 0x594c9
addq $0x4, %rdx
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x594e2
movl (%rdx), %eax
movl %eax, (%rsi)
jmp 0x594d7
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x594e2
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x594ea
movq %r13, %rdi
callq 0xf7b4
incq %r12
cmpq $0x4, %r12
jne 0x59497
movq 0x10(%rsp), %rdi
movslq (%rdi), %rcx
movq 0xa0(%rsp), %rax
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
movq 0x80(%rsp), %r9
andq %r9, %rsi
xorl %r8d, %r8d
movq %r15, %r12
cmpq %r15, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jae 0x59549
xorl %ebx, %ebx
movl %ebp, 0x8(%rsp)
movq 0x60(%rsp), %r15
jmp 0x595b8
movslq 0x4(%rdi), %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
andq %r9, %rsi
xorl %r8d, %r8d
cmpq %r12, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
movq 0x60(%rsp), %r15
jb 0x595b2
movslq 0x8(%rdi), %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
andq %r9, %rsi
xorl %r8d, %r8d
cmpq %r12, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jae 0x595de
xorl %ebx, %ebx
movl %ebp, 0x8(%rsp)
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
testb %bl, %bl
leaq 0xf6207(%rip), %rbx     # 0x14f7d5
je 0x5961d
incq %rbp
cmpq %r15, %rbp
jne 0x59430
jmp 0x5961d
movslq 0xc(%rdi), %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
leaq (%rax,%rdx,8), %rax
movq %rcx, %rdx
andq %r9, %rdx
xorl %esi, %esi
cmpq %r12, %rdx
setbe %sil
movq -0x8(%rax,%rsi,8), %rax
btq %rcx, %rax
setae %bl
movl 0x8(%rsp), %eax
cmovbl %ebp, %eax
movl %eax, 0x8(%rsp)
jmp 0x595b8
testl %r15d, %r15d
setg %al
cmpl $0x0, 0x8(%rsp)
setns %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x5980e
movl $0xffffffff, 0x58(%rsp) # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq 0x2f0(%r14), %rax
imulq $0x98, %rbp, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
movq %rbx, %rsi
callq 0x4170
testl %eax, %eax
jne 0x597f8
movq 0xa0(%rsp), %rax
movq %rbp, %rcx
shrq $0x6, %rcx
movq (%rax,%rcx,8), %rax
btq %rbp, %rax
jb 0x597f8
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
xorl %ebx, %ebx
movq 0x68(%rsp), %rax
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
movq (%rax,%rcx,8), %rcx
movslq (%rcx,%rbx,4), %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdx
movl (%rdx), %eax
cmpq %rax, %rbp
jne 0x596d5
addq $0x4, %rdx
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x596ee
movl (%rdx), %eax
movl %eax, (%rsi)
jmp 0x596e3
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x596ee
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x596f6
movq %r13, %rdi
callq 0xf7b4
incq %rbx
cmpq $0x4, %rbx
jne 0x59698
movq 0x10(%rsp), %rdi
movslq (%rdi), %rcx
movq 0xa0(%rsp), %rax
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
movq 0x80(%rsp), %r9
andq %r9, %rsi
xorl %r8d, %r8d
cmpq %r12, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jb 0x597de
movslq 0x4(%rdi), %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
andq %r9, %rsi
xorl %r8d, %r8d
cmpq %r12, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jb 0x597de
movslq 0x8(%rdi), %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
leaq (%rax,%rdx,8), %rdx
movq %rcx, %rsi
andq %r9, %rsi
xorl %r8d, %r8d
cmpq %r12, %rsi
setbe %r8b
movq -0x8(%rdx,%r8,8), %rdx
btq %rcx, %rdx
jb 0x597de
movslq 0xc(%rdi), %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
leaq (%rax,%rdx,8), %rax
movq %rcx, %rdx
andq %r9, %rdx
xorl %esi, %esi
cmpq %r12, %rdx
setbe %sil
movq -0x8(%rax,%rsi,8), %rax
btq %rcx, %rax
jae 0x59806
movb $0x1, %bl
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
testb %bl, %bl
leaq 0xf5fdf(%rip), %rbx     # 0x14f7d5
je 0x5980e
incq %rbp
cmpq %r15, %rbp
jne 0x59640
jmp 0x5980e
xorl %ebx, %ebx
movl %ebp, 0x58(%rsp)
jmp 0x597e0
cmpl $0x0, 0x8(%rsp)
movq 0x98(%rsp), %rbx
movq 0x13d7ce(%rip), %rbp    # 0x196ff0
movl 0x58(%rsp), %edi
js 0x59860
testl %edi, %edi
js 0x59860
movq 0xa0(%rsp), %rax
movl 0x8(%rsp), %ecx
movl %ecx, %edx
movq $-0x2, %rsi
rolq %cl, %rsi
shrl $0x6, %edx
andq %rsi, (%rax,%rdx,8)
movl %edi, %edx
movl $0x1, %esi
movl %edi, %ecx
shlq %cl, %rsi
shrl $0x6, %edx
orq %rsi, (%rax,%rdx,8)
jmp 0x59893
cmpl $0x0, 0x8(%rsp)
js 0x59893
movl $0x38, %edx
movq %rbp, %rdi
leaq 0xfb81b(%rip), %rsi     # 0x155091
callq 0x44e0
movl $0x1, %edx
movq %rbp, %rdi
leaq 0xfbca4(%rip), %rsi     # 0x15552e
callq 0x44e0
xorl %eax, %eax
jmp 0x59897
incl %ebx
movb $0x1, %al
testb %al, %al
je 0x598f2
cmpl $0x0, 0x8(%rsp)
js 0x598ac
cmpl 0x30(%rsp), %ebx
jl 0x593fe
cmpl 0x30(%rsp), %ebx
jne 0x599c2
movq 0x13d733(%rip), %rdi    # 0x196ff0
leaq 0xfb806(%rip), %rsi     # 0x1550ca
movl $0x2d, %edx
callq 0x44e0
movq 0x13d71b(%rip), %rdi    # 0x196ff0
movl 0x30(%rsp), %esi
callq 0x4750
leaq 0xfb813(%rip), %rsi     # 0x1550f8
movl $0x6, %edx
movq %rax, %rdi
callq 0x44e0
xorl %ebx, %ebx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x59939
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 %rax, 0xc0(%rsp)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x59950
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x59cdb
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x59cdb
movq 0x13d673(%rip), %rdi    # 0x196ff0
leaq 0xfb543(%rip), %rsi     # 0x154ec7
movl $0x5c, %edx
callq 0x44e0
movq 0x13d65b(%rip), %r14    # 0x196ff0
leaq 0xfbb92(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %r14, %rdi
callq 0x44e0
leaq 0xfb100(%rip), %rsi     # 0x154ab0
movl $0x12, %edx
movq %r14, %rdi
callq 0x44e0
jmp 0x59cbb
movq %r14, %rdi
movq 0x38(%rsp), %rsi
callq 0x528f4
testl %r15d, %r15d
jle 0x59ab9
movl $0x48, %r12d
xorl %ebx, %ebx
leaq 0x140(%rsp), %rbp
movzbl 0x230(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0xa0(%rsp), %rax
movq %rbx, %rcx
shrq $0x6, %rcx
movq (%rax,%rcx,8), %rax
btq %rbx, %rax
jae 0x59aa6
movq 0x38(%rsp), %rax
movq 0x2f0(%rax), %rax
leaq (%rax,%r12), %rdi
addq $-0x8, %rdi
movq 0x8(%rdi), %rdx
movl $0x2, %r8d
xorl %esi, %esi
leaq 0xfb656(%rip), %r13     # 0x15508e
movq %r13, %rcx
callq 0x4670
leaq 0x150(%rsp), %rax
movq %rax, 0x140(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
leaq 0xfb633(%rip), %rdx     # 0x155090
callq 0x2263c
movq %rbp, %rdi
movl 0x8(%rsp), %esi
callq 0x21e42
movq 0x38(%rsp), %rax
movq 0x2f0(%rax), %rax
movsd %xmm0, -0x18(%rax,%r12)
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x59aa6
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x4470
incq %rbx
addq $0x98, %r12
cmpq %rbx, %r15
jne 0x599f4
movb $0x1, %bl
testl %r15d, %r15d
jle 0x598f4
shlq $0x3, %r15
leaq (%r15,%r15,2), %r15
movl $0x40, %ebp
movq $0x0, 0x8(%rsp)
leaq 0xf5ce9(%rip), %r12     # 0x14f7ca
xorl %r13d, %r13d
movq 0x2f0(%r14), %rdi
addq %rbp, %rdi
movq %r12, %rsi
callq 0x4170
testl %eax, %eax
jne 0x59bb6
movq 0x68(%rsp), %rcx
movq (%rcx,%r13), %rax
cmpq %rax, 0x8(%rcx,%r13)
je 0x59cf9
movslq (%rax), %rax
movq 0x38(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
leaq 0xfb557(%rip), %rsi     # 0x15508e
callq 0x4170
testl %eax, %eax
je 0x59b8e
movq 0x68(%rsp), %rcx
movq (%rcx,%r13), %rax
movq 0x8(%rcx,%r13), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq $0x2, %rdx
jb 0x59cfd
movslq 0x4(%rax), %rax
movq 0x38(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
leaq 0xfb509(%rip), %rsi     # 0x15508e
callq 0x4170
testl %eax, %eax
jne 0x59bb6
movq 0x38(%rsp), %rax
movq 0x2f0(%rax), %rdi
movq 0x8(%rdi,%rbp), %rdx
addq %rbp, %rdi
movl $0x4, %r8d
xorl %esi, %esi
leaq 0xfb4db(%rip), %rcx     # 0x15508c
callq 0x4670
addq $0x18, %r13
addq $0x98, %rbp
cmpq %r13, %r15
jne 0x59ae4
jmp 0x598f4
movq 0x13d41a(%rip), %rdi    # 0x196ff0
leaq 0xfb2a1(%rip), %rsi     # 0x154e7e
movl $0x48, %edx
callq 0x44e0
movq 0x68(%rsp), %rax
movq (%rax,%r13), %rsi
subq -0x8(%rax,%r13), %rsi
sarq $0x2, %rsi
movq 0x13d3f0(%rip), %rdi    # 0x196ff0
callq 0x42b0
movq %rax, %r14
leaq 0xfaef2(%rip), %rsi     # 0x154b01
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfb90b(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %r14, %rdi
callq 0x44e0
leaq 0xfae79(%rip), %rsi     # 0x154ab0
movl $0x12, %edx
movq %r14, %rdi
callq 0x44e0
jmp 0x59cbb
movq 0x13d3a3(%rip), %rdi    # 0x196ff0
leaq 0xfb1e0(%rip), %rsi     # 0x154e34
movl $0x49, %edx
callq 0x44e0
movq 0x68(%rsp), %rax
movq (%rax,%r13), %rsi
subq -0x8(%rax,%r13), %rsi
sarq $0x2, %rsi
movq 0x13d379(%rip), %rdi    # 0x196ff0
callq 0x42b0
movq %rax, %r14
leaq 0xfae10(%rip), %rsi     # 0x154a96
movl $0x19, %edx
movq %rax, %rdi
callq 0x44e0
leaq 0xfb894(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %r14, %rdi
callq 0x44e0
leaq 0xfae02(%rip), %rsi     # 0x154ab0
movl $0x12, %edx
movq %r14, %rdi
callq 0x44e0
movq %r14, %rdi
movl %ebx, %esi
callq 0x4750
leaq 0xfb862(%rip), %rsi     # 0x15552e
movl $0x1, %edx
movq %rax, %rdi
callq 0x44e0
xorl %ebx, %ebx
leaq 0x68(%rsp), %rdi
callq 0xefda
movl %ebx, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edx, %edx
jmp 0x59d07
movl $0x1, %eax
movq %rax, 0x8(%rsp)
leaq 0xf5997(%rip), %rdi     # 0x14f6a5
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x4630
jmp 0x59d8d
jmp 0x59dcb
jmp 0x59d8d
jmp 0x59dcb
movq %rax, %rbx
jmp 0x59e9c
jmp 0x59d8d
movq %rax, %rbx
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x59e40
movq 0x150(%rsp), %rsi
incq %rsi
jmp 0x59e3b
jmp 0x59d8d
jmp 0x59d8d
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x59ec3
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0x59ec3
jmp 0x59dc1
movq %rax, %rbx
jmp 0x59e40
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x59eb9
movq 0xf0(%rsp), %rsi
incq %rsi
jmp 0x59eb4
movq %rax, %rbx
jmp 0x59eb9
jmp 0x59e02
movq %rax, %rbx
jmp 0x59e85
movq %rax, %rbx
jmp 0x59e12
movq %rax, %rbx
movq 0x1a0(%rsp), %rdi
leaq 0x1b0(%rsp), %rax
cmpq %rax, %rdi
je 0x59e12
movq 0x1b0(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x59e12
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0x2f814
leaq 0xa0(%rsp), %rdi
callq 0x2f814
jmp 0x59eb9
jmp 0x59e26
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x59e40
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x59e85
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 %rax, 0xc0(%rsp)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x59e9c
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x160(%rsp), %rdi
testq %rdi, %rdi
je 0x59eb9
movq 0x170(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x68(%rsp), %rdi
callq 0xefda
movq %rbx, %rdi
callq 0x4780