// File: /workspace/github_cpp_makefile_star2_O1/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:
cmpq $0x0, 0xd030(%rdi)
je 0x3b959
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movslq 0xd000(%rdi), %r15
movl $0x100, %edi            # imm = 0x100
callq 0x7580
testq %rax, %rax
je 0x3b94b
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
movupd 0x30(%rbp), %xmm3
movupd %xmm3, 0x30(%r14)
movups %xmm2, 0x20(%r14)
movups %xmm1, 0x10(%r14)
movups %xmm0, (%r14)
movsd 0x40(%rbp), %xmm0
movsd 0x50(%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm0
jb 0x3b654
xorps %xmm2, %xmm2
sqrtsd %xmm0, %xmm2
jmp 0x3b661
callq 0x7370
xorpd %xmm3, %xmm3
movapd %xmm0, %xmm2
movsd 0x48(%rbp), %xmm0
movsd 0x58(%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm3, %xmm0
jb 0x3b683
sqrtsd %xmm0, %xmm0
jmp 0x3b694
movsd %xmm2, 0x8(%rsp)
callq 0x7370
movsd 0x8(%rsp), %xmm2
addsd %xmm0, %xmm2
mulsd 0x39a0(%rip), %xmm2     # 0x3f040
movsd 0x110(%rbp), %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x68(%r14)
movsd 0x118(%rbp), %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x70(%r14)
movslq 0x160(%rbp), %rax
movb %al, 0xb8(%r14)
testq %rax, %rax
jle 0x3b6f5
xorl %ecx, %ecx
movsd 0x120(%rbp,%rcx,8), %xmm0
mulsd %xmm2, %xmm0
movsd %xmm0, 0x78(%r14,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x3b6d9
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 0xd030(%rbx), %rax
movq %rax, 0xf0(%r14)
movq $0x0, 0xd030(%rbx)
movsd 0x28(%rax), %xmm0
movsd %xmm0, 0xd0(%r14)
movsd 0x30(%rax), %xmm0
movsd %xmm0, 0xd8(%r14)
movsd 0x38(%rax), %xmm0
movsd %xmm0, 0xe0(%r14)
movsd 0x40(%rax), %xmm0
movsd %xmm0, 0xe8(%r14)
movq 0x48(%rax), %rax
testq %rax, %rax
je 0x3b7ee
movsd 0xd0(%r14), %xmm1
movsd 0xd8(%r14), %xmm2
movsd 0xe0(%r14), %xmm3
minsd 0x28(%rax), %xmm1
movsd %xmm1, 0xd0(%r14)
minsd 0x30(%rax), %xmm2
movsd %xmm2, 0xd8(%r14)
maxsd 0x38(%rax), %xmm3
movsd %xmm3, 0xe0(%r14)
maxsd 0x40(%rax), %xmm0
movsd %xmm0, 0xe8(%r14)
movq 0x48(%rax), %rax
testq %rax, %rax
jne 0x3b7ad
leaq 0x40(%rbp), %r12
movzbl 0x198(%rbp), %eax
cmpl $0x2, %eax
je 0x3b83a
cmpl $0x1, %eax
je 0x3b80e
testl %eax, %eax
jne 0x3b87e
movb $0x0, 0x40(%r14)
jmp 0x3b87e
movb $0x1, 0x40(%r14)
movl 0x70(%rbp), %eax
movl %eax, 0x48(%r14)
movsd 0x80(%rbp), %xmm0
mulsd 0x39de(%rip), %xmm0     # 0x3f208
cvttsd2si %xmm0, %rcx
shll $0x18, %ecx
orl %eax, %ecx
movl %ecx, 0x48(%r14)
jmp 0x3b87e
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3bdeb
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3bed2
leaq 0x90(%rbp), %rsi
movq %rbx, %rdi
leaq 0x10(%rsp), %rdx
movq %r15, %rcx
callq 0x3c1cb
movq %rax, 0x48(%r14)
testq %rax, %rax
jne 0x3b87e
movb $0x0, (%r15)
movzbl 0x199(%rbp), %eax
cmpl $0x2, %eax
je 0x3b8c6
cmpl $0x1, %eax
je 0x3b89a
testl %eax, %eax
jne 0x3b912
movb $0x0, 0x50(%r14)
jmp 0x3b912
movb $0x1, 0x50(%r14)
movl 0x74(%rbp), %eax
movl %eax, 0x58(%r14)
movsd 0x88(%rbp), %xmm0
mulsd 0x3952(%rip), %xmm0     # 0x3f208
cvttsd2si %xmm0, %rcx
shll $0x18, %ecx
orl %eax, %ecx
movl %ecx, 0x58(%r14)
jmp 0x3b912
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x3bdeb
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3bed2
leaq 0xd0(%rbp), %rsi
movq %r14, %r15
addq $0x50, %r15
movq %rbx, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0x3c1cb
movq %rax, 0x58(%r14)
testq %rax, %rax
jne 0x3b912
movb $0x0, (%r15)
cmpb $0x0, 0x19a(%rbp)
setne 0xc9(%r14)
movq 0xd038(%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0x3b93d
movl $0xf8, %eax
addq 0xd048(%rbx), %rax
jmp 0x3b941
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