// File: /workspace/github_cpp_makefile_star2_O2/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 0xb96d1(%rip), %xmm0    # 0xfc038
jbe 0x4297e
movq 0x10d680(%rip), %rdi    # 0x14fff0
leaq 0xbf3ff(%rip), %rsi     # 0x101d76
callq 0x4480
jmp 0x429af
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movsd %xmm0, 0x8(%rsp)
jbe 0x429c5
movq 0x10d65b(%rip), %rdi    # 0x14fff0
leaq 0xbf430(%rip), %rsi     # 0x101dcc
callq 0x4480
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x46c0
leaq 0xbfbc8(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
xorl %ebx, %ebx
jmp 0x42bb1
movq %rdi, %r14
movq %r9, 0x50(%rsp)
movl %ecx, 0x14(%rsp)
movq %r8, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movslq 0x110(%rdi), %r12
xorpd %xmm0, %xmm0
leaq 0xa0(%rsp), %rdx
movapd %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
leaq 0x58(%rsp), %rdi
leaq 0x160(%rsp), %rcx
movq %r12, %rsi
callq 0x4b956
leaq 0xa0(%rsp), %r13
movq %r13, %rdi
callq 0xb290
xorl %eax, %eax
leaq 0x70(%rsp), %r15
leaq 0x160(%rsp), %rbx
leaq 0x20(%rsp), %rbp
movl %eax, 0x70(%rsp)
cmpl %r12d, %eax
jge 0x42bc5
cltq
imulq $0x98, %rax, %rsi
addq 0x2f0(%r14), %rsi
movq %r13, %rdi
callq 0xa75c
movq %r15, %rax
movslq (%rax), %rax
incq %rax
movl %eax, 0x20(%rsp)
cmpl %r12d, %eax
jge 0x42af2
imulq $0x98, %rax, %rsi
addq 0x2f0(%r14), %rsi
movq %rbx, %rdi
callq 0xa75c
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x3f612
movsd 0xbec49(%rip), %xmm1    # 0x1016e0
ucomisd %xmm0, %xmm1
jbe 0x42ae2
leaq 0xe0(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0x4040
testl %eax, %eax
je 0x42b05
movslq 0x70(%rsp), %rax
imulq $0x18, %rax, %rdi
addq 0x58(%rsp), %rdi
movq %rbp, %rsi
callq 0x9434
movslq 0x20(%rsp), %rax
imulq $0x18, %rax, %rdi
addq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x9434
movq %rbx, %rdi
callq 0xa808
movq %rbp, %rax
jmp 0x42a58
movq %r13, %rdi
callq 0xa808
movl 0x70(%rsp), %eax
incl %eax
jmp 0x42a30
movq 0x10d4e4(%rip), %rdi    # 0x14fff0
leaq 0xbf30d(%rip), %rsi     # 0x101e20
callq 0x4480
leaq 0xbfa5f(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xbef56(%rip), %rsi     # 0x101a84
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
leaq 0xe0(%rsp), %rsi
callq 0x43f0
leaq 0xbef4a(%rip), %rsi     # 0x101a97
movq %rax, %rdi
callq 0x4480
movl 0x70(%rsp), %esi
movq %rax, %rdi
callq 0x4760
leaq 0xc0bcc(%rip), %rsi     # 0x103734
movq %rax, %rdi
callq 0x4480
movl 0x20(%rsp), %esi
movq %rax, %rdi
callq 0x4760
leaq 0xbf9fb(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x160(%rsp), %rdi
callq 0xa808
leaq 0xa0(%rsp), %rdi
callq 0xa808
xorl %ebx, %ebx
leaq 0x58(%rsp), %rdi
callq 0xad7e
movl %ebx, %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebx, %ebx
testl %r12d, %r12d
movl $0x0, %ebp
cmovgl %r12d, %ebp
pushq $0x8
popq %r15
pushq $0x40
popq %r13
movl $0x0, 0x18(%rsp)
cmpq %rbx, %rbp
je 0x42c6c
movq 0x2f0(%r14), %rdi
addq %r13, %rdi
leaq 0xb9bee(%rip), %rsi     # 0xfc7eb
callq 0x4190
testl %eax, %eax
je 0x42c3d
movq 0x2f0(%r14), %rdi
addq %r13, %rdi
leaq 0xb9bc9(%rip), %rsi     # 0xfc7e0
callq 0x4190
testl %eax, %eax
jne 0x430c8
movq 0x58(%rsp), %rax
movq (%rax,%r15), %rcx
subq -0x8(%rax,%r15), %rcx
cmpq $0x8, %rcx
je 0x42c59
jmp 0x430d8
movq 0x58(%rsp), %rax
movq (%rax,%r15), %rcx
subq -0x8(%rax,%r15), %rcx
cmpq $0x10, %rcx
jne 0x43111
incl 0x18(%rsp)
incq %rbx
addq $0x18, %r15
addq $0x98, %r13
jmp 0x42be3
xorpd %xmm0, %xmm0
leaq 0x160(%rsp), %rbx
andq $0x0, 0x10(%rbx)
movapd %xmm0, (%rbx)
xorl %eax, %eax
leaq 0xb9b61(%rip), %r15     # 0xfc7eb
leaq 0xa0(%rsp), %r13
movsd 0x8(%rsp), %xmm0
movl %eax, 0xa0(%rsp)
cmpl %r12d, %eax
jge 0x42cde
cltq
movq 0x2f0(%r14), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
movq %r15, %rsi
callq 0x4190
testl %eax, %eax
jne 0x42cd3
movq %rbx, %rdi
movq %r13, %rsi
callq 0x9434
movl 0xa0(%rsp), %eax
incl %eax
jmp 0x42c92
movl 0x18(%rsp), %r15d
cvtsi2sd %r15d, %xmm1
movsd %xmm1, 0x90(%rsp)
mulsd %xmm1, %xmm0
addsd 0xb933b(%rip), %xmm0    # 0xfc038
callq 0x4720
cvttsd2si %xmm0, %eax
movl %eax, 0x8(%rsp)
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
divsd 0x90(%rsp), %xmm0
movq 0x50(%rsp), %rax
movsd %xmm0, (%rax)
movl 0x14(%rsp), %edi
callq 0x4460
leaq 0x70(%rsp), %rax
andq $0x0, 0x10(%rax)
xorpd %xmm0, %xmm0
movapd %xmm0, (%rax)
xorl %r13d, %r13d
testl %r15d, %r15d
movl $0x0, %ebx
cmovgl %r15d, %ebx
leaq 0xa0(%rsp), %r15
cmpl %r13d, %ebx
je 0x42d81
callq 0x4170
movl %eax, 0xa0(%rsp)
movl %r13d, 0xa4(%rsp)
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x109e8
incl %r13d
jmp 0x42d56
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rsi
leaq -0x1093(%rip), %rdx     # 0x41cff
callq 0x4d0b4
leaq 0x20(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0xa0(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
movq %r12, %rsi
callq 0x2a0d6
xorl %eax, %eax
leaq 0xa0(%rsp), %rbx
movq 0x48(%rsp), %r15
movl 0x8(%rsp), %r12d
movl %eax, (%r15)
cmpl %r12d, %eax
jge 0x42dfa
cltq
movq 0x70(%rsp), %rcx
movslq 0x4(%rcx,%rax,8), %rax
movq 0x160(%rsp), %rcx
movslq (%rcx,%rax,4), %rsi
movq %rbx, %rdi
callq 0x1043e
orq %rdx, (%rax)
movl (%r15), %eax
incl %eax
jmp 0x42dc8
imull $0x2710, 0x18(%rsp), %eax # imm = 0x2710
movl %eax, 0x48(%rsp)
xorl %ecx, %ecx
leaq 0xa0(%rsp), %r12
leaq 0xb99d4(%rip), %r15     # 0xfc7eb
leaq 0x20(%rsp), %r13
movq %rbp, 0x98(%rsp)
movq %rcx, 0x50(%rsp)
xorl %ebx, %ebx
pushq $-0x1
popq %rax
movl %eax, 0x8(%rsp)
cmpq %rbp, %rbx
je 0x42f4b
movq 0x2f0(%r14), %rax
imulq $0x98, %rbx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
movq %r15, %rsi
callq 0x4190
testl %eax, %eax
jne 0x42f1e
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1043e
testq %rdx, (%rax)
je 0x42f1e
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
xorl %r15d, %r15d
cmpq $0x4, %r15
je 0x42ec2
movq 0x58(%rsp), %rax
imulq $0x18, %rbx, %rcx
movq (%rax,%rcx), %rcx
movslq (%rcx,%r15,4), %rcx
imulq $0x18, %rcx, %rcx
movq (%rax,%rcx), %rax
movl (%rax), %ecx
xorl %edx, %edx
cmpq %rcx, %rbx
sete %dl
leaq (%rax,%rdx,4), %rsi
movq %r13, %rdi
callq 0x9434
incq %r15
jmp 0x42e88
movq 0x20(%rsp), %rax
movslq (%rax), %rsi
movq %r12, %rdi
callq 0x1043e
testq %rdx, (%rax)
jne 0x42f03
movq 0x20(%rsp), %rax
movslq 0x4(%rax), %rsi
movq %r12, %rdi
callq 0x1043e
testq %rdx, (%rax)
jne 0x42f03
movq 0x20(%rsp), %rax
movslq 0x8(%rax), %rsi
movq %r12, %rdi
callq 0x1043e
testq %rdx, (%rax)
je 0x42f26
xorl %r15d, %r15d
movl %ebx, 0x8(%rsp)
movq %r13, %rdi
callq 0xb290
testb %r15b, %r15b
leaq 0xb98cf(%rip), %r15     # 0xfc7eb
je 0x42f4b
incq %rbx
jmp 0x42e32
movq 0x20(%rsp), %rax
movslq 0xc(%rax), %rsi
movq %r12, %rdi
callq 0x1043e
testq %rdx, (%rax)
sete %r15b
movl 0x8(%rsp), %eax
cmovnel %ebx, %eax
movl %eax, 0x8(%rsp)
jmp 0x42f0a
cmpl $0x0, 0x8(%rsp)
js 0x43189
xorl %ebx, %ebx
pushq $-0x1
popq %rax
movl %eax, 0x14(%rsp)
cmpq %rbp, %rbx
je 0x4307c
movq 0x2f0(%r14), %rax
imulq $0x98, %rbx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x40, %rdi
movq %r15, %rsi
callq 0x4190
testl %eax, %eax
jne 0x4306b
movq %r12, %rdi
movq %rbx, %rsi
callq 0x1043e
testq %rdx, (%rax)
jne 0x4306b
movq %r12, %rbp
andq $0x0, 0x30(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
imulq $0x18, %rbx, %r15
xorl %r12d, %r12d
cmpq $0x4, %r12
je 0x42ff2
movq 0x58(%rsp), %rax
movq (%rax,%r15), %rcx
movslq (%rcx,%r12,4), %rcx
imulq $0x18, %rcx, %rcx
movq (%rax,%rcx), %rax
movl (%rax), %ecx
xorl %edx, %edx
cmpq %rcx, %rbx
sete %dl
leaq (%rax,%rdx,4), %rsi
movq %r13, %rdi
callq 0x9434
incq %r12
jmp 0x42fbc
movq 0x20(%rsp), %rax
movslq (%rax), %rsi
movq %rbp, %r12
movq %rbp, %rdi
callq 0x1043e
testq %rdx, (%rax)
movq 0x98(%rsp), %rbp
jne 0x43054
movq 0x20(%rsp), %rax
movslq 0x4(%rax), %rsi
movq %r12, %rdi
callq 0x1043e
testq %rdx, (%rax)
jne 0x43054
movq 0x20(%rsp), %rax
movslq 0x8(%rax), %rsi
movq %r12, %rdi
callq 0x1043e
testq %rdx, (%rax)
jne 0x43054
movq 0x20(%rsp), %rax
movslq 0xc(%rax), %rsi
movq %r12, %rdi
callq 0x1043e
testq %rdx, (%rax)
je 0x43073
movb $0x1, %r15b
movq %r13, %rdi
callq 0xb290
testb %r15b, %r15b
leaq 0xb9782(%rip), %r15     # 0xfc7eb
je 0x4307c
incq %rbx
jmp 0x42f5f
xorl %r15d, %r15d
movl %ebx, 0x14(%rsp)
jmp 0x43057
movl 0x14(%rsp), %ebx
testl %ebx, %ebx
js 0x43349
movl 0x8(%rsp), %esi
movq %r12, %rdi
callq 0x1043e
notq %rdx
andq %rdx, (%rax)
movl %ebx, %esi
movq %r12, %rdi
callq 0x1043e
movq 0x50(%rsp), %rcx
orq %rdx, (%rax)
incl %ecx
cmpl $0x0, 0x8(%rsp)
js 0x43190
cmpl 0x48(%rsp), %ecx
jl 0x42e24
jmp 0x43190
movq 0x10cf21(%rip), %rdi    # 0x14fff0
leaq 0xbee41(%rip), %rsi     # 0x101f17
jmp 0x43148
movq 0x10cf11(%rip), %rdi    # 0x14fff0
leaq 0xbede8(%rip), %rsi     # 0x101ece
callq 0x4480
movq 0x58(%rsp), %rcx
movq (%rcx,%r15), %rsi
subq -0x8(%rcx,%r15), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
leaq 0xbea42(%rip), %rsi     # 0x101b51
jmp 0x43148
movq 0x10ced8(%rip), %rdi    # 0x14fff0
leaq 0xbed65(%rip), %rsi     # 0x101e84
callq 0x4480
movq 0x58(%rsp), %rcx
movq (%rcx,%r15), %rsi
subq -0x8(%rcx,%r15), %rsi
sarq $0x2, %rsi
movq %rax, %rdi
callq 0x42e0
movq %rax, %rdi
leaq 0xbe99e(%rip), %rsi     # 0x101ae6
callq 0x4480
leaq 0xbf42a(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xbe99d(%rip), %rsi     # 0x101b00
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movl %ebx, %esi
callq 0x4760
leaq 0xbf402(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
jmp 0x42ba5
movq 0x50(%rsp), %rcx
incl %ecx
cmpl 0x48(%rsp), %ecx
jne 0x431c9
movq 0x10ce53(%rip), %rdi    # 0x14fff0
leaq 0xbef76(%rip), %rsi     # 0x10211a
callq 0x4480
movq %rax, %rdi
movl 0x48(%rsp), %esi
callq 0x4760
leaq 0xbef8c(%rip), %rsi     # 0x102148
movq %rax, %rdi
callq 0x4480
jmp 0x4336b
movq %r14, %rdi
movq 0x40(%rsp), %rsi
callq 0x3eada
pushq $0x40
popq %r12
xorl %ebx, %ebx
leaq 0x140(%rsp), %r13
movzbl 0x230(%rsp), %eax
movl %eax, 0x8(%rsp)
cmpq %rbx, %rbp
je 0x4326b
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
callq 0x1043e
testq %rdx, (%rax)
je 0x4325f
movq 0x40(%rsp), %rax
movq 0x2f0(%rax), %rdi
addq %r12, %rdi
leaq 0xbeebe(%rip), %r15     # 0x1020de
movq %r15, %rsi
callq 0x4810
movq %r13, %rdi
movq %r15, %rsi
leaq 0x20(%rsp), %rdx
callq 0x1b80e
movq %r13, %rdi
movl 0x8(%rsp), %esi
callq 0x1b1bb
movq 0x40(%rsp), %rax
movq 0x2f0(%rax), %rax
movsd %xmm0, -0x10(%rax,%r12)
movq %r13, %rdi
callq 0x4210
incq %rbx
addq $0x98, %r12
jmp 0x431f0
imulq $0x18, %rbp, %rbp
pushq $0x40
popq %r12
xorl %r13d, %r13d
leaq 0xb9563(%rip), %rbx     # 0xfc7e0
leaq 0xbee5a(%rip), %r15     # 0x1020de
cmpq %r13, %rbp
je 0x43345
movq 0x2f0(%r14), %rdi
addq %r12, %rdi
movq %rbx, %rsi
callq 0x4190
testl %eax, %eax
jne 0x43335
movq 0x58(%rsp), %rdi
addq %r13, %rdi
xorl %esi, %esi
callq 0xac00
movslq (%rax), %rax
movq 0x40(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
movq %r15, %rsi
callq 0x4190
testl %eax, %eax
je 0x4331a
movq 0x58(%rsp), %rdi
addq %r13, %rdi
pushq $0x1
popq %rsi
callq 0xac00
movslq (%rax), %rax
movq 0x40(%rsp), %rcx
movq 0x2f0(%rcx), %rcx
imulq $0x98, %rax, %rax
leaq (%rcx,%rax), %rdi
addq $0x40, %rdi
movq %r15, %rsi
callq 0x4190
testl %eax, %eax
jne 0x43335
movq 0x40(%rsp), %rax
movq 0x2f0(%rax), %rdi
addq %r12, %rdi
leaq 0xbedac(%rip), %rsi     # 0x1020dc
callq 0x4810
addq $0x18, %r13
addq $0x98, %r12
jmp 0x43284
movb $0x1, %bl
jmp 0x4336d
movq 0x10cca0(%rip), %rdi    # 0x14fff0
leaq 0xbed8a(%rip), %rsi     # 0x1020e1
callq 0x4480
leaq 0xbf21b(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
xorl %ebx, %ebx
leaq 0xa0(%rsp), %rdi
callq 0xa976
leaq 0x70(%rsp), %rdi
callq 0x10942
leaq 0x160(%rsp), %rdi
callq 0xb290
jmp 0x42ba7
jmp 0x433f3
jmp 0x433e3
jmp 0x433e3
jmp 0x433f3
jmp 0x43401
jmp 0x43401
jmp 0x43401
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x4210
jmp 0x4340e
jmp 0x433f3
jmp 0x433f3
jmp 0x433f3
jmp 0x43401
jmp 0x433ec
jmp 0x433f3
jmp 0x433f3
jmp 0x433f3
movq %rax, %rbx
jmp 0x43425
jmp 0x43401
jmp 0x43401
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0xb290
jmp 0x4345b
jmp 0x433f3
movq %rax, %rbx
jmp 0x4341b
jmp 0x43401
jmp 0x43401
movq %rax, %rbx
jmp 0x43451
jmp 0x433f3
movq %rax, %rbx
jmp 0x4340e
jmp 0x43434
jmp 0x43401
movq %rax, %rbx
jmp 0x43444
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xb290
leaq 0xa0(%rsp), %rdi
callq 0xa976
leaq 0x70(%rsp), %rdi
callq 0x10942
leaq 0x160(%rsp), %rdi
callq 0xb290
jmp 0x43451
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0xa808
leaq 0xa0(%rsp), %rdi
callq 0xa808
leaq 0x58(%rsp), %rdi
callq 0xad7e
movq %rbx, %rdi
callq 0x4780