// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %r8, %rbx
movq %rcx, %r14
movq %rsi, %r12
movq %rdi, %r15
fldt 0x1f0(%rsp)
fstpt 0x8c(%rsp)
fldt 0x1e0(%rsp)
fldt 0x80(%rsi)
fldt 0x50(%rsi)
fsubrp %st, %st(1)
fstpl 0x1a8(%rsp)
movsd 0x1a8(%rsp), %xmm1
fldt 0x90(%rsi)
fldt 0x60(%rsi)
fsubrp %st, %st(1)
fstpl 0x1b0(%rsp)
movsd 0x1b0(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
mulsd %xmm0, %xmm0
movsd %xmm1, 0x58(%rsp)
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm2
movsd 0x1e2f(%rip), %xmm0     # 0x9258
mulsd %xmm0, %xmm2
movsd 0xb0(%rsi), %xmm1
movsd %xmm1, 0x80(%rsp)
mulsd %xmm1, %xmm1
movsd %xmm2, 0x48(%rsp)
mulsd %xmm2, %xmm2
addsd %xmm1, %xmm2
xorps %xmm1, %xmm1
sqrtsd %xmm2, %xmm1
addsd %xmm1, %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x70(%rsp)
movsd 0x18(%rdx), %xmm0
movss 0xbc(%rsi), %xmm1
cvtss2sd %xmm1, %xmm3
mulsd %xmm0, %xmm3
movss 0xc0(%rsi), %xmm2
movaps %xmm1, %xmm4
addss %xmm2, %xmm4
cvtss2sd %xmm4, %xmm4
divsd %xmm4, %xmm3
movsd %xmm3, 0x1a0(%rsp)
fldl 0x1a0(%rsp)
fucomi %st(1), %st
jbe 0x7698
fldt 0x70(%r12)
fstpt 0x60(%rsp)
movss %xmm1, 0x98(%rsp)
fxch %st(1)
fmuls 0x98(%rsp)
fdivp %st, %st(1)
fldz
faddp %st, %st(1)
fstpl 0x120(%rsp)
movsd 0x120(%rsp), %xmm1
movsd 0x1fee(%rip), %xmm0     # 0x94d0
callq 0x3590
fldz
movsd %xmm0, 0x118(%rsp)
fldt 0x60(%rsp)
fdivl 0x118(%rsp)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x130(%rsp)
fld %st(0)
fmull 0x130(%rsp)
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x128(%rsp)
fdivl 0x128(%rsp)
fstpl 0x110(%rsp)
movsd 0x110(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
xorpd %xmm1, %xmm1
movsd 0x48(%rsp), %xmm0
ucomisd %xmm1, %xmm0
fld %st(1)
jbe 0x75ca
fstp %st(0)
fstp %st(1)
movsd 0x48(%rsp), %xmm2
movsd %xmm2, 0x108(%rsp)
fld %st(0)
fmull 0x108(%rsp)
fdivl 0xb0(%r12)
fstpl 0x100(%rsp)
movsd 0x100(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm2
divsd %xmm2, %xmm1
mulsd 0x50(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm1, 0xf0(%rsp)
fldl 0xf0(%rsp)
movsd %xmm0, 0xf8(%rsp)
fldl 0xf8(%rsp)
fxch %st(2)
fxch %st(1)
fxch %st(1)
fstpt 0xac(%rsp)
fldt 0x50(%r12)
faddp %st, %st(1)
fstpt 0x80(%rsp)
fldt 0x60(%r12)
faddp %st, %st(1)
fstpt 0x70(%rsp)
fldt 0x8c(%rsp)
fadds 0x34(%r12)
fstpt (%rsp)
callq 0x3390
fstpt 0xa0(%rsp)
fldt 0x8c(%rsp)
fadds 0x34(%r12)
fstpt (%rsp)
callq 0x3500
movsd 0x48(%rsp), %xmm0
ucomisd 0x1eaf(%rip), %xmm0     # 0x94d8
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0xe8(%rsp)
fldt 0xa0(%rsp)
fmull 0xe8(%rsp)
fldt 0xac(%rsp)
fmulp %st, %st(2)
jbe 0x78a9
movsd 0x48(%rsp), %xmm2
addsd %xmm2, %xmm2
movsd 0x58(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd 0x50(%rsp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm0, 0xe0(%rsp)
fldl 0xe0(%rsp)
movsd %xmm1, 0xd8(%rsp)
fldl 0xd8(%rsp)
jmp 0x7895
movss %xmm2, 0x9c(%rsp)
movsd %xmm0, 0x198(%rsp)
fldl 0x198(%rsp)
fsub %st, %st(2)
fxch %st(2)
fmuls 0x9c(%rsp)
fxch %st(2)
fsubp %st, %st(1)
fdivrp %st, %st(1)
fldz
faddp %st, %st(1)
fstpl 0x180(%rsp)
movsd 0x180(%rsp), %xmm1
movsd 0x1df2(%rip), %xmm0     # 0x94d0
callq 0x3590
fldz
fldt 0xa0(%r12)
movsd %xmm0, 0x178(%rsp)
fdivl 0x178(%rsp)
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x190(%rsp)
fld %st(0)
fmull 0x190(%rsp)
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x188(%rsp)
fdivl 0x188(%rsp)
fstpl 0x170(%rsp)
movsd 0x170(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
xorpd %xmm1, %xmm1
movsd 0x48(%rsp), %xmm0
ucomisd %xmm1, %xmm0
fld %st(1)
jbe 0x77ca
fstp %st(0)
fstp %st(1)
movsd 0x48(%rsp), %xmm2
movsd %xmm2, 0x168(%rsp)
fld %st(0)
fmull 0x168(%rsp)
fdivl 0xb0(%r12)
fstpl 0x160(%rsp)
movsd 0x160(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm2
divsd %xmm2, %xmm1
mulsd 0x50(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd %xmm1, 0x150(%rsp)
fldl 0x150(%rsp)
movsd %xmm0, 0x158(%rsp)
fldl 0x158(%rsp)
fxch %st(2)
fxch %st(1)
fxch %st(1)
fstpt 0xac(%rsp)
fldt 0x80(%r12)
fsubp %st, %st(1)
fstpt 0x80(%rsp)
fldt 0x90(%r12)
fsubp %st, %st(1)
fstpt 0x70(%rsp)
fldt 0x8c(%rsp)
fadds 0x34(%r12)
fstpt (%rsp)
callq 0x3390
fstpt 0xa0(%rsp)
fldt 0x8c(%rsp)
fadds 0x34(%r12)
fstpt (%rsp)
callq 0x3500
movsd 0x48(%rsp), %xmm0
ucomisd 0x1ca9(%rip), %xmm0     # 0x94d8
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x148(%rsp)
fldt 0xa0(%rsp)
fmull 0x148(%rsp)
fldt 0xac(%rsp)
fmulp %st, %st(2)
jbe 0x78a9
movsd 0x48(%rsp), %xmm2
addsd %xmm2, %xmm2
movsd 0x58(%rsp), %xmm0
divsd %xmm2, %xmm0
movsd 0x50(%rsp), %xmm1
divsd %xmm2, %xmm1
movsd %xmm0, 0x140(%rsp)
fldl 0x140(%rsp)
movsd %xmm1, 0x138(%rsp)
fldl 0x138(%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 0x70(%rsp)
fstpl 0xd0(%rsp)
movsd 0xd0(%rsp), %xmm0
fldt 0x80(%rsp)
fstpl 0xc8(%rsp)
movsd 0xc8(%rsp), %xmm1
movsd %xmm1, 0xb8(%rsp)
faddl 0xb8(%rsp)
movsd %xmm0, 0xc0(%rsp)
fxch %st(1)
faddl 0xc0(%rsp)
cmpb $0x1, (%r12)
jne 0x792a
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 0x5efa
jmp 0x793f
fstpt 0x10(%rsp)
fstpt (%rsp)
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x6006
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r14
popq %r15
retq