// File: /workspace/github_c_makefile_star2_O3/veltzer[P]xmeltdown/src/stickread.c
// Function: Interpolate
void Interpolate(Skeleton** skellist, int steps)
{
	RayPtr to, from, tweenray;
	int bonesize=sizeof(Ray);
	Skeleton* skel1, *skel2;
	int stepctr, skelctr, bone;
	Skeleton tween1;
	// Skeleton	tween2;
	double factor;
	// Skeleton	*oldskel;
	Skeleton* newskel=NULL;
	/* Skeleton *tempskel; */
	int curbuf=0;
	int flag1=1;
	int flag2=1;
	int flag3=1;
	int flag4=0;

	newskel=&tween1;
	// oldskel = &tween2;
	for (skelctr=0; skellist[skelctr+1] != NULL; skelctr++) {
		skel1=skellist[skelctr];
		skel2=skellist[skelctr+1];

		tween1.headradius=skel1->headradius;
		// tween2.headradius = skel2->headradius;
		for (stepctr=0; stepctr < steps; stepctr++) {
			factor=(double) (steps-stepctr)/(double) steps;
			for (bone=0; bone < 11; bone++) {
				from=(RayPtr)((long) &(skel1->torso)+(long) (bone*bonesize));
				to=(RayPtr) ((long) &(skel2->torso)+(long) (bone*bonesize));
				tweenray=(RayPtr) ((long) &(newskel->torso)+(long) (bone*bonesize));
/*
** Never rotate through an angle > PI. I.e., take the shortest path.
*/
				if ((from->t-to->t) > M_PI)
					to->t+=2*M_PI;
				else if ((to->t-from->t) > M_PI)
					from->t+=2*M_PI;
				tweenray->t=(from->t*factor+to->t*(1.0-factor));
				tweenray->r=(from->r*factor+to->r*(1.0-factor));
			}
			newskel->waistx=skel1->waistx*factor+
					 skel2->waistx*(1.0-factor);
			newskel->waisty=skel1->waisty*factor+
					 skel2->waisty*(1.0-factor);
/*
** Real double-buffering...clear the hidden window, draw the skeleton
** in it, bring it to the top.
*/
			if (flag1 == 1) XClearWindow(dpy, buffer[!curbuf]);
			if (!flag2 && flag4) XRaiseWindow(dpy, buffer[!curbuf]);
			if (!flag2 && !flag4) {
				XMapWindow(dpy, buffer[!curbuf]);
				XUnmapWindow(dpy, buffer[curbuf]);
			}
			DrawSkel(newskel, unset_gc, buffer[!curbuf]);
			if (flag2 && flag4) XRaiseWindow(dpy, buffer[!curbuf]);
			if (flag2 && !flag4) {
				XMapWindow(dpy, buffer[!curbuf]);
				XUnmapWindow(dpy, buffer[curbuf]);
			}
			if (flag3) curbuf=!curbuf;
/*
 * Simulated double-buffering: Keep track of previous skeleton, and undraw
 * it just before drawing the new one.
 *
 * DrawSkel(newskel, neg_gc);
 *
 * if (oldskel != NULL)
 * DrawSkel(oldskel, neg_gc);
 *
 * DrawSkel(newskel, unset_gc);
 *
 * tempskel = oldskel;
 * oldskel = newskel;
 * newskel = tempskel;
 */
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq 0x8(%rdi), %r12
testq %r12, %r12
je 0x19da
cvtsi2sd %esi, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %eax, %eax
movl $0x1, %ecx
movsd 0x17fa(%rip), %xmm5     # 0x3010
movsd 0x17fa(%rip), %xmm6     # 0x3018
xorl %r13d, %r13d
movq %rdi, 0x8(%rsp)
movl %esi, 0x4(%rsp)
movq %rcx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq (%rdi,%rax,8), %rbp
movl (%rbp), %eax
movl %eax, 0x28(%rsp)
testl %esi, %esi
jle 0x19b1
xorl %r14d, %r14d
movl %esi, %eax
subl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x20(%rsp), %xmm0
movsd 0x17a4(%rip), %xmm1     # 0x3008
subsd %xmm0, %xmm1
movl $0x10, %eax
movsd 0x8(%rbp,%rax), %xmm2
movsd 0x8(%r12,%rax), %xmm3
movapd %xmm2, %xmm4
subsd %xmm3, %xmm4
ucomisd %xmm5, %xmm4
jbe 0x189b
addsd %xmm6, %xmm3
movsd %xmm3, 0x8(%r12,%rax)
movsd 0x8(%rbp,%rax), %xmm2
jmp 0x18ba
movapd %xmm3, %xmm4
subsd %xmm2, %xmm4
ucomisd %xmm5, %xmm4
jbe 0x18ba
addsd %xmm6, %xmm2
movsd %xmm2, 0x8(%rbp,%rax)
movsd 0x8(%r12,%rax), %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
movsd %xmm2, 0x30(%rsp,%rax)
xorps %xmm2, %xmm2
cvtsi2sdl (%rbp,%rax), %xmm2
xorps %xmm3, %xmm3
cvtsi2sdl (%r12,%rax), %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %ecx
movl %ecx, 0x28(%rsp,%rax)
addq $0x20, %rax
cmpq $0x170, %rax            # imm = 0x170
jne 0x186d
cvtdq2pd 0x4(%rbp), %xmm2
cvtdq2pd 0x4(%r12), %xmm3
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm3, %xmm1
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm2, %xmm0
addpd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm0
movlpd %xmm0, 0x2c(%rsp)
leaq 0x384d(%rip), %rax      # 0x5180
movq (%rax), %rdi
xorl %ebx, %ebx
testl %r13d, %r13d
sete %bl
leaq 0x385b(%rip), %r15      # 0x51a0
movq (%r15,%rbx,8), %rsi
callq 0x1040
movq 0x37ab(%rip), %rsi      # 0x5100
movq (%r15,%rbx,8), %rdx
leaq 0x28(%rsp), %rdi
callq 0x1a90
leaq 0x3816(%rip), %rax      # 0x5180
movq (%rax), %rdi
movq (%r15,%rbx,8), %rsi
callq 0x1120
leaq 0x3803(%rip), %rax      # 0x5180
movq (%rax), %rdi
movl %r13d, %eax
movq (%r15,%rax,8), %rsi
callq 0x10e0
movsd 0x1684(%rip), %xmm6     # 0x3018
movsd 0x1674(%rip), %xmm5     # 0x3010
incl %r14d
movl %ebx, %r13d
movl 0x4(%rsp), %esi
cmpl %esi, %r14d
jne 0x184a
jmp 0x19b4
movl %r13d, %ebx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rcx
movq 0x8(%rdi,%rcx,8), %r12
incq %rcx
movq 0x18(%rsp), %rax
incq %rax
movl %ebx, %r13d
testq %r12, %r12
jne 0x182a
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq