// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %rbx
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
callq 0x8390
movq 0xd040(%r14), %r12
testq %r12, %r12
je 0x3f512
movq %r13, -0x40(%rbp)
movq %r14, -0x58(%rbp)
movslq 0xd000(%r14), %rax
movq %rax, -0xa8(%rbp)
xorl %r14d, %r14d
movq %r12, %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x85d0
testl %eax, %eax
je 0x3f4bd
movq 0x120(%r13), %r13
testq %r13, %r13
jne 0x3f49d
jmp 0x3f7fe
movq %rbx, -0xa0(%rbp)
movq 0x118(%r13), %rax
movq %r13, %r15
testq %rax, %rax
je 0x3f51a
movq %rax, %r12
movl 0x110(%r15), %ebx
movslq %ebx, %r15
shlq $0x4, %r15
leaq 0x50(%r15), %rdi
callq 0x85c0
testq %rax, %rax
je 0x3f512
movq %rax, %r14
cmpb $0x1, 0xd9(%r13)
jne 0x3f55b
movq -0x40(%rbp), %rax
movupd (%rax), %xmm1
movupd 0x10(%rax), %xmm2
subpd %xmm1, %xmm2
jmp 0x3f56f
xorl %r14d, %r14d
jmp 0x3f7fe
xorl %r14d, %r14d
movq %r13, %r15
movq %r15, %rbx
addq $0x40, %rbx
movq %r12, %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x85d0
testl %eax, %eax
je 0x3f54a
movq 0x120(%r15), %r15
testq %r15, %r15
jne 0x3f52a
jmp 0x3f7fe
movq 0x118(%r15), %rax
testq %rax, %rax
je 0x3f520
jmp 0x3f4d3
movq -0x58(%rbp), %rax
movupd 0xd050(%rax), %xmm1
movupd 0xd060(%rax), %xmm2
movq %r15, -0x98(%rbp)
cmpb $0x2, 0x80(%r13)
movapd %xmm2, -0x70(%rbp)
movapd %xmm1, -0x40(%rbp)
jne 0x3f65c
movsd 0x88(%r13), %xmm0
movl 0x90(%r13), %esi
movq -0x58(%rbp), %r15
movq %r15, %rdi
callq 0x3e03c
movsd %xmm0, -0x50(%rbp)
movsd 0x98(%r13), %xmm0
movl 0xa0(%r13), %esi
movaps -0x70(%rbp), %xmm1
movhlps %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movaps %xmm1, %xmm2
movaps %xmm1, -0x80(%rbp)
movaps -0x40(%rbp), %xmm1
movhlps %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movaps %xmm1, -0x90(%rbp)
movq %r15, %rdi
callq 0x3e03c
movsd %xmm0, -0x48(%rbp)
movsd 0xa8(%r13), %xmm0
movl 0xb0(%r13), %esi
movq %r15, %rdi
movaps -0x40(%rbp), %xmm1
movaps -0x70(%rbp), %xmm2
callq 0x3e03c
movaps %xmm0, -0x40(%rbp)
movsd 0xb8(%r13), %xmm0
movl 0xc0(%r13), %esi
movq %r15, %rdi
movaps -0x90(%rbp), %xmm1
movaps -0x80(%rbp), %xmm2
callq 0x3e03c
movapd -0x40(%rbp), %xmm4
movsd -0x48(%rbp), %xmm2
movsd -0x50(%rbp), %xmm1
subsd %xmm1, %xmm4
subsd %xmm2, %xmm0
movsd %xmm0, (%r14)
movapd 0x2a6d(%rip), %xmm3     # 0x420c0
xorpd %xmm4, %xmm3
jmp 0x3f781
movapd %xmm2, %xmm0
unpckhpd %xmm2, %xmm0            # xmm0 = xmm0[1],xmm2[1]
movapd %xmm0, -0x80(%rbp)
mulsd %xmm0, %xmm0
movapd %xmm2, %xmm3
mulsd %xmm2, %xmm3
addsd %xmm0, %xmm3
xorps %xmm0, %xmm0
sqrtsd %xmm3, %xmm0
divsd 0x2b50(%rip), %xmm0     # 0x421d8
movsd %xmm0, -0x90(%rbp)
movsd 0x88(%r13), %xmm0
movl 0x90(%r13), %esi
movq -0x58(%rbp), %r15
movq %r15, %rdi
callq 0x3e03c
movsd %xmm0, -0x50(%rbp)
movsd 0x98(%r13), %xmm0
movl 0xa0(%r13), %esi
movaps -0x40(%rbp), %xmm1
movhlps %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movaps %xmm1, -0xc0(%rbp)
movq %r15, %rdi
movaps -0x80(%rbp), %xmm2
callq 0x3e03c
movsd %xmm0, -0x48(%rbp)
movsd 0xb8(%r13), %xmm0
movl 0xc0(%r13), %esi
movq %r15, %rdi
movaps -0x40(%rbp), %xmm1
movaps -0x70(%rbp), %xmm2
callq 0x3e03c
movaps %xmm0, -0x40(%rbp)
movsd 0xc8(%r13), %xmm0
movl 0xd0(%r13), %esi
movq %r15, %rdi
movaps -0xc0(%rbp), %xmm1
movaps -0x80(%rbp), %xmm2
callq 0x3e03c
movaps %xmm0, -0x70(%rbp)
movsd 0xa8(%r13), %xmm0
movl 0xb0(%r13), %esi
xorps %xmm1, %xmm1
movq %r15, %rdi
movsd -0x90(%rbp), %xmm2
callq 0x3e03c
xorpd %xmm3, %xmm3
movsd -0x48(%rbp), %xmm2
movsd %xmm0, (%r14)
movapd -0x40(%rbp), %xmm4
unpcklpd -0x70(%rbp), %xmm4      # xmm4 = xmm4[0],mem[0]
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
divpd %xmm1, %xmm4
movsd -0x50(%rbp), %xmm1
movupd %xmm4, 0x38(%r14)
xorpd %xmm4, %xmm4
movsd %xmm3, 0x8(%r14)
movsd %xmm4, 0x10(%r14)
movsd %xmm0, 0x18(%r14)
movsd %xmm1, 0x20(%r14)
movsd %xmm2, 0x28(%r14)
leaq 0xe0(%r13), %rsi
movq %r14, %rdi
callq 0x3e128
imulq $0x1a0, -0xa8(%rbp), %rax # imm = 0x1A0
leaq (%r15,%rax), %rsi
addq $0x40, %rsi
movq %r14, %rdi
callq 0x3e128
movb 0xd8(%r13), %al
movb %al, 0x30(%r14)
movq %r14, %rdi
addq $0x50, %rdi
movq %r12, %rsi
movq -0x98(%rbp), %rdx
callq 0x83a0
movl %ebx, 0x48(%r14)
movb 0x80(%r13), %al
movq -0xa0(%rbp), %rcx
movb %al, (%rcx)
movq %r14, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop