// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movl %esi, %ebp
movq %rdi, %rbx
divsd 0x18(%rdi), %xmm0
cvttsd2si %xmm0, %eax
cltd
idivl 0x28(%rdi)
movl %eax, %r14d
movq 0x8(%rdi), %rax
movsd 0x70(%rax), %xmm0
movsd %xmm0, 0x20(%rdi)
leaq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x21d0
leaq 0x30(%rbx), %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x20b0
leaq 0x78(%rsp), %rdi
callq 0x2060
testb %al, %al
je 0x3ae7
xorl %r15d, %r15d
testl %r14d, %r14d
cmovlel %r15d, %r14d
movl %r14d, (%rsp)
leaq 0x8(%rsp), %r12
leaq 0x2878(%rip), %r14      # 0x625c
xorl %eax, %eax
cmpl (%rsp), %eax
je 0x3ab3
movl %eax, 0x4(%rsp)
xorl %r13d, %r13d
cmpl 0x28(%rbx), %r13d
jge 0x3a25
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
incl %r15d
movl %r15d, %eax
cltd
idivl %ebp
testl %edx, %edx
jne 0x3a20
movq 0x8(%rbx), %rdi
movsd 0x10(%rbx), %xmm0
callq 0x321c
incl %r13d
jmp 0x39f6
movsd 0x20(%rbx), %xmm0
movq %r12, %rdi
callq 0x21c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2150
movq 0x8(%rbx), %rdi
callq 0x40dc
movq %r12, %rdi
callq 0x21c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2150
movq 0x8(%rbx), %rax
movsd 0x80(%rax), %xmm0
movq %r12, %rdi
callq 0x21c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2150
movq 0x8(%rbx), %rax
movsd 0x78(%rax), %xmm0
addsd 0x80(%rax), %xmm0
movq %r12, %rdi
callq 0x21c0
movq %rax, %rdi
callq 0x20c0
cmpb $0x1, 0x50(%rbx)
jne 0x3aa8
movq 0x8(%rbx), %rdi
callq 0x300c
movl 0x4(%rsp), %eax
incl %eax
jmp 0x39e6
leaq 0x8(%rsp), %rdi
callq 0x2180
movq 0x8(%rbx), %rax
movsd 0x20(%rbx), %xmm0
movsd %xmm0, 0x70(%rax)
leaq 0x8(%rsp), %rdi
callq 0x21a0
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x54e2(%rip), %rdi      # 0x8fd0
leaq 0x274c(%rip), %rsi      # 0x6241
callq 0x2150
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rdi
callq 0x2160
jmp 0x3b0e
jmp 0x3b0e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x2200
nop