// File: /workspace/github_c_makefile_star2_O2/veltzer[P]xmeltdown/src/stickman.c
// Function: HandleMotion
void HandleMotion(XMotionEvent* pevent)
{
	int newx, newy, oldx, oldy;
	double newtheta, totaltheta, newr;
	RayPtr fooray;

	DrawSkel(&bones, set_gc, buffer[0]);
	newx=pevent->x;
	newy=pevent->y;

	oldx=targetray->anchor->x;
	oldy=targetray->anchor->y;
/*
** Spin the ray around its anchor
*/
	if (ButtonDown == 1) {
		if (oldx == newx)
			newx++;
		newtheta=atan((double)(oldy-newy)/(double)(oldx-newx));
		if (oldx > newx) newtheta+=M_PI;
		for (totaltheta=0, fooray=targetray->anchor; fooray; fooray=fooray->anchor) {
			totaltheta+=fooray->t;
		}
		targetray->t=newtheta-totaltheta;
		DrawSkel(&bones, unset_gc, buffer[0]);
		FlashRay (targetray);
	}
	if (ButtonDown == 2) {
		bones.waistx=newx+offsetx;
		bones.waisty=newy+offsety;
		DrawSkel(&bones, unset_gc, buffer[0]);
		DrawSkel(&bones, dotted_gc, buffer[0]);
	}
/*
** Stretch the ray out from its anchor
*/
	if (ButtonDown == 3) {
		newr=FindDistance(newx, newy, targetray->anchor);
		targetray->r=newr;
		DrawSkel(&bones, unset_gc, buffer[0]);
		FlashRay (targetray);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x2d2f(%rip), %rsi      # 0x4248
leaq 0x2de0(%rip), %r14      # 0x4300
movq (%r14), %rdx
leaq 0x2b9e(%rip), %rdi      # 0x40c8
callq 0x17a6
movl 0x40(%rbx), %ecx
movl 0x44(%rbx), %r15d
movl 0x2d24(%rip), %eax      # 0x4260
cmpl $0x1, %eax
jne 0x159e
movq 0x2d20(%rip), %rax      # 0x4268
movq 0x18(%rax), %rax
movl 0x10(%rax), %ebx
movl 0x14(%rax), %eax
xorl %ebp, %ebp
cmpl %ecx, %ebx
sete %bpl
addl %ecx, %ebp
subl %r15d, %eax
cvtsi2sd %eax, %xmm0
movl %ebx, %eax
subl %ebp, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
callq 0x10c0
movapd %xmm0, %xmm1
addsd 0xa88(%rip), %xmm1      # 0x2008
xorpd %xmm2, %xmm2
movq 0x2cdd(%rip), %rax      # 0x4268
movq %rax, %rcx
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
je 0x15a2
addsd 0x8(%rcx), %xmm2
jmp 0x158e
movl %ecx, %ebp
jmp 0x15db
cmpl %ebp, %ebx
jg 0x15aa
movapd %xmm0, %xmm1
subsd %xmm2, %xmm1
movsd %xmm1, 0x8(%rax)
movq 0x2c9e(%rip), %rsi      # 0x4258
movq (%r14), %rdx
leaq 0x2b04(%rip), %rdi      # 0x40c8
callq 0x17a6
movq 0x2c98(%rip), %rdi      # 0x4268
callq 0x1695
movl 0x2c85(%rip), %eax      # 0x4260
cmpl $0x2, %eax
jne 0x162e
movl 0x2c8a(%rip), %eax      # 0x4270
addl %ebp, %eax
movl %eax, 0x2ade(%rip)      # 0x40cc
leaq 0x2ad3(%rip), %rbx      # 0x40c8
movl 0x2c79(%rip), %eax      # 0x4274
addl %r15d, %eax
movl %eax, 0x2acc(%rip)      # 0x40d0
movq 0x2c4d(%rip), %rsi      # 0x4258
movq (%r14), %rdx
movq %rbx, %rdi
callq 0x17a6
movq 0x2c33(%rip), %rsi      # 0x4250
movq (%r14), %rdx
movq %rbx, %rdi
callq 0x17a6
movl 0x2c32(%rip), %eax      # 0x4260
cmpl $0x3, %eax
jne 0x168a
movq 0x2c2e(%rip), %rax      # 0x4268
movq 0x18(%rax), %rcx
subl 0x10(%rcx), %ebp
subl 0x14(%rcx), %r15d
imull %ebp, %ebp
imull %r15d, %r15d
addl %ebp, %r15d
cvtsi2sd %r15, %xmm0
sqrtsd %xmm0, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, (%rax)
movq 0x2bf3(%rip), %rsi      # 0x4258
movq (%r14), %rdx
leaq 0x2a59(%rip), %rdi      # 0x40c8
callq 0x17a6
movq 0x2bed(%rip), %rdi      # 0x4268
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1695
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq