// File: joraso[P]Glassius/Integration.cpp
// Function: Integrator::Equilibrate(double, int)
void Integrator::Equilibrate(double t, int Nthermalize){
    /* Advanced the integration for time=t, themostating the system every
    Nthermalize steps. Records into an energy file as it does. */
    
    // Cycling indeces
    int m, n; int steps = int(t/dt);
    int cycles = int(steps/Nrecord);
    int s = 0; // thermostat counter
    
    // Retrieving the system time
    time = System->Time();
    
    // Prepping output file
    std::ofstream energyfile;
    energyfile.open(efilename, std::ios::app);
    
    // File check-stop
    if(!energyfile.is_open()){
        cout << "Error opening energy file!" << endl;
        exit(1);
    }
    
    // Integrating
    for(m=0;m<cycles;m++){
        for(n=0;n<Nrecord;n++){
            Propigate(); s++;
            if(s%Nthermalize==0){System->Thermalize(Temp);}
        }
        energyfile << time << ", ";
        energyfile << System->KE() << ", ";
        energyfile << System->PE() << ", ";
        energyfile << System->TotalEnergy() << std::endl;
        if (recordtraj) {System->SaveTrajectory();};
    }
    
    // Closing the energy file
    energyfile.close();
    
    // Storing the system time
    System->setTime(time);
    
    return;
}

// Assembly:
subq $0x298, %rsp            # imm = 0x298
movq %rdi, 0x290(%rsp)
movsd %xmm0, 0x288(%rsp)
movl %esi, 0x284(%rsp)
movq 0x290(%rsp), %rcx
movq %rcx, 0x50(%rsp)
movsd 0x288(%rsp), %xmm0
movsd 0x18(%rcx), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x278(%rsp)
movl 0x278(%rsp), %eax
movl 0x28(%rcx), %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x274(%rsp)
movl $0x0, 0x270(%rsp)
movq 0x8(%rax), %rdi
callq 0x5d00
movq 0x50(%rsp), %rax
movsd %xmm0, 0x20(%rax)
leaq 0x70(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x21e0
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0x30, %rsi
movl $0x1, %edx
callq 0x20a0
jmp 0x4fbb
leaq 0x70(%rsp), %rdi
callq 0x20e0
movb %al, 0x4f(%rsp)
jmp 0x4fcb
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0x5029
jmp 0x4fd5
movq 0x6ff4(%rip), %rdi      # 0xbfd0
leaq 0x4226(%rip), %rsi      # 0x9209
callq 0x2140
movq %rax, 0x40(%rsp)
jmp 0x4fef
movq 0x40(%rsp), %rdi
movq 0x6fbd(%rip), %rsi      # 0xbfb8
callq 0x2150
jmp 0x5002
movl $0x1, %edi
callq 0x2170
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x21c0
jmp 0x521b
movl $0x0, 0x280(%rsp)
movl 0x280(%rsp), %eax
cmpl 0x274(%rsp), %eax
jge 0x51e8
movl $0x0, 0x27c(%rsp)
movq 0x50(%rsp), %rcx
movl 0x27c(%rsp), %eax
cmpl 0x28(%rcx), %eax
jge 0x50c5
movq 0x50(%rsp), %rdi
movq (%rdi), %rax
movq 0x8(%rax), %rax
callq *%rax
jmp 0x5074
movl 0x270(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x270(%rsp)
movl 0x270(%rsp), %eax
cltd
idivl 0x284(%rsp)
cmpl $0x0, %edx
jne 0x50b0
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rdi
movsd 0x10(%rax), %xmm0
callq 0x4050
jmp 0x50ae
jmp 0x50b0
jmp 0x50b2
movl 0x27c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x27c(%rsp)
jmp 0x5053
movq 0x50(%rsp), %rax
movsd 0x20(%rax), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x2240
movq %rax, 0x38(%rsp)
jmp 0x50e0
movq 0x38(%rsp), %rdi
leaq 0x4138(%rip), %rsi      # 0x9224
callq 0x2140
jmp 0x50f3
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x5d10
movsd %xmm0, 0x30(%rsp)
jmp 0x5109
movsd 0x30(%rsp), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x2240
movq %rax, 0x28(%rsp)
jmp 0x5120
movq 0x28(%rsp), %rdi
leaq 0x40f8(%rip), %rsi      # 0x9224
callq 0x2140
jmp 0x5133
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x5d40
movsd %xmm0, 0x20(%rsp)
jmp 0x5149
movsd 0x20(%rsp), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x2240
movq %rax, 0x18(%rsp)
jmp 0x5160
movq 0x18(%rsp), %rdi
leaq 0x40b8(%rip), %rsi      # 0x9224
callq 0x2140
jmp 0x5173
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x5d60
movsd %xmm0, 0x10(%rsp)
jmp 0x5189
movsd 0x10(%rsp), %xmm0
leaq 0x70(%rsp), %rdi
callq 0x2240
movq %rax, 0x8(%rsp)
jmp 0x51a0
movq 0x8(%rsp), %rdi
movq 0x6e0c(%rip), %rsi      # 0xbfb8
callq 0x2150
jmp 0x51b3
movq 0x50(%rsp), %rax
testb $0x1, 0x50(%rax)
je 0x51d0
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x3cf0
jmp 0x51ce
jmp 0x51d0
jmp 0x51d2
movl 0x280(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x280(%rsp)
jmp 0x5034
leaq 0x70(%rsp), %rdi
callq 0x21a0
jmp 0x51f4
movq 0x50(%rsp), %rax
movq 0x8(%rax), %rdi
movsd 0x20(%rax), %xmm0
callq 0x5d80
jmp 0x5209
leaq 0x70(%rsp), %rdi
callq 0x21c0
addq $0x298, %rsp            # imm = 0x298
retq
movq 0x68(%rsp), %rdi
callq 0x2210
nopw %cs:(%rax,%rax)