// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x3, -0x34(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x1ed33
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x1ed23
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rax
movl -0x1c(%rbp), %esi
movl 0x8(%rcx), %ecx
imull %ecx, %esi
movl -0x18(%rbp), %ecx
movl %ecx, %edx
movl %esi, %ecx
leal (%rcx,%rdx,4), %ecx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
cvtsi2ssl -0x2c(%rbp), %xmm0
movl -0x18(%rbp), %eax
cvtsi2ss %rax, %xmm1
cvtsi2ssl -0x14(%rbp), %xmm2
divss %xmm2, %xmm1
addss %xmm1, %xmm0
movss %xmm0, -0x38(%rbp)
cvtsi2ssl -0x30(%rbp), %xmm0
movl -0x1c(%rbp), %eax
cvtsi2ss %rax, %xmm1
cvtsi2ssl -0x14(%rbp), %xmm2
divss %xmm2, %xmm1
addss %xmm1, %xmm0
movss %xmm0, -0x3c(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
cvttss2si -0x3c(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cvttss2si -0x3c(%rbp), %ecx
addl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1ecbd
cvttss2si -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cvttss2si -0x38(%rbp), %ecx
addl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jge 0x1ecad
cmpl $0x0, -0x44(%rbp)
jl 0x1ec9d
movl -0x44(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x1ec9d
cmpl $0x0, -0x48(%rbp)
jl 0x1ec9d
movl -0x48(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x1ec9d
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x44(%rbp), %ecx
movq -0x8(%rbp), %rdx
imull 0x8(%rdx), %ecx
addl -0x48(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1ec9d
movss -0x38(%rbp), %xmm0
movss -0x3c(%rbp), %xmm1
cvtsi2ssl -0x48(%rbp), %xmm3
cvtsi2ssl -0x44(%rbp), %xmm4
movss 0x5523(%rip), %xmm2     # 0x24190
callq 0x1ea10
movss %xmm0, -0x4c(%rbp)
movss -0x4c(%rbp), %xmm0
movss 0x551c(%rip), %xmm1     # 0x241a0
callq 0x21f0
movss %xmm0, -0x4c(%rbp)
movss -0x4c(%rbp), %xmm0
addss -0x40(%rbp), %xmm0
movss %xmm0, -0x40(%rbp)
jmp 0x1ec9f
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1ebf6
jmp 0x1ecaf
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1ebd8
movss -0x40(%rbp), %xmm2
movss 0x54c6(%rip), %xmm0     # 0x24190
movss 0x54ca(%rip), %xmm1     # 0x2419c
callq 0x1ea80
movss 0x54b9(%rip), %xmm1     # 0x24198
mulss %xmm1, %xmm0
cvttss2si %xmm0, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movl -0x50(%rbp), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x50(%rbp), %eax
movb %al, %cl
movq -0x28(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x28(%rbp), %rax
movb $-0x1, 0x3(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1eb56
jmp 0x1ed25
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1eb3f
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)