// File: /workspace/github_cpp_makefile_star2_O2/thierry7100[P]CutOptim/include/nanosvg.h
// Function: nsvg__addShape(NSVGparser*)
static void nsvg__addShape(NSVGparser* p)
{
	NSVGattrib* attr = nsvg__getAttr(p);
	double scale = 1.0;
	NSVGshape* shape;
	NSVGpath* path;
	int i;

	if (p->plist == NULL)
		return;

	shape = (NSVGshape*)malloc(sizeof(NSVGshape));
	if (shape == NULL) goto error;
	memset(shape, 0, sizeof(NSVGshape));

	memcpy(shape->id, attr->id, sizeof shape->id);
	scale = nsvg__getAverageScale(attr->xform);
	shape->strokeWidth = attr->strokeWidth * scale;
	shape->strokeDashOffset = attr->strokeDashOffset * scale;
	shape->strokeDashCount = (char)attr->strokeDashCount;
	for (i = 0; i < attr->strokeDashCount; i++)
		shape->strokeDashArray[i] = attr->strokeDashArray[i] * scale;
	shape->strokeLineJoin = attr->strokeLineJoin;
	shape->strokeLineCap = attr->strokeLineCap;
	shape->miterLimit = attr->miterLimit;
	shape->fillRule = attr->fillRule;
	shape->opacity = attr->opacity;

	shape->paths = p->plist;
	p->plist = NULL;

	// Calculate shape bounds
	shape->bounds[0] = shape->paths->bounds[0];
	shape->bounds[1] = shape->paths->bounds[1];
	shape->bounds[2] = shape->paths->bounds[2];
	shape->bounds[3] = shape->paths->bounds[3];
	for (path = shape->paths->next; path != NULL; path = path->next) {
		shape->bounds[0] = nsvg__minf(shape->bounds[0], path->bounds[0]);
		shape->bounds[1] = nsvg__minf(shape->bounds[1], path->bounds[1]);
		shape->bounds[2] = nsvg__maxf(shape->bounds[2], path->bounds[2]);
		shape->bounds[3] = nsvg__maxf(shape->bounds[3], path->bounds[3]);
	}

	// Set fill
	if (attr->hasFill == 0) {
		shape->fill.type = NSVG_PAINT_NONE;
	} else if (attr->hasFill == 1) {
		shape->fill.type = NSVG_PAINT_COLOR;
		shape->fill.color = attr->fillColor;
		shape->fill.color |= (unsigned int)(attr->fillOpacity*255) << 24;
	} else if (attr->hasFill == 2) {
		double inv[6], localBounds[4];
		nsvg__xformInverse(inv, attr->xform);
		nsvg__getLocalBounds(localBounds, shape, inv);
		shape->fill.gradient = nsvg__createGradient(p, attr->fillGradient, localBounds, &shape->fill.type);
		if (shape->fill.gradient == NULL) {
			shape->fill.type = NSVG_PAINT_NONE;
		}
	}

	// Set stroke
	if (attr->hasStroke == 0) {
		shape->stroke.type = NSVG_PAINT_NONE;
	} else if (attr->hasStroke == 1) {
		shape->stroke.type = NSVG_PAINT_COLOR;
		shape->stroke.color = attr->strokeColor;
		shape->stroke.color |= (unsigned int)(attr->strokeOpacity*255) << 24;
	} else if (attr->hasStroke == 2) {
		double inv[6], localBounds[4];
		nsvg__xformInverse(inv, attr->xform);
		nsvg__getLocalBounds(localBounds, shape, inv);
		shape->stroke.gradient = nsvg__createGradient(p, attr->strokeGradient, localBounds, &shape->stroke.type);
		if (shape->stroke.gradient == NULL)
			shape->stroke.type = NSVG_PAINT_NONE;
	}

	// Set flags
	shape->flags = (attr->visible ? NSVG_FLAGS_VISIBLE : 0x00);

	// Add to tail
	if (p->image->shapes == NULL)
		p->image->shapes = shape;
	else
		p->shapesTail->next = shape;
	p->shapesTail = shape;

	return;

error:
	if (shape) free(shape);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq 0xd030(%rdi), %rbp
testq %rbp, %rbp
je 0x3244d
movq %rdi, %rbx
movslq 0xd000(%rdi), %r14
movl $0x100, %edi            # imm = 0x100
callq 0x85b0
testq %rax, %rax
je 0x3244d
movq %rax, %r15
imulq $0x1a0, %r14, %r12      # imm = 0x1A0
addq %rbx, %r12
movq %rax, %r14
leaq 0x40(%rax), %rdi
xorl %r13d, %r13d
movl $0xc0, %edx
movq %rdi, 0x8(%rsp)
xorl %esi, %esi
callq 0x8280
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups 0x30(%r12), %xmm3
movups %xmm0, (%r15)
movups %xmm1, 0x10(%r15)
movups %xmm2, 0x20(%r15)
movups %xmm3, 0x30(%r15)
leaq 0x40(%r12), %rsi
movupd 0x40(%r12), %xmm0
movupd 0x50(%r12), %xmm1
movupd 0x110(%r12), %xmm2
mulpd %xmm1, %xmm1
mulpd %xmm0, %xmm0
addpd %xmm1, %xmm0
sqrtpd %xmm0, %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
mulsd 0x3e66(%rip), %xmm0     # 0x36040
movapd %xmm0, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
mulpd %xmm2, %xmm1
movupd %xmm1, 0x68(%r15)
movl 0x160(%r12), %eax
movb %al, 0xb8(%r15)
testl %eax, %eax
cmovlel %r13d, %eax
cmpq %r13, %rax
je 0x32220
movsd 0x120(%r12,%r13,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x78(%r14,%r13,8)
incq %r13
jmp 0x32201
movb 0x164(%r12), %al
movb %al, 0xb9(%r14)
movb 0x165(%r12), %al
movb %al, 0xba(%r14)
movsd 0x168(%r12), %xmm0
movsd %xmm0, 0xc0(%r14)
movb 0x170(%r12), %al
movb %al, 0xc8(%r14)
movsd 0x78(%r12), %xmm0
movsd %xmm0, 0x60(%r14)
movq %rbp, 0xf0(%r14)
andq $0x0, 0xd030(%rbx)
movsd 0x28(%rbp), %xmm0
movsd %xmm0, 0xd0(%r14)
movsd 0x30(%rbp), %xmm1
movsd %xmm1, 0xd8(%r14)
movsd 0x38(%rbp), %xmm2
movsd %xmm2, 0xe0(%r14)
movsd 0x40(%rbp), %xmm3
movsd %xmm3, 0xe8(%r14)
movq 0x48(%rbp), %rbp
testq %rbp, %rbp
je 0x322ee
minsd 0x28(%rbp), %xmm0
movsd %xmm0, 0xd0(%r14)
minsd 0x30(%rbp), %xmm1
movsd %xmm1, 0xd8(%r14)
maxsd 0x38(%rbp), %xmm2
movsd %xmm2, 0xe0(%r14)
maxsd 0x40(%rbp), %xmm3
jmp 0x322ab
movzbl 0x198(%r12), %eax
cmpl $0x2, %eax
je 0x32336
cmpl $0x1, %eax
je 0x3230c
testl %eax, %eax
jne 0x32383
movb $0x0, 0x40(%r14)
jmp 0x32383
movb $0x1, 0x40(%r14)
movsd 0x80(%r12), %xmm0
mulsd 0x3f45(%rip), %xmm0     # 0x36268
cvttsd2si %xmm0, %rax
shll $0x18, %eax
orl 0x70(%r12), %eax
movl %eax, 0x48(%r14)
jmp 0x32383
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %rsi, %r13
callq 0x32a34
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x32b1b
leaq 0x90(%r12), %rsi
movq %rbx, %rdi
leaq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rbp
movq %rbp, %rcx
callq 0x32cc8
movq %rax, 0x48(%r14)
testq %rax, %rax
jne 0x32380
movb $0x0, (%rbp)
movq %r13, %rsi
movzbl 0x199(%r12), %eax
cmpl $0x2, %eax
je 0x323cb
cmpl $0x1, %eax
je 0x323a1
testl %eax, %eax
jne 0x32412
movb $0x0, 0x50(%r14)
jmp 0x32412
movb $0x1, 0x50(%r14)
movsd 0x88(%r12), %xmm0
mulsd 0x3eb0(%rip), %xmm0     # 0x36268
cvttsd2si %xmm0, %rax
shll $0x18, %eax
orl 0x74(%r12), %eax
movl %eax, 0x58(%r14)
jmp 0x32412
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
callq 0x32a34
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x32b1b
leaq 0xd0(%r12), %rsi
addq $0x50, %r15
movq %rbx, %rdi
movq %r13, %rdx
movq %r15, %rcx
callq 0x32cc8
movq %rax, 0x58(%r14)
testq %rax, %rax
jne 0x32412
movb $0x0, (%r15)
cmpb $0x0, 0x19a(%r12)
setne 0xc9(%r14)
movq 0xd038(%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0x3243f
movl $0xf8, %eax
addq 0xd048(%rbx), %rax
jmp 0x32443
addq $0x10, %rax
movq %r14, (%rax)
movq %r14, 0xd048(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq