// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x60, %rsp
movq %rdi, %rbx
movsd (%rsi), %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x38(%rdi), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x68(%rbp)
andq $0x0, -0x40(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0x50(%rbp)
leaq -0x30(%rbp), %rdi
movapd %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x48(%rbx), %rsi
callq 0xa344
cmpb $0x0, 0xf0(%rbx)
jne 0xa04e
movb $0x1, 0xf0(%rbx)
leaq 0x78(%rbx), %rdi
movq 0x80(%rbx), %rsi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
sarq $0x3, %rdx
leaq -0x58(%rbp), %rcx
andq $0x0, (%rcx)
callq 0xa43c
leaq 0x90(%rbx), %rdi
movq 0x98(%rbx), %rsi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
sarq $0x3, %rdx
leaq -0x58(%rbp), %rcx
andq $0x0, (%rcx)
callq 0xa43c
leaq 0xa8(%rbx), %rdi
movq 0xb0(%rbx), %rsi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
sarq $0x3, %rdx
leaq -0x58(%rbp), %rcx
andq $0x0, (%rcx)
callq 0xa43c
leaq 0xc0(%rbx), %rdi
movq 0xc8(%rbx), %rsi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
sarq $0x3, %rdx
leaq -0x58(%rbp), %rcx
andq $0x0, (%rcx)
callq 0xa43c
leaq 0xd8(%rbx), %rdi
movq 0xe0(%rbx), %rsi
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
sarq $0x3, %rdx
leaq -0x58(%rbp), %rcx
andq $0x0, (%rcx)
callq 0xa43c
movsd 0xb112(%rip), %xmm0     # 0x15168
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq 0x78(%rbx), %rdx
xorl %esi, %esi
movl %esi, %esi
cmpq %rsi, %rcx
jbe 0xa08d
movq (%rax,%rsi,8), %rdi
movsd (%rdi), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incl %esi
jmp 0xa075
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq 0x60(%rbx), %r14
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0xa344
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq 0x78(%rbx), %rdx
movq 0x90(%rbx), %rsi
xorl %r8d, %r8d
movq -0x30(%rbp), %rdi
movsd -0x38(%rbp), %xmm1
movl %r8d, %r8d
cmpq %r8, %rcx
jbe 0xa103
movq (%rax,%r8,8), %r9
movsd (%r9), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsi,%r8,8)
mulsd 0xb079(%rip), %xmm0     # 0x15168
addsd (%rdx,%r8,8), %xmm0
movq (%rdi,%r8,8), %r9
movsd %xmm0, (%r9)
incl %r8d
jmp 0xa0cc
movq 0x38(%rbx), %rax
movsd (%rax), %xmm0
addsd -0x60(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x9eba
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0xa344
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq 0x78(%rbx), %rdx
movq 0xa8(%rbx), %rsi
xorl %r8d, %r8d
movq -0x30(%rbp), %rdi
movsd -0x38(%rbp), %xmm1
movsd 0xb005(%rip), %xmm2     # 0x15168
movl %r8d, %r8d
cmpq %r8, %rcx
jbe 0xa196
movq (%rax,%r8,8), %r9
movsd (%r9), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rsi,%r8,8)
mulsd %xmm2, %xmm0
addsd (%rdx,%r8,8), %xmm0
movq (%rdi,%r8,8), %r9
movsd %xmm0, (%r9)
incl %r8d
jmp 0xa163
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x9eba
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0xa344
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq 0x78(%rbx), %rdx
movq 0xc0(%rbx), %rsi
xorl %r8d, %r8d
movq -0x30(%rbp), %rdi
movsd -0x38(%rbp), %xmm1
movl %r8d, %r8d
cmpq %r8, %rcx
jbe 0xa20c
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)
incl %r8d
jmp 0xa1dd
movq 0x38(%rbx), %rax
movsd -0x60(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
leaq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x9eba
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x18(%rax)
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0xa344
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq 0xd8(%rbx), %rdx
movq 0x78(%rbx), %rsi
movq 0x90(%rbx), %rdi
movq 0xa8(%rbx), %r8
movq 0xc0(%rbx), %r9
xorl %r11d, %r11d
movq -0x30(%rbp), %r10
movsd 0xb23c(%rip), %xmm0     # 0x154b8
movsd 0xad9c(%rip), %xmm1     # 0x15020
movsd -0x38(%rbp), %xmm5
movl %r11d, %r11d
cmpq %r11, %rcx
jbe 0xa2e6
movq (%rax,%r11,8), %r14
movsd (%r14), %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), %r14
movsd %xmm2, (%r14)
incl %r11d
jmp 0xa289
leaq -0x30(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9eba
movq 0x38(%rbx), %rax
movsd -0x68(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %r14, %rdi
callq 0xa46a
leaq -0x50(%rbp), %rdi
callq 0xa46a
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0xa326
jmp 0xa326
jmp 0xa326
jmp 0xa326
jmp 0xa326
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
callq 0xa46a
leaq -0x50(%rbp), %rdi
callq 0xa46a
movq %rbx, %rdi
callq 0x3320
nop