// File: /workspace/github_c_makefile_star2_O1/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 0x1a14
cvtsi2sd %esi, %xmm0
movsd %xmm0, 0x20(%rsp)
xorl %eax, %eax
movl $0x1, %ecx
movsd 0x17e6(%rip), %xmm5     # 0x3010
movsd 0x17e6(%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 0x19eb
xorl %r14d, %r14d
movl %esi, %eax
subl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x20(%rsp), %xmm0
movsd 0x1790(%rip), %xmm1     # 0x3008
subsd %xmm0, %xmm1
movl $0x10, %eax
movsd 0x8(%rbp,%rax), %xmm3
movsd 0x8(%r12,%rax), %xmm2
movapd %xmm3, %xmm4
subsd %xmm2, %xmm4
ucomisd %xmm5, %xmm4
jbe 0x18a6
leaq (%r12,%rax), %rcx
addq $0x8, %rcx
jmp 0x18bc
subsd %xmm3, %xmm2
ucomisd %xmm5, %xmm2
jbe 0x18c4
leaq (%rax,%rbp), %rcx
addq $0x8, %rcx
movapd %xmm3, %xmm2
addsd %xmm6, %xmm2
movsd %xmm2, (%rcx)
leaq (%rax,%rbp), %rcx
leaq (%r12,%rax), %rdx
movsd 0x8(%rdx), %xmm2
mulsd %xmm1, %xmm2
movsd 0x8(%rcx), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x30(%rsp,%rax)
xorps %xmm2, %xmm2
cvtsi2sdl (%rcx), %xmm2
xorps %xmm3, %xmm3
cvtsi2sdl (%rdx), %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 0x1881
xorps %xmm2, %xmm2
cvtsi2sdl 0x4(%rbp), %xmm2
xorps %xmm3, %xmm3
cvtsi2sdl 0x4(%r12), %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %eax
movl %eax, 0x2c(%rsp)
xorps %xmm2, %xmm2
cvtsi2sdl 0x8(%rbp), %xmm2
xorps %xmm3, %xmm3
cvtsi2sdl 0x8(%r12), %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm0, %xmm2
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %eax
movl %eax, 0x30(%rsp)
leaq 0x3813(%rip), %rax      # 0x5180
movq (%rax), %rdi
xorl %ebx, %ebx
testl %r13d, %r13d
sete %bl
leaq 0x3821(%rip), %r15      # 0x51a0
movq (%r15,%rbx,8), %rsi
callq 0x1040
movq 0x3771(%rip), %rsi      # 0x5100
movq (%r15,%rbx,8), %rdx
leaq 0x28(%rsp), %rdi
callq 0x1acc
leaq 0x37dc(%rip), %rax      # 0x5180
movq (%rax), %rdi
movq (%r15,%rbx,8), %rsi
callq 0x1120
leaq 0x37c9(%rip), %rax      # 0x5180
movq (%rax), %rdi
movl %r13d, %eax
movq (%r15,%rax,8), %rsi
callq 0x10e0
movsd 0x164a(%rip), %xmm6     # 0x3018
movsd 0x163a(%rip), %xmm5     # 0x3010
incl %r14d
movl %ebx, %r13d
movl 0x4(%rsp), %esi
cmpl %esi, %r14d
jne 0x185e
jmp 0x19ee
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 0x183e
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq