// File: /workspace/github_cpp_makefile_star2_O1/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, -0x70(%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 0xa8ca
cmpb $0x0, 0xf0(%rbx)
jne 0xa512
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 0xaaea
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 0xaaea
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 0xaaea
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 0xaaea
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 0xaaea
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
je 0xa540
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 0xa529
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq 0x60(%rbx), %r15
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xa8ca
movsd 0xbc07(%rip), %xmm3     # 0x16168
movsd -0x58(%rbp), %xmm2
mulsd %xmm2, %xmm3
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
je 0xa5c6
sarq $0x3, %rcx
movq 0x78(%rbx), %rdx
movq 0x90(%rbx), %rsi
movq -0x30(%rbp), %rdi
xorl %r8d, %r8d
movsd 0xbbd3(%rip), %xmm0     # 0x16168
movq (%rax,%r8,8), %r9
movsd (%r9), %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, (%rsi,%r8,8)
mulsd %xmm0, %xmm1
addsd (%rdx,%r8,8), %xmm1
movq (%rdi,%r8,8), %r9
movsd %xmm1, (%r9)
incq %r8
movl %r8d, %r9d
cmpq %r9, %rcx
ja 0xa595
movq 0x38(%rbx), %rax
movsd (%rax), %xmm0
movsd %xmm3, -0x68(%rbp)
addsd %xmm3, %xmm0
movsd %xmm0, (%rax)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
je 0xa60b
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 0xa5f1
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xa8ca
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
movsd -0x58(%rbp), %xmm2
je 0xa681
sarq $0x3, %rcx
movq 0x78(%rbx), %rdx
movq 0xa8(%rbx), %rsi
movq -0x30(%rbp), %rdi
xorl %r8d, %r8d
movsd 0xbb18(%rip), %xmm0     # 0x16168
movq (%rax,%r8,8), %r9
movsd (%r9), %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, (%rsi,%r8,8)
mulsd %xmm0, %xmm1
addsd (%rdx,%r8,8), %xmm1
movq (%rdi,%r8,8), %r9
movsd %xmm1, (%r9)
incq %r8
movl %r8d, %r9d
cmpq %r9, %rcx
ja 0xa650
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
je 0xa6b1
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 0xa697
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xa8ca
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
movsd -0x58(%rbp), %xmm1
movsd -0x68(%rbp), %xmm2
je 0xa720
sarq $0x3, %rcx
movq 0x78(%rbx), %rdx
movq 0xc0(%rbx), %rsi
movq -0x30(%rbp), %rdi
xorl %r8d, %r8d
movq (%rax,%r8,8), %r9
movsd (%r9), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsi,%r8,8)
addsd (%rdx,%r8,8), %xmm0
movq (%rdi,%r8,8), %r9
movsd %xmm0, (%r9)
incq %r8
movl %r8d, %r9d
cmpq %r9, %rcx
ja 0xa6f3
movq 0x38(%rbx), %rax
addsd (%rax), %xmm2
movsd %xmm2, (%rax)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
je 0xa75c
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 0xa742
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0xa8ca
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
movsd -0x58(%rbp), %xmm5
je 0xa81d
sarq $0x3, %rcx
movq 0xd8(%rbx), %rdx
movq 0x78(%rbx), %rsi
movq 0x90(%rbx), %rdi
movq 0xa8(%rbx), %r8
movq 0xc0(%rbx), %r9
movq -0x30(%rbp), %r10
xorl %r11d, %r11d
movsd 0xbcfe(%rip), %xmm0     # 0x164b8
movsd 0xb85e(%rip), %xmm1     # 0x16020
movq (%rax,%r11,8), %r15
movsd (%r15), %xmm2
mulsd %xmm5, %xmm2
movsd %xmm2, (%rdx,%r11,8)
movsd (%rdi,%r11,8), %xmm3
divsd %xmm0, %xmm3
addsd (%rsi,%r11,8), %xmm3
movsd (%r8,%r11,8), %xmm4
divsd %xmm1, %xmm4
addsd %xmm3, %xmm4
movsd (%r9,%r11,8), %xmm3
divsd %xmm1, %xmm3
addsd %xmm4, %xmm3
divsd %xmm0, %xmm2
addsd %xmm3, %xmm2
movq (%r10,%r11,8), %r15
movsd %xmm2, (%r15)
incq %r11
movl %r11d, %r15d
cmpq %r15, %rcx
ja 0xa7c2
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rax
subq %rdi, %rax
je 0xa84d
sarq $0x3, %rax
movq (%r14), %rcx
xorl %edx, %edx
movq (%rdi,%rdx,8), %rsi
movsd (%rsi), %xmm0
movq (%rcx,%rdx,8), %rsi
movsd %xmm0, (%rsi)
incq %rdx
movl %edx, %esi
cmpq %rsi, %rax
ja 0xa833
movq 0x38(%rbx), %rax
movsd -0x70(%rbp), %xmm0
movsd %xmm0, (%rax)
testq %rdi, %rdi
je 0xa86b
movq -0x20(%rbp), %rsi
subq %rdi, %rsi
callq 0x31a0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0xa880
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x31a0
addq $0x58, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa895
jmp 0xa895
jmp 0xa895
jmp 0xa895
jmp 0xa895
movq %rax, %rbx
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0xa8ad
movq -0x20(%rbp), %rsi
subq %rdi, %rsi
callq 0x31a0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0xa8c2
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x31a0
movq %rbx, %rdi
callq 0x32d0