// File: /workspace/github_c_makefile_star2_O2/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
cvtsi2sd %esi, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %eax, %eax
testl %esi, %esi
movl $0x0, %ecx
movl %esi, 0x4(%rsp)
cmovgl %esi, %ecx
movl %ecx, 0x8(%rsp)
movsd 0x192c(%rip), %xmm5     # 0x3010
movsd 0x192c(%rip), %xmm6     # 0x3018
xorl %ebp, %ebp
movq %rdi, 0x10(%rsp)
movq 0x8(%rdi,%rax,8), %r13
testq %r13, %r13
je 0x1881
movq (%rdi,%rax,8), %rbx
incq %rax
movq %rax, 0x18(%rsp)
movl (%rbx), %eax
movl %eax, 0x28(%rsp)
xorl %esi, %esi
cmpl 0x8(%rsp), %esi
je 0x1872
movl 0x4(%rsp), %eax
subl %esi, %eax
cvtsi2sd %eax, %xmm0
divsd 0x20(%rsp), %xmm0
movsd 0x18d1(%rip), %xmm1     # 0x3008
subsd %xmm0, %xmm1
pushq $0x10
popq %rax
cmpq $0x170, %rax            # imm = 0x170
je 0x17d2
movsd 0x8(%rbx,%rax), %xmm2
movsd 0x8(%r13,%rax), %xmm3
movapd %xmm2, %xmm4
subsd %xmm3, %xmm4
ucomisd %xmm5, %xmm4
jbe 0x1778
addsd %xmm6, %xmm3
movsd %xmm3, 0x8(%r13,%rax)
movsd 0x8(%rbx,%rax), %xmm2
jmp 0x1797
movapd %xmm3, %xmm4
subsd %xmm2, %xmm4
ucomisd %xmm5, %xmm4
jbe 0x1797
addsd %xmm6, %xmm2
movsd %xmm2, 0x8(%rbx,%rax)
movsd 0x8(%r13,%rax), %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
movsd %xmm2, 0x30(%rsp,%rax)
cvtsi2sdl (%rbx,%rax), %xmm2
cvtsi2sdl (%r13,%rax), %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %ecx
movl %ecx, 0x28(%rsp,%rax)
addq $0x20, %rax
jmp 0x173e
cvtdq2pd 0x4(%rbx), %xmm2
cvtdq2pd 0x4(%r13), %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 0x397e(%rip), %r12      # 0x5180
movq (%r12), %rdi
xorl %r14d, %r14d
testl %ebp, %ebp
sete %r14b
leaq 0x398a(%rip), %r15      # 0x51a0
movl %esi, 0xc(%rsp)
movq (%r15,%r14,8), %rsi
callq 0x1040
movq 0x38d6(%rip), %rsi      # 0x5100
movq (%r15,%r14,8), %rdx
leaq 0x28(%rsp), %rdi
callq 0x193a
movq (%r12), %rdi
movq (%r15,%r14,8), %rsi
callq 0x1120
movq (%r12), %rdi
movl %ebp, %eax
movq (%r15,%rax,8), %rsi
callq 0x10e0
movl 0xc(%rsp), %esi
movsd 0x17b8(%rip), %xmm6     # 0x3018
movsd 0x17a8(%rip), %xmm5     # 0x3010
incl %esi
movl %r14d, %ebp
jmp 0x1715
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
jmp 0x16f3
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq