// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/meatball.c
// Function: metaballize
void
metaballize(Image *in, Image *out, int mag)
{
	u32 x, y;
	u8 *p;

//	int offx = 192;
//	int offy = 68;
	int offx = 0;
	int offy = 0;
	int sz = 3;

	for(y = 0; y < out->h; y++)
		for(x = 0; x < out->w; x++) {
			p = &out->pixels[y*out->stride + x*4];

			float fx = offx + (float)x/mag;
			float fy = offy + (float)y/mag;

			float f = 0.0f;
			for(int i = (int)fy - sz; i < (int)fy + sz; i++)
			for(int j = (int)fx - sz; j < (int)fx + sz; j++)
				if(i >= 0 && i < in->h &&
				   j >= 0 && j < in->w &&
				   in->pixels[i*in->stride + j] == 0) {
					float m = meta(fx,fy, 1.00f, j, i);
					m = powf(m, 2.2f);
					f += m;
				}

#if 0
			int c = 255;
			if(f > 1.0f) {
				c = 0;
			}
#else
			int c = smoothstep(1.0f, 0.7f, f)*255;
#endif
			p[0] = c;
			p[1] = c;
			p[2] = c;
			p[3] = 255;
		}
}

// Assembly:
movl 0x4(%rsi), %eax
testl %eax, %eax
je 0x13e37
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
cvtsi2ss %edx, %xmm0
movss %xmm0, 0x10(%rsp)
movl (%rsi), %ecx
movl $0x0, 0xc(%rsp)
movq %rsi, 0x28(%rsp)
testl %ecx, %ecx
movl $0x0, %ecx
je 0x13e17
movl 0xc(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
divss 0x10(%rsp), %xmm0
addss 0x57a1(%rip), %xmm0     # 0x19430
movss %xmm0, 0x18(%rsp)
cvttss2si %xmm0, %r15d
leal -0x3(%r15), %eax
movl %eax, 0x14(%rsp)
addl $0x2, %r15d
xorl %edx, %edx
movq 0x10(%rsi), %rax
movq %rax, 0x38(%rsp)
movl 0x8(%rsi), %eax
imull 0xc(%rsp), %eax
movl %edx, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
divss 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
addss %xmm1, %xmm0
movss %xmm0, 0x1c(%rsp)
cvttss2si %xmm0, %ebx
movq %rdx, 0x40(%rsp)
leal (%rax,%rdx,4), %eax
movq %rax, 0x30(%rsp)
leal 0x2(%rbx), %r12d
addl $-0x4, %ebx
movl 0x14(%rsp), %eax
movl %eax, %ebp
xorps %xmm0, %xmm0
cvtsi2ss %ebp, %xmm0
movss 0x18(%rsp), %xmm2
subss %xmm0, %xmm2
mulss %xmm2, %xmm2
movss %xmm2, 0x20(%rsp)
movl %ebx, %r13d
movl %r13d, %eax
leal 0x1(%rax), %r13d
testl %ebp, %ebp
js 0x13d87
testl %r13d, %r13d
js 0x13d87
cmpl 0x4(%r14), %ebp
jae 0x13d87
cmpl (%r14), %r13d
jae 0x13d87
movq 0x10(%r14), %rcx
movl 0x8(%r14), %edx
imull %ebp, %edx
addl %edx, %eax
incl %eax
cmpb $0x0, (%rcx,%rax)
jne 0x13d87
xorps %xmm0, %xmm0
cvtsi2ss %r13d, %xmm0
movss %xmm1, 0x24(%rsp)
movss 0x1c(%rsp), %xmm1
subss %xmm0, %xmm1
mulss %xmm1, %xmm1
addss 0x20(%rsp), %xmm1
movss 0x56ac(%rip), %xmm0     # 0x19418
divss %xmm1, %xmm0
movss 0x56a8(%rip), %xmm1     # 0x19420
callq 0x21f0
movss 0x24(%rsp), %xmm1
addss %xmm0, %xmm1
cmpl %r12d, %r13d
jl 0x13d12
leal 0x1(%rbp), %eax
cmpl %r15d, %ebp
movl %eax, %ebp
jl 0x13cf4
addss 0x5682(%rip), %xmm1     # 0x19424
divss 0x567e(%rip), %xmm1     # 0x19428
xorps %xmm0, %xmm0
maxss %xmm1, %xmm0
movss 0x565f(%rip), %xmm1     # 0x19418
minss %xmm0, %xmm1
movaps %xmm1, %xmm0
mulss %xmm1, %xmm0
addss %xmm1, %xmm1
movss 0x564c(%rip), %xmm2     # 0x1941c
subss %xmm1, %xmm2
mulss %xmm0, %xmm2
mulss 0x564c(%rip), %xmm2     # 0x1942c
cvttss2si %xmm2, %eax
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %rdx
movb %al, (%rcx,%rdx)
movb %al, 0x1(%rcx,%rdx)
movb %al, 0x2(%rcx,%rdx)
movb $-0x1, 0x3(%rcx,%rdx)
movq 0x40(%rsp), %rdx
incl %edx
movq 0x28(%rsp), %rsi
movl (%rsi), %ecx
cmpl %ecx, %edx
jb 0x13ca8
movl 0x4(%rsi), %eax
movl 0xc(%rsp), %edx
incl %edx
movl %edx, 0xc(%rsp)
cmpl %eax, %edx
jb 0x13c68
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq