// File: /workspace/github_c_makefile_star2_O2/esheldon[P]xshear/src/cosmo.c
// Function: gauleg
void gauleg(double x1, double x2, int npts, double* x, double* w) {
	int i, j, m;
	double xm, xl, z1, z, p1, p2, p3, pp=0, EPS, abszdiff;

	EPS = 4.e-11;

	m = (npts + 1)/2;

	xm = (x1 + x2)/2.0;
	xl = (x2 - x1)/2.0;
	z1 = 0.0;

	for (i=1; i<= m; ++i) 
	{

		z=cos( M_PI*(i-0.25)/(npts+.5) );

		abszdiff = fabs(z-z1);

		while (abszdiff > EPS) 
		{
			p1 = 1.0;
			p2 = 0.0;
			for (j=1; j <= npts;++j)
			{
				p3 = p2;
				p2 = p1;
				p1 = ( (2.0*j - 1.0)*z*p2 - (j-1.0)*p3 )/j;
			}
			pp = npts*(z*p1 - p2)/(z*z -1.);
			z1=z;
			z=z1 - p1/pp;

			abszdiff = fabs(z-z1);

		}

		x[i-1] = xm - xl*z;
		x[npts+1-i-1] = xm + xl*z;
		w[i-1] = 2.0*xl/( (1.-z*z)*pp*pp );
		w[npts+1-i-1] = w[i-1];


	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
movq %rsi, %r14
leal 0x1(%rdi), %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movapd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd 0x5fca(%rip), %xmm3     # 0x9070
mulsd %xmm3, %xmm2
movsd %xmm2, 0x10(%rsp)
subsd %xmm0, %xmm1
mulsd %xmm3, %xmm1
cvtsi2sd %edi, %xmm6
addsd %xmm6, %xmm3
movsd %xmm3, 0x8(%rsp)
movapd 0x5fe2(%rip), %xmm0     # 0x90b0
xorpd %xmm1, %xmm0
movapd %xmm0, 0x40(%rsp)
movapd %xmm1, 0x50(%rsp)
addsd %xmm1, %xmm1
movapd %xmm1, 0x30(%rsp)
xorl %ebp, %ebp
testl %edi, %edi
movq %rdi, 0x18(%rsp)
cmovgl %edi, %ebp
movslq %eax, %r12
xorpd %xmm3, %xmm3
pushq $0x1
popq %r13
pushq $0x1
popq %r15
xorpd %xmm4, %xmm4
movsd %xmm6, (%rsp)
cmpq %r12, %r13
jg 0x328b
cvtsi2sd %r13d, %xmm0
addsd 0x6046(%rip), %xmm0     # 0x9168
mulsd 0x5f1e(%rip), %xmm0     # 0x9048
divsd 0x8(%rsp), %xmm0
movsd %xmm4, 0x28(%rsp)
movsd %xmm3, 0x20(%rsp)
callq 0x2140
movsd 0x20(%rsp), %xmm3
movsd 0x28(%rsp), %xmm4
movsd 0x5ee2(%rip), %xmm10    # 0x9038
movsd 0x5ec1(%rip), %xmm9     # 0x9020
movsd 0x6008(%rip), %xmm8     # 0x9170
movapd 0x5f50(%rip), %xmm7     # 0x90c0
movsd (%rsp), %xmm6
movapd %xmm0, %xmm1
subsd %xmm3, %xmm1
andpd %xmm7, %xmm1
ucomisd %xmm8, %xmm1
jbe 0x321f
xorpd %xmm3, %xmm3
movl %ebp, %eax
movapd %xmm9, %xmm4
movapd %xmm9, %xmm2
movl %r15d, %ecx
movapd %xmm4, %xmm1
subl $0x1, %eax
jb 0x31dd
movapd %xmm2, %xmm4
addsd %xmm2, %xmm4
addsd %xmm10, %xmm4
leal -0x1(%rcx), %edx
cvtsi2sd %edx, %xmm5
mulsd %xmm0, %xmm4
mulsd %xmm5, %xmm3
mulsd %xmm1, %xmm4
subsd %xmm3, %xmm4
divsd %xmm2, %xmm4
addsd %xmm9, %xmm2
incl %ecx
movapd %xmm1, %xmm3
jmp 0x319f
movapd %xmm0, %xmm4
mulsd %xmm1, %xmm4
subsd %xmm3, %xmm4
mulsd %xmm6, %xmm4
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm10, %xmm2
divsd %xmm2, %xmm4
divsd %xmm4, %xmm1
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
movapd %xmm0, %xmm3
movapd %xmm2, %xmm0
jmp 0x317d
movapd 0x40(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm2
addsd %xmm2, %xmm1
movsd %xmm1, -0x8(%r14,%r13,8)
movapd 0x50(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
movq 0x18(%rsp), %rax
subl %r13d, %eax
cltq
movsd %xmm1, (%r14,%rax,8)
mulsd %xmm0, %xmm0
movapd %xmm9, %xmm1
subsd %xmm0, %xmm1
mulsd %xmm4, %xmm1
mulsd %xmm4, %xmm1
movapd 0x30(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbx,%r13,8)
movsd %xmm0, (%rbx,%rax,8)
incq %r13
jmp 0x310c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq