// File: /workspace/github_c_makefile_star2_O1/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:
cmpl $0x0, 0x4(%rsi)
je 0x14164
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 $0x0, 0xc(%rsp)
movq %rsi, 0x28(%rsp)
cmpl $0x0, (%rsi)
je 0x14143
movl 0xc(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
divss 0x10(%rsp), %xmm0
addss 0x534c(%rip), %xmm0     # 0x1930c
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 0x140b8
testl %r13d, %r13d
js 0x140b8
cmpl 0x4(%r14), %ebp
jae 0x140b8
cmpl (%r14), %r13d
jae 0x140b8
movq 0x10(%r14), %rcx
movl 0x8(%r14), %edx
imull %ebp, %edx
addl %edx, %eax
incl %eax
cmpb $0x0, (%rcx,%rax)
jne 0x140b8
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 0x5257(%rip), %xmm0     # 0x192f4
divss %xmm1, %xmm0
movss 0x5253(%rip), %xmm1     # 0x192fc
callq 0x21e0
movss 0x24(%rsp), %xmm1
addss %xmm0, %xmm1
cmpl %r12d, %r13d
jl 0x14043
leal 0x1(%rbp), %eax
cmpl %r15d, %ebp
movl %eax, %ebp
jl 0x14025
addss 0x522d(%rip), %xmm1     # 0x19300
divss 0x5229(%rip), %xmm1     # 0x19304
xorps %xmm0, %xmm0
maxss %xmm1, %xmm0
movss 0x520a(%rip), %xmm1     # 0x192f4
minss %xmm0, %xmm1
movaps %xmm1, %xmm0
mulss %xmm1, %xmm0
addss %xmm1, %xmm1
movss 0x51f7(%rip), %xmm2     # 0x192f8
subss %xmm1, %xmm2
mulss %xmm0, %xmm2
mulss 0x51f7(%rip), %xmm2     # 0x19308
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
cmpl (%rsi), %edx
jb 0x13fd9
movl 0xc(%rsp), %eax
incl %eax
movl %eax, 0xc(%rsp)
cmpl 0x4(%rsi), %eax
jb 0x13f9d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq