// File: /workspace/github_cpp_makefile_star2_O3/DavidLBruce[P]sim3dof/build/../src/MdlBase.cpp
// Function: MdlBase::Integrate(double&)
void MdlBase::Integrate(double   &timeStep )
{
  //   
  // Determine step interval and step dependent values
  //
  double hh = timeStep;
  double h_half = hh / 2.0;
  double tempSimTime = *pSimTime;

  //
  // Define local derivaitve and state containers
  //
  std::vector<double *> pDeriv;
  std::vector<double *> pState;

  //
  // Get current states and store values
  //
  GetStates( pState );

  if ( !initComp )
  {
    initComp = true;

    //
    // Allocate container memory with sizes of state vector
    //
    xn.insert( xn.end(), pState.size(), 0.0 );
    k1.insert( k1.end(), pState.size(), 0.0 );
    k2.insert( k2.end(), pState.size(), 0.0 );
    k3.insert( k3.end(), pState.size(), 0.0 );
    k4.insert( k4.end(), pState.size(), 0.0 );
  }

  for( unsigned int idx = 0; idx < pState.size(); ++idx )
  {
     xn[idx] = *pState[idx];
  }

  //
  // Integrate
  // Step 1
  //
  UpdateDerivatives();
  GetDerivatives( pDeriv );

  for( unsigned int idx = 0; idx < pDeriv.size(); ++idx )
  {
    k1[idx] = *pDeriv[idx] * hh;

    //
    // Compute states for next step while we are here
    //
    *pState[idx] = xn[idx] + k1[idx] / 2.0;
  }

  // 
  // Advance clock half step for Stage 2 and Stage 3
  //
  *pSimTime += h_half;

  //
  // Step 2
  // Apply state step and get new derivatives
  //
  SetStates(pState);
  UpdateDerivatives();
  GetDerivatives(pDeriv);

  for( unsigned int idx = 0; idx < pDeriv.size(); ++idx )
  {
    k2[idx] = *pDeriv[idx] * hh;

    //
    // Compute states for next step while we are here
    //
    *pState[idx] = xn[idx] + k2[idx]/2.0;
  }

  //
  // Step 3
  // Apply state step and get new derivatives
  //
  SetStates(pState);
  UpdateDerivatives();
  GetDerivatives(pDeriv);

  for(unsigned int idx = 0; idx < pDeriv.size(); ++idx)
  {
    k3[idx] = *pDeriv[idx]*hh;

    //
    // Compute states for next step while we are here
    //
    *pState[idx] = xn[idx] + k3[idx];
  }

  //
  // Advance clock another half step (for a complete step) for Stage 4
  //
  *pSimTime += h_half;

  //
  // Step 4
  // Apply state step and get new derivatives
  //
  SetStates(pState);
  UpdateDerivatives();
  GetDerivatives(pDeriv);

  for(unsigned int idx = 0; idx < pDeriv.size(); ++idx)
  {
    k4[idx] = *pDeriv[idx]*hh;

    //
    // Compute states
    //
    *pState[idx] = xn[idx] + k1[idx]/6.0 + k2[idx]/3.0 + k3[idx]/3.0 + 
                                                               k4[idx]/6.0;
  }
  SetStates(pState);

  //
  // Reset clock for this module
  //
  *pSimTime = tempSimTime;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movsd (%rsi), %xmm0
movsd %xmm0, -0x58(%rbp)
movq 0x38(%rdi), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
xorl %eax, %eax
movq %rax, -0x40(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x50(%rbp)
leaq -0x30(%rbp), %rdi
movq %rax, 0x10(%rdi)
movapd %xmm0, (%rdi)
leaq 0x48(%rbx), %r14
movq %r14, %rsi
callq 0xa818
cmpb $0x0, 0xf0(%rbx)
jne 0xa45e
movb $0x1, 0xf0(%rbx)
leaq 0x78(%rbx), %rdi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
movq 0x80(%rbx), %rsi
sarq $0x3, %rdx
leaq -0x60(%rbp), %rcx
movq $0x0, (%rcx)
callq 0xaa46
leaq 0x90(%rbx), %rdi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
movq 0x98(%rbx), %rsi
sarq $0x3, %rdx
leaq -0x60(%rbp), %rcx
movq $0x0, (%rcx)
callq 0xaa46
leaq 0xa8(%rbx), %rdi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
movq 0xb0(%rbx), %rsi
sarq $0x3, %rdx
leaq -0x60(%rbp), %rcx
movq $0x0, (%rcx)
callq 0xaa46
leaq 0xc0(%rbx), %rdi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
movq 0xc8(%rbx), %rsi
sarq $0x3, %rdx
leaq -0x60(%rbp), %rcx
movq $0x0, (%rcx)
callq 0xaa46
leaq 0xd8(%rbx), %rdi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
movq 0xe0(%rbx), %rsi
sarq $0x3, %rdx
leaq -0x60(%rbp), %rcx
movq $0x0, (%rcx)
callq 0xaa46
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
je 0xa48c
sarq $0x3, %rcx
movq 0x78(%rbx), %rdx
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
movsd (%rdi), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0xa475
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq 0x60(%rbx), %r15
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xa818
movsd 0xbcbb(%rip), %xmm3     # 0x16168
movsd -0x58(%rbp), %xmm2
mulsd %xmm2, %xmm3
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rax
subq %rcx, %rdx
je 0xa512
sarq $0x3, %rdx
movq 0x78(%rbx), %rsi
movq 0x90(%rbx), %rdi
xorl %r8d, %r8d
movsd 0xbc87(%rip), %xmm0     # 0x16168
movq (%rcx,%r8,8), %r9
movsd (%r9), %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, (%rdi,%r8,8)
mulsd %xmm0, %xmm1
addsd (%rsi,%r8,8), %xmm1
movq (%rax,%r8,8), %r9
movsd %xmm1, (%r9)
incq %r8
movl %r8d, %r9d
cmpq %r9, %rdx
ja 0xa4e1
movq 0x38(%rbx), %rcx
movsd (%rcx), %xmm0
movsd %xmm3, -0x70(%rbp)
addsd %xmm3, %xmm0
movsd %xmm0, (%rcx)
movq -0x28(%rbp), %rcx
subq %rax, %rcx
je 0xa553
sarq $0x3, %rcx
movq (%r14), %rdx
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
movsd (%rdi), %xmm0
movq (%rdx,%rsi,8), %rdi
movsd %xmm0, (%rdi)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0xa539
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xa818
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rax
subq %rcx, %rdx
movsd -0x58(%rbp), %xmm2
je 0xa5c9
sarq $0x3, %rdx
movq 0x78(%rbx), %rsi
movq 0xa8(%rbx), %rdi
xorl %r8d, %r8d
movsd 0xbbd0(%rip), %xmm0     # 0x16168
movq (%rcx,%r8,8), %r9
movsd (%r9), %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, (%rdi,%r8,8)
mulsd %xmm0, %xmm1
addsd (%rsi,%r8,8), %xmm1
movq (%rax,%r8,8), %r9
movsd %xmm1, (%r9)
incq %r8
movl %r8d, %r9d
cmpq %r9, %rdx
ja 0xa598
movq -0x28(%rbp), %rcx
subq %rax, %rcx
je 0xa5f5
sarq $0x3, %rcx
movq (%r14), %rdx
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
movsd (%rdi), %xmm0
movq (%rdx,%rsi,8), %rdi
movsd %xmm0, (%rdi)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0xa5db
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xa818
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rax
subq %rcx, %rdx
movsd -0x58(%rbp), %xmm1
movsd -0x70(%rbp), %xmm2
je 0xa664
sarq $0x3, %rdx
movq 0x78(%rbx), %rsi
movq 0xc0(%rbx), %rdi
xorl %r8d, %r8d
movq (%rcx,%r8,8), %r9
movsd (%r9), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rdi,%r8,8)
addsd (%rsi,%r8,8), %xmm0
movq (%rax,%r8,8), %r9
movsd %xmm0, (%r9)
incq %r8
movl %r8d, %r9d
cmpq %r9, %rdx
ja 0xa637
movq 0x38(%rbx), %rcx
addsd (%rcx), %xmm2
movsd %xmm2, (%rcx)
movq -0x28(%rbp), %rcx
subq %rax, %rcx
je 0xa69c
sarq $0x3, %rcx
movq (%r14), %rdx
xorl %esi, %esi
movq (%rax,%rsi,8), %rdi
movsd (%rdi), %xmm0
movq (%rdx,%rsi,8), %rdi
movsd %xmm0, (%rdi)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0xa682
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xa818
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rdi
subq %rax, %rcx
movsd -0x58(%rbp), %xmm5
je 0xa75d
sarq $0x3, %rcx
movq 0xd8(%rbx), %rdx
movq 0x78(%rbx), %rsi
movq 0x90(%rbx), %r8
movq 0xa8(%rbx), %r9
movq 0xc0(%rbx), %r10
xorl %r11d, %r11d
movsd 0xbdbe(%rip), %xmm0     # 0x164b8
movsd 0xb91e(%rip), %xmm1     # 0x16020
movq (%rax,%r11,8), %r15
movsd (%r15), %xmm2
mulsd %xmm5, %xmm2
movsd %xmm2, (%rdx,%r11,8)
movsd (%r8,%r11,8), %xmm3
divsd %xmm0, %xmm3
addsd (%rsi,%r11,8), %xmm3
movsd (%r9,%r11,8), %xmm4
divsd %xmm1, %xmm4
addsd %xmm3, %xmm4
movsd (%r10,%r11,8), %xmm3
divsd %xmm1, %xmm3
addsd %xmm4, %xmm3
divsd %xmm0, %xmm2
addsd %xmm3, %xmm2
movq (%rdi,%r11,8), %r15
movsd %xmm2, (%r15)
incq %r11
movl %r11d, %r15d
cmpq %r15, %rcx
ja 0xa702
movq -0x28(%rbp), %rcx
subq %rdi, %rcx
je 0xa798
sarq $0x3, %rcx
movq (%r14), %rax
xorl %edx, %edx
movq (%rdi,%rdx,8), %rsi
movsd (%rsi), %xmm0
movq (%rax,%rdx,8), %rsi
movsd %xmm0, (%rsi)
incq %rdx
movl %edx, %esi
cmpq %rsi, %rcx
ja 0xa76f
movq 0x38(%rbx), %rax
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0xa7aa
movq 0x38(%rbx), %rcx
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rcx)
testq %rdi, %rdi
je 0xa7ba
movq -0x20(%rbp), %rsi
subq %rdi, %rsi
callq 0x31a0
movq -0x50(%rbp), %rax
testq %rax, %rax
je 0xa7ce
movq -0x40(%rbp), %rsi
subq %rax, %rsi
movq %rax, %rdi
callq 0x31a0
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa7e3
jmp 0xa7e3
jmp 0xa7e3
jmp 0xa7e3
jmp 0xa7e3
movq %rax, %rbx
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0xa7fb
movq -0x20(%rbp), %rsi
subq %rdi, %rsi
callq 0x31a0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0xa810
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x31a0
movq %rbx, %rdi
callq 0x32d0