// File: /workspace/github_cpp_makefile_star2_O1/intheswim[P]FractalTubes/m3d.cpp
// Function: M3DDrawer::GetMandelColor3(DrawParams&, ShapeParams&, long double, long double, int&, int&)
long M3DDrawer::GetMandelColor3 (struct DrawParams &params, struct ShapeParams &sp,
                                 long double alpha, long double alp, int &mandel, int &fraction)
{
    long double xRadius = params.xRadius;
    
	long double currentRadius;
	double k ;
	double deltaRe = (params.xCenter2 - params.xCenter);
	double deltaIm = (params.yCenter2 - params.yCenter);
	double half_dist = sqrt (deltaRe * deltaRe + deltaIm * deltaIm) / 2;
	double ellipse_half_dist ;
	double horizRadius;
	double xDelta = 0, yDelta = 0, ellipseXCenter, ellipseYCenter;
	double cos_angle = 0.0, sin_angle = 1.0;
	double focus_dist = 2 * sqrt (half_dist * half_dist + params.max_radius * params.max_radius);
	double a = focus_dist / 2;
	double height = params.max_radius; // a always >= than b.
    
	long color = 0;
	long double Re, Im, tRe, tIm;
	long double magic = (sp.alpha_range) * params.steps1 / (params.steps1 + params.steps2);
    
	if (alpha < magic)
    {
		k = pow ((double)POWER_BASE, (double)(POWER_ADD + params.steps1 * alpha / magic));
		currentRadius = xRadius / k;
		horizRadius = currentRadius * a / height;
		ellipse_half_dist = half_dist * currentRadius / params.max_radius;
        
		if (half_dist > 0)
        {
			xDelta = ellipse_half_dist * deltaRe / (2 * half_dist);
			yDelta = ellipse_half_dist * deltaIm / (2 * half_dist);
        }
        
		ellipseXCenter =  params.xCenter + xDelta;
		ellipseYCenter =  params.yCenter + yDelta;
        
		tRe = horizRadius * cos (alp + params.sampleRotation);
		tIm = currentRadius * sin (alp + params.sampleRotation);
        
		if (half_dist > 0)
        {
			cos_angle = deltaRe / (2 *half_dist);
			sin_angle = deltaIm / (2 *half_dist);
            
			Re = tRe * cos_angle - tIm * sin_angle;
			Im = tRe * sin_angle + tIm * cos_angle;
        }
		else
        {
			Re = tRe ;
			Im = tIm ;
        }
        
		Re += ellipseXCenter; //currentParams.xCenter;
		Im += ellipseYCenter; //currentParams.yCenter;
    }
	else
    {
		k = pow ((double)POWER_BASE, (double)(POWER_ADD + params.steps2 * (sp.alpha_range - alpha) / (sp.alpha_range - magic)));
        
		currentRadius = params.xRadius2 / k;
		horizRadius = currentRadius * a / height;
		ellipse_half_dist = half_dist * currentRadius / params.max_radius;
        
		if (half_dist > 0)
        {
			xDelta = ellipse_half_dist * deltaRe / (2 * half_dist);
			yDelta = ellipse_half_dist * deltaIm / (2 * half_dist);
        }
        
		ellipseXCenter =  params.xCenter2 - xDelta;
		ellipseYCenter =  params.yCenter2 - yDelta;
        
		tRe = horizRadius * cos (alp + params.sampleRotation);
		tIm = currentRadius * sin (alp + params.sampleRotation);
        
		if (half_dist > 0)
        {
			cos_angle = deltaRe / (2 * half_dist);
			sin_angle = deltaIm / (2 * half_dist);
            
			Re = tRe * cos_angle - tIm * sin_angle;
			Im = tRe * sin_angle + tIm * cos_angle;
        }
		else
        {
			Re = tRe ;
			Im = tIm ;
        }
        
		Re += ellipseXCenter; //currentParams.xCenter;
		Im += ellipseYCenter; //currentParams.yCenter;
    }
    
	if (params.juliaSet)
    {
		color = Julia (params.juliaRe, params.juliaIm, Re, Im, mandel, fraction);
    }
	else
    {
		color = Strange(Re, Im, mandel, fraction);
    }
    
	return color;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b0, %rsp            # imm = 0x1B0
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r15
fldt 0x1f0(%rsp)
fstpt 0x90(%rsp)
fldt 0x1e0(%rsp)
fldt 0x70(%rsi)
fstpt 0x78(%rsp)
fldt 0x80(%rsi)
fldt 0x50(%rsi)
fsubrp %st, %st(1)
fstpl 0x1a0(%rsp)
movsd 0x1a0(%rsp), %xmm0
fldt 0x90(%rsi)
fldt 0x60(%rsi)
fsubrp %st, %st(1)
fstpl 0x1a8(%rsp)
movsd 0x1a8(%rsp), %xmm1
movsd %xmm1, 0x50(%rsp)
mulsd %xmm1, %xmm1
movsd %xmm0, 0x58(%rsp)
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
fstpt 0x84(%rsp)
jb 0x75ce
sqrtsd %xmm0, %xmm0
jmp 0x75d7
callq 0x3240
xorpd %xmm2, %xmm2
mulsd 0x1c79(%rip), %xmm0     # 0x9258
movsd %xmm0, 0x60(%rsp)
movsd 0xb0(%r12), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm2, %xmm0
jb 0x7607
sqrtsd %xmm0, %xmm0
jmp 0x760c
callq 0x3240
fldt 0x84(%rsp)
addsd %xmm0, %xmm0
mulsd 0x1c39(%rip), %xmm0     # 0x9258
movsd %xmm0, 0x68(%rsp)
movsd 0xb0(%r12), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x18(%r13), %xmm0
movss 0xbc(%r12), %xmm1
cvtss2sd %xmm1, %xmm3
mulsd %xmm0, %xmm3
movss 0xc0(%r12), %xmm2
movaps %xmm1, %xmm4
addss %xmm2, %xmm4
cvtss2sd %xmm4, %xmm4
divsd %xmm4, %xmm3
movsd %xmm3, 0x198(%rsp)
fldl 0x198(%rsp)
fucomi %st(1), %st
jbe 0x784f
movss %xmm1, 0x9c(%rsp)
fxch %st(1)
fmuls 0x9c(%rsp)
fdivp %st, %st(1)
fldz
faddp %st, %st(1)
fstpl 0x118(%rsp)
movsd 0x118(%rsp), %xmm1
movsd 0x1e12(%rip), %xmm0     # 0x94c0
callq 0x35a0
fldz
movsd %xmm0, 0x110(%rsp)
fldt 0x78(%rsp)
fdivl 0x110(%rsp)
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x128(%rsp)
fld %st(0)
fmull 0x128(%rsp)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x120(%rsp)
fdivl 0x120(%rsp)
fstpl 0x108(%rsp)
movsd 0x108(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
xorpd %xmm0, %xmm0
movsd 0x60(%rsp), %xmm2
ucomisd %xmm0, %xmm2
fld %st(1)
jbe 0x778d
fstp %st(0)
fstp %st(1)
movsd %xmm2, 0x100(%rsp)
fld %st(0)
fmull 0x100(%rsp)
fdivl 0xb0(%r12)
fstpl 0xf8(%rsp)
movsd 0xf8(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm2
divsd %xmm2, %xmm1
mulsd 0x50(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm1, 0xe8(%rsp)
fldl 0xe8(%rsp)
movsd %xmm0, 0xf0(%rsp)
fldl 0xf0(%rsp)
fxch %st(2)
fxch %st(1)
fxch %st(1)
fstpt 0x78(%rsp)
fldt 0x50(%r12)
faddp %st, %st(1)
fstpt 0x84(%rsp)
fldt 0x60(%r12)
faddp %st, %st(1)
fstpt 0x68(%rsp)
fldt 0x90(%rsp)
fadds 0x34(%r12)
fstpt (%rsp)
callq 0x33a0
fstpt 0xa4(%rsp)
fldt 0x90(%rsp)
fadds 0x34(%r12)
fstpt (%rsp)
callq 0x3510
movsd 0x60(%rsp), %xmm2
ucomisd 0x1cdf(%rip), %xmm2     # 0x94c8
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
fldt 0xa4(%rsp)
fmull 0xe0(%rsp)
fldt 0x78(%rsp)
fmulp %st, %st(2)
jbe 0x7a4b
addsd %xmm2, %xmm2
movsd 0x58(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd 0x50(%rsp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm0, 0xd8(%rsp)
fldl 0xd8(%rsp)
movsd %xmm1, 0xd0(%rsp)
fldl 0xd0(%rsp)
jmp 0x7a37
movss %xmm2, 0xa0(%rsp)
movsd %xmm0, 0x190(%rsp)
fldl 0x190(%rsp)
fsub %st, %st(2)
fxch %st(2)
fmuls 0xa0(%rsp)
fxch %st(2)
fsubp %st, %st(1)
fdivrp %st, %st(1)
fldz
faddp %st, %st(1)
fstpl 0x178(%rsp)
movsd 0x178(%rsp), %xmm1
movsd 0x1c2b(%rip), %xmm0     # 0x94c0
callq 0x35a0
fldz
fldt 0xa0(%r12)
movsd %xmm0, 0x170(%rsp)
fdivl 0x170(%rsp)
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x188(%rsp)
fld %st(0)
fmull 0x188(%rsp)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x180(%rsp)
fdivl 0x180(%rsp)
fstpl 0x168(%rsp)
movsd 0x168(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
xorpd %xmm0, %xmm0
movsd 0x60(%rsp), %xmm2
ucomisd %xmm0, %xmm2
fld %st(1)
jbe 0x7978
fstp %st(0)
fstp %st(1)
movsd %xmm2, 0x160(%rsp)
fld %st(0)
fmull 0x160(%rsp)
fdivl 0xb0(%r12)
fstpl 0x158(%rsp)
movsd 0x158(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm2
divsd %xmm2, %xmm1
mulsd 0x50(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm1, 0x148(%rsp)
fldl 0x148(%rsp)
movsd %xmm0, 0x150(%rsp)
fldl 0x150(%rsp)
fxch %st(2)
fxch %st(1)
fxch %st(1)
fstpt 0x78(%rsp)
fldt 0x80(%r12)
fsubp %st, %st(1)
fstpt 0x84(%rsp)
fldt 0x90(%r12)
fsubp %st, %st(1)
fstpt 0x68(%rsp)
fldt 0x90(%rsp)
fadds 0x34(%r12)
fstpt (%rsp)
callq 0x33a0
fstpt 0xa4(%rsp)
fldt 0x90(%rsp)
fadds 0x34(%r12)
fstpt (%rsp)
callq 0x3510
movsd 0x60(%rsp), %xmm2
ucomisd 0x1aee(%rip), %xmm2     # 0x94c8
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x140(%rsp)
fldt 0xa4(%rsp)
fmull 0x140(%rsp)
fldt 0x78(%rsp)
fmulp %st, %st(2)
jbe 0x7a4b
addsd %xmm2, %xmm2
movsd 0x58(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd 0x50(%rsp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm0, 0x138(%rsp)
fldl 0x138(%rsp)
movsd %xmm1, 0x130(%rsp)
fldl 0x130(%rsp)
fld %st(0)
fmul %st(4), %st
fld %st(3)
fmul %st(3), %st
fxch %st(4)
fmulp %st, %st(2)
fsubrp %st, %st(3)
fxch %st(3)
fmulp %st, %st(1)
faddp %st, %st(2)
fldt 0x68(%rsp)
fstpl 0xc8(%rsp)
movsd 0xc8(%rsp), %xmm0
fldt 0x84(%rsp)
fstpl 0xc0(%rsp)
movsd 0xc0(%rsp), %xmm1
movsd %xmm1, 0xb0(%rsp)
faddl 0xb0(%rsp)
movsd %xmm0, 0xb8(%rsp)
fxch %st(1)
faddl 0xb8(%rsp)
cmpb $0x1, (%r12)
jne 0x7acc
fldt 0x10(%r12)
fldt 0x20(%r12)
fxch %st(2)
fstpt 0x30(%rsp)
fxch %st(2)
fstpt 0x20(%rsp)
fstpt 0x10(%rsp)
fstpt (%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x5fd8
jmp 0x7ae1
fstpt 0x10(%rsp)
fstpt (%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x6102
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq