// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq 0xd030(%rdi), %r12
testq %r12, %r12
je 0x3a95a
movq %rdi, %rbx
movslq 0xd000(%rdi), %r15
movl $0x100, %edi            # imm = 0x100
callq 0x7590
testq %rax, %rax
je 0x3a95a
movq %rax, %r14
imulq $0x1a0, %r15, %rbp      # imm = 0x1A0
addq %rbx, %rbp
leaq 0x40(%rax), %r15
movl $0xc0, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x7270
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movups 0x30(%rbp), %xmm3
movups %xmm0, (%r14)
movups %xmm1, 0x10(%r14)
movups %xmm2, 0x20(%r14)
movups %xmm3, 0x30(%r14)
movupd 0x40(%rbp), %xmm0
movupd 0x50(%rbp), %xmm1
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 0x3959(%rip), %xmm0     # 0x3e040
movupd 0x110(%rbp), %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
mulpd %xmm1, %xmm2
movupd %xmm2, 0x68(%r14)
movslq 0x160(%rbp), %rax
movb %al, 0xb8(%r14)
testq %rax, %rax
jle 0x3a732
xorl %ecx, %ecx
movsd 0x120(%rbp,%rcx,8), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x78(%r14,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x3a716
movb 0x164(%rbp), %al
movb %al, 0xb9(%r14)
movb 0x165(%rbp), %al
movb %al, 0xba(%r14)
movsd 0x168(%rbp), %xmm0
movsd %xmm0, 0xc0(%r14)
movb 0x170(%rbp), %al
movb %al, 0xc8(%r14)
movsd 0x78(%rbp), %xmm0
movsd %xmm0, 0x60(%r14)
movq %r12, 0xf0(%r14)
movq $0x0, 0xd030(%rbx)
movsd 0x28(%r12), %xmm0
movsd %xmm0, 0xd0(%r14)
movsd 0x30(%r12), %xmm1
movsd %xmm1, 0xd8(%r14)
movsd 0x38(%r12), %xmm2
movsd %xmm2, 0xe0(%r14)
movsd 0x40(%r12), %xmm3
movsd %xmm3, 0xe8(%r14)
movq 0x48(%r12), %rax
testq %rax, %rax
je 0x3a80f
minsd 0x28(%rax), %xmm0
movsd %xmm0, 0xd0(%r14)
minsd 0x30(%rax), %xmm1
movsd %xmm1, 0xd8(%r14)
maxsd 0x38(%rax), %xmm2
movsd %xmm2, 0xe0(%r14)
maxsd 0x40(%rax), %xmm3
movsd %xmm3, 0xe8(%r14)
movq 0x48(%rax), %rax
jmp 0x3a7cc
leaq 0x40(%rbp), %r12
movzbl 0x198(%rbp), %eax
cmpl $0x2, %eax
je 0x3a855
cmpl $0x1, %eax
je 0x3a82f
testl %eax, %eax
jne 0x3a895
movb $0x0, 0x40(%r14)
jmp 0x3a895
movb $0x1, 0x40(%r14)
movsd 0x80(%rbp), %xmm0
mulsd 0x3a64(%rip), %xmm0     # 0x3e2a8
cvttsd2si %xmm0, %rax
shll $0x18, %eax
orl 0x70(%rbp), %eax
movl %eax, 0x48(%r14)
jmp 0x3a895
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3ae1d
movq %rsp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3af04
leaq 0x90(%rbp), %rsi
movq %rbx, %rdi
movq %rsp, %rdx
movq %r15, %rcx
callq 0x3b154
movq %rax, 0x48(%r14)
testq %rax, %rax
jne 0x3a895
movb $0x0, (%r15)
movzbl 0x199(%rbp), %eax
cmpl $0x2, %eax
je 0x3a8d7
cmpl $0x1, %eax
je 0x3a8b1
testl %eax, %eax
jne 0x3a921
movb $0x0, 0x50(%r14)
jmp 0x3a921
movb $0x1, 0x50(%r14)
movsd 0x88(%rbp), %xmm0
mulsd 0x39e2(%rip), %xmm0     # 0x3e2a8
cvttsd2si %xmm0, %rax
shll $0x18, %eax
orl 0x74(%rbp), %eax
movl %eax, 0x58(%r14)
jmp 0x3a921
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x3ae1d
movq %rsp, %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3af04
leaq 0xd0(%rbp), %rsi
movq %r14, %r15
addq $0x50, %r15
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0x3b154
movq %rax, 0x58(%r14)
testq %rax, %rax
jne 0x3a921
movb $0x0, (%r15)
cmpb $0x0, 0x19a(%rbp)
setne 0xc9(%r14)
movq 0xd038(%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0x3a94c
movl $0xf8, %eax
addq 0xd048(%rbx), %rax
jmp 0x3a950
addq $0x10, %rax
movq %r14, (%rax)
movq %r14, 0xd048(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq