// File: /workspace/github_cpp_makefile_star2_O1/thierry7100[P]CutOptim/include/nanosvg.h
// Function: nsvg__createGradient(NSVGparser*, char const*, double const*, char*)
static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const double* localBounds, char* paintType)
{
	NSVGattrib* attr = nsvg__getAttr(p);
	NSVGgradientData* data = NULL;
	NSVGgradientData* ref = NULL;
	NSVGgradientStop* stops = NULL;
	NSVGgradient* grad;
	double ox, oy, sw, sh, sl;
	int nstops = 0;

	data = nsvg__findGradientData(p, id);
	if (data == NULL) return NULL;

	// TODO: use ref to fill in all unset values too.
	ref = data;
	while (ref != NULL) {
		if (stops == NULL && ref->stops != NULL) {
			stops = ref->stops;
			nstops = ref->nstops;
			break;
		}
		ref = nsvg__findGradientData(p, ref->ref);
	}
	if (stops == NULL) return NULL;

	grad = (NSVGgradient*)malloc(sizeof(NSVGgradient) + sizeof(NSVGgradientStop)*(nstops-1));
	if (grad == NULL) return NULL;

	// The shape width and height.
	if (data->units == NSVG_OBJECT_SPACE) {
		ox = localBounds[0];
		oy = localBounds[1];
		sw = localBounds[2] - localBounds[0];
		sh = localBounds[3] - localBounds[1];
	} else {
		ox = nsvg__actualOrigX(p);
		oy = nsvg__actualOrigY(p);
		sw = nsvg__actualWidth(p);
		sh = nsvg__actualHeight(p);
	}
	sl = sqrt(sw*sw + sh*sh) / sqrt(2.0);

	if (data->type == NSVG_PAINT_LINEAR_GRADIENT) {
		double x1, y1, x2, y2, dx, dy;
		x1 = nsvg__convertToPixels(p, data->linear.x1, ox, sw);
		y1 = nsvg__convertToPixels(p, data->linear.y1, oy, sh);
		x2 = nsvg__convertToPixels(p, data->linear.x2, ox, sw);
		y2 = nsvg__convertToPixels(p, data->linear.y2, oy, sh);
		// Calculate transform aligned to the line
		dx = x2 - x1;
		dy = y2 - y1;
		grad->xform[0] = dy; grad->xform[1] = -dx;
		grad->xform[2] = dx; grad->xform[3] = dy;
		grad->xform[4] = x1; grad->xform[5] = y1;
	} else {
		double cx, cy, fx, fy, r;
		cx = nsvg__convertToPixels(p, data->radial.cx, ox, sw);
		cy = nsvg__convertToPixels(p, data->radial.cy, oy, sh);
		fx = nsvg__convertToPixels(p, data->radial.fx, ox, sw);
		fy = nsvg__convertToPixels(p, data->radial.fy, oy, sh);
		r = nsvg__convertToPixels(p, data->radial.r, 0, sl);
		// Calculate transform aligned to the circle
		grad->xform[0] = r; grad->xform[1] = 0;
		grad->xform[2] = 0; grad->xform[3] = r;
		grad->xform[4] = cx; grad->xform[5] = cy;
		grad->fx = fx / r;
		grad->fy = fy / r;
	}

	nsvg__xformMultiply(grad->xform, data->xform);
	nsvg__xformMultiply(grad->xform, attr->xform);

	grad->spread = data->spread;
	memcpy(grad->stops, stops, nstops*sizeof(NSVGgradientStop));
	grad->nstops = nstops;

	*paintType = data->type;

	return grad;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r13
movq %rdx, %rbx
movq %rdi, %r15
movslq 0xd000(%rdi), %rax
movq %rax, 0x60(%rsp)
movq 0xd040(%rdi), %rbp
testq %rbp, %rbp
je 0x3c21b
movq %rsi, %r12
movq %rbp, %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x7590
testl %eax, %eax
je 0x3c21e
movq 0x120(%r14), %r14
testq %r14, %r14
jne 0x3c200
xorl %r14d, %r14d
testq %r14, %r14
je 0x3c2d1
movq %r13, 0x58(%rsp)
movq %r14, %r13
movq 0x118(%r13), %r12
testq %r12, %r12
jne 0x3c275
testq %rbp, %rbp
je 0x3c263
addq $0x40, %r13
movq %rbp, %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x7590
testl %eax, %eax
je 0x3c266
movq 0x120(%r12), %r12
testq %r12, %r12
jne 0x3c247
xorl %r12d, %r12d
movq %r12, %r13
testq %r12, %r12
jne 0x3c22f
xorl %eax, %eax
xorl %r12d, %r12d
jmp 0x3c27c
movl 0x110(%r13), %eax
testq %r12, %r12
je 0x3c2d1
movq %rax, 0x50(%rsp)
movslq %eax, %rbp
shlq $0x4, %rbp
leaq 0x50(%rbp), %rdi
callq 0x7580
testq %rax, %rax
je 0x3c2d1
movq %rax, %r13
cmpb $0x1, 0xd9(%r14)
jne 0x3c2d9
movsd (%rbx), %xmm1
movsd 0x8(%rbx), %xmm0
movsd 0x10(%rbx), %xmm2
movsd %xmm1, 0x10(%rsp)
subsd %xmm1, %xmm2
movsd 0x18(%rbx), %xmm3
movsd %xmm0, 0x8(%rsp)
subsd %xmm0, %xmm3
jmp 0x3c309
xorl %r13d, %r13d
jmp 0x3c5ba
movsd 0xd050(%r15), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0xd058(%r15), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0xd060(%r15), %xmm2
movsd 0xd068(%r15), %xmm3
movapd %xmm3, %xmm1
mulsd %xmm3, %xmm1
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movsd %xmm3, 0x20(%rsp)
movsd %xmm2, 0x38(%rsp)
jb 0x3c339
sqrtsd %xmm0, %xmm0
jmp 0x3c344
callq 0x7370
movsd 0x38(%rsp), %xmm2
cmpb $0x2, 0x80(%r14)
jne 0x3c43b
movsd 0x88(%r14), %xmm0
movl 0x90(%r14), %esi
movq %r15, %rdi
movsd 0x10(%rsp), %xmm1
callq 0x3ad0d
movsd %xmm0, 0x28(%rsp)
movsd 0x98(%r14), %xmm0
movl 0xa0(%r14), %esi
movq %r15, %rdi
movsd 0x8(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
callq 0x3ad0d
movsd %xmm0, 0x30(%rsp)
movsd 0xa8(%r14), %xmm0
movl 0xb0(%r14), %esi
movq %r15, %rdi
movsd 0x10(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
callq 0x3ad0d
movaps %xmm0, 0x10(%rsp)
movsd 0xb8(%r14), %xmm0
movl 0xc0(%r14), %esi
movq %r15, %rdi
movsd 0x8(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
callq 0x3ad0d
movsd 0x30(%rsp), %xmm2
movsd 0x28(%rsp), %xmm3
movapd 0x10(%rsp), %xmm4
subsd %xmm3, %xmm4
subsd %xmm2, %xmm0
movsd %xmm0, (%r13)
movapd 0x2c6b(%rip), %xmm1     # 0x3f080
xorpd %xmm4, %xmm1
movlpd %xmm1, 0x8(%r13)
movsd %xmm4, 0x10(%r13)
movsd %xmm0, 0x18(%r13)
movsd %xmm3, 0x20(%r13)
movl $0x28, %eax
jmp 0x3c557
divsd 0x2cfd(%rip), %xmm0     # 0x3f140
movsd %xmm0, 0x28(%rsp)
movsd 0x88(%r14), %xmm0
movl 0x90(%r14), %esi
movq %r15, %rdi
movsd 0x10(%rsp), %xmm1
callq 0x3ad0d
movsd %xmm0, 0x48(%rsp)
movsd 0x98(%r14), %xmm0
movl 0xa0(%r14), %esi
movq %r15, %rdi
movsd 0x8(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
callq 0x3ad0d
movsd %xmm0, 0x40(%rsp)
movsd 0xb8(%r14), %xmm0
movl 0xc0(%r14), %esi
movq %r15, %rdi
movsd 0x10(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
callq 0x3ad0d
movsd %xmm0, 0x10(%rsp)
movsd 0xc8(%r14), %xmm0
movl 0xd0(%r14), %esi
movq %r15, %rdi
movsd 0x8(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
callq 0x3ad0d
movsd %xmm0, 0x30(%rsp)
movsd 0xa8(%r14), %xmm0
movl 0xb0(%r14), %esi
xorps %xmm1, %xmm1
movq %r15, %rdi
movsd 0x28(%rsp), %xmm2
callq 0x3ad0d
movsd 0x30(%rsp), %xmm2
movsd %xmm0, (%r13)
xorps %xmm1, %xmm1
movups %xmm1, 0x8(%r13)
movsd %xmm0, 0x18(%r13)
movsd 0x48(%rsp), %xmm1
movsd %xmm1, 0x20(%r13)
movsd 0x40(%rsp), %xmm1
movsd %xmm1, 0x28(%r13)
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x38(%r13)
divsd %xmm0, %xmm2
movl $0x40, %eax
movsd %xmm2, (%r13,%rax)
leaq 0xe0(%r14), %rsi
movq %r13, %rdi
callq 0x3ad90
imulq $0x1a0, 0x60(%rsp), %rax # imm = 0x1A0
leaq (%r15,%rax), %rsi
addq $0x40, %rsi
movq %r13, %rdi
callq 0x3ad90
movb 0xd8(%r14), %al
movb %al, 0x30(%r13)
movq %r13, %rdi
addq $0x50, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x7380
movq 0x50(%rsp), %rax
movl %eax, 0x48(%r13)
movb 0x80(%r14), %al
movq 0x58(%rsp), %rcx
movb %al, (%rcx)
movq %r13, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq