// File: /workspace/github_cpp_makefile_star2_O1/rachit31[P]CubeSatADCS/propagateANDupdate.cpp
// Function: quatProp(double const (&) [3], double, double (&) [4])
void quatProp(const double (&wbi_B)[3], const double dtGyro, double (&q_BI)[4])
 {
	 double wmag = sqrt(wbi_B[0]*wbi_B[0]+wbi_B[1]*wbi_B[1]+wbi_B[2]*wbi_B[2]);
		
	 double s = sin(0.5*wmag*dtGyro);
     double c = cos(0.5*wmag*dtGyro);
		
     double psi[3];
		
     psi[0] = s*wbi_B[0]/wmag;
     psi[1] = s*wbi_B[1]/wmag;
     psi[2] = s*wbi_B[2]/wmag;
		
     double qnew_BI[4];
		
     qnew_BI[0] = c*q_BI[0] - psi[0]*q_BI[1] - psi[1]*q_BI[2] - psi[2]*q_BI[3];
     qnew_BI[1] = c*q_BI[1] + psi[0]*q_BI[0] - psi[1]*q_BI[3] + psi[2]*q_BI[2];
     qnew_BI[2] = c*q_BI[2] + psi[1]*q_BI[0] + psi[0]*q_BI[3] - psi[2]*q_BI[1];
     qnew_BI[3] = c*q_BI[3] - psi[0]*q_BI[2] + psi[1]*q_BI[1] + psi[2]*q_BI[0];
		
     double qmag = sqrt(qnew_BI[0]*qnew_BI[0]+qnew_BI[1]*qnew_BI[1]+qnew_BI[2]*qnew_BI[2]+qnew_BI[3]*qnew_BI[3]);
		
     q_BI[0] = qnew_BI[0]/qmag;
     q_BI[1] = qnew_BI[1]/qmag;
     q_BI[2] = qnew_BI[2]/qmag;
     q_BI[3] = qnew_BI[3]/qmag;
 }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rsi, %rbx
movapd %xmm0, %xmm2
movq %rdi, %r14
movsd (%rdi), %xmm1
movsd 0x8(%rdi), %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rdi), %xmm0
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x719c
sqrtsd %xmm0, %xmm0
jmp 0x71ab
movsd %xmm2, -0x18(%rbp)
callq 0x21f0
movsd -0x18(%rbp), %xmm2
movsd %xmm0, -0x28(%rbp)
movsd 0x1258(%rip), %xmm1     # 0x8410
mulsd %xmm0, %xmm1
mulsd %xmm2, %xmm1
movsd %xmm1, -0x20(%rbp)
movapd %xmm1, %xmm0
callq 0x2090
movsd %xmm0, -0x18(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x23e0
movsd (%r14), %xmm10
movsd -0x18(%rbp), %xmm11
mulsd %xmm11, %xmm10
movsd -0x28(%rbp), %xmm2
divsd %xmm2, %xmm10
movsd 0x8(%r14), %xmm1
mulsd %xmm11, %xmm1
divsd %xmm2, %xmm1
mulsd 0x10(%r14), %xmm11
divsd %xmm2, %xmm11
movsd (%rbx), %xmm2
movsd 0x8(%rbx), %xmm3
movapd %xmm1, %xmm5
movapd %xmm0, %xmm4
mulsd %xmm3, %xmm4
movapd %xmm1, %xmm6
movapd %xmm1, %xmm7
movapd %xmm11, %xmm8
mulsd %xmm3, %xmm8
mulsd %xmm3, %xmm1
mulsd %xmm10, %xmm3
movapd %xmm0, %xmm12
mulsd %xmm2, %xmm12
subsd %xmm3, %xmm12
movsd 0x10(%rbx), %xmm3
mulsd %xmm3, %xmm5
subsd %xmm5, %xmm12
movsd 0x18(%rbx), %xmm5
movapd %xmm11, %xmm9
mulsd %xmm5, %xmm9
subsd %xmm9, %xmm12
movapd %xmm10, %xmm9
mulsd %xmm2, %xmm9
addsd %xmm9, %xmm4
mulsd %xmm5, %xmm6
subsd %xmm6, %xmm4
movapd %xmm11, %xmm6
mulsd %xmm3, %xmm6
addsd %xmm4, %xmm6
mulsd %xmm2, %xmm7
movapd %xmm0, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm7, %xmm4
mulsd %xmm10, %xmm3
mulsd %xmm5, %xmm10
addsd %xmm4, %xmm10
subsd %xmm8, %xmm10
mulsd %xmm5, %xmm0
subsd %xmm3, %xmm0
addsd %xmm0, %xmm1
mulsd %xmm2, %xmm11
addsd %xmm1, %xmm11
movapd %xmm6, %xmm0
mulsd %xmm6, %xmm0
movapd %xmm12, %xmm1
mulsd %xmm12, %xmm1
addsd %xmm0, %xmm1
movapd %xmm10, %xmm2
mulsd %xmm10, %xmm2
addsd %xmm1, %xmm2
movsd %xmm11, -0x18(%rbp)
movapd %xmm11, %xmm0
mulsd %xmm11, %xmm0
addsd %xmm2, %xmm0
ucomisd 0x1128(%rip), %xmm0     # 0x8438
jb 0x7318
sqrtsd %xmm0, %xmm0
jmp 0x733f
movsd %xmm10, -0x28(%rbp)
movsd %xmm12, -0x20(%rbp)
movsd %xmm6, -0x30(%rbp)
callq 0x21f0
movsd -0x30(%rbp), %xmm6
movsd -0x20(%rbp), %xmm12
movsd -0x28(%rbp), %xmm10
divsd %xmm0, %xmm12
movsd %xmm12, (%rbx)
divsd %xmm0, %xmm6
movsd %xmm6, 0x8(%rbx)
divsd %xmm0, %xmm10
movsd %xmm10, 0x10(%rbx)
movsd -0x18(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rbx)
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq