// File: /workspace/github_c_makefile_star2_O0/halcy[P]quasi_crystals_bot/Engine/Downsample.c
// Function: DownsampleBitmap
void DownsampleBitmap(Bitmap *dest,const Bitmap *src,int factor)
{
	float gammatable[256];
	for(int i=0;i<256;i++) gammatable[i]=powf((float)i/255.0,Gamma);

	for(int y=0;y<dest->height;y++)
	for(int x=0;x<dest->width;x++)
	{
		float r=0,g=0,b=0;
		for(int dy=0;dy<factor;dy++)
		for(int dx=0;dx<factor;dx++)
		{
			Pixel p=ReadPixelNoClip(src,x*factor+dx,y*factor+dy);
			r+=gammatable[ExtractRed(p)];
			g+=gammatable[ExtractGreen(p)];
			b+=gammatable[ExtractBlue(p)];
		}

		DrawPixelNoClip(dest,x,y,RGB(
			powf(r/(float)(factor*factor),1.0/Gamma)*255,
			powf(g/(float)(factor*factor),1.0/Gamma)*255,
			powf(b/(float)(factor*factor),1.0/Gamma)*255
		));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq -0x480(%rsp), %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x424(%rbp)
cmpl $0x100, -0x424(%rbp)    # imm = 0x100
jge 0x20e7
cvtsi2ssl -0x424(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x14f9f(%rip), %xmm1    # 0x17050
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss 0x14ff3(%rip), %xmm1    # 0x170b4
callq 0x11a0
movslq -0x424(%rbp), %rax
movss %xmm0, -0x420(%rbp,%rax,4)
movl -0x424(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x424(%rbp)
jmp 0x2091
movl $0x0, -0x428(%rbp)
movl -0x428(%rbp), %eax
movq -0x8(%rbp), %rcx
movswl 0x2(%rcx), %ecx
cmpl %ecx, %eax
jge 0x2676
movl $0x0, -0x42c(%rbp)
movl -0x42c(%rbp), %eax
movq -0x8(%rbp), %rcx
movswl (%rcx), %ecx
cmpl %ecx, %eax
jge 0x2660
xorps %xmm0, %xmm0
movss %xmm0, -0x430(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x434(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x438(%rbp)
movl $0x0, -0x43c(%rbp)
movl -0x43c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2313
movl $0x0, -0x440(%rbp)
movl -0x440(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x22fd
movq -0x10(%rbp), %rdi
movl -0x42c(%rbp), %esi
imull -0x14(%rbp), %esi
addl -0x440(%rbp), %esi
movl -0x428(%rbp), %edx
imull -0x14(%rbp), %edx
addl -0x43c(%rbp), %edx
callq 0xad20
movl %eax, -0x444(%rbp)
movl -0x444(%rbp), %eax
shrl $0x0, %eax
andl $0xff, %eax
cmpl $0x0, %eax
jne 0x21c5
xorl %eax, %eax
movl %eax, -0x448(%rbp)
jmp 0x21f2
movl -0x444(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
imull $0xff, %eax, %eax
movl -0x444(%rbp), %ecx
shrl $0x0, %ecx
andl $0xff, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x448(%rbp)
movl -0x448(%rbp), %eax
movl %eax, %eax
movss -0x420(%rbp,%rax,4), %xmm0
addss -0x430(%rbp), %xmm0
movss %xmm0, -0x430(%rbp)
movl -0x444(%rbp), %eax
shrl $0x0, %eax
andl $0xff, %eax
cmpl $0x0, %eax
jne 0x2230
xorl %eax, %eax
movl %eax, -0x44c(%rbp)
jmp 0x225d
movl -0x444(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
imull $0xff, %eax, %eax
movl -0x444(%rbp), %ecx
shrl $0x0, %ecx
andl $0xff, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x44c(%rbp)
movl -0x44c(%rbp), %eax
movl %eax, %eax
movss -0x420(%rbp,%rax,4), %xmm0
addss -0x434(%rbp), %xmm0
movss %xmm0, -0x434(%rbp)
movl -0x444(%rbp), %eax
shrl $0x0, %eax
andl $0xff, %eax
cmpl $0x0, %eax
jne 0x229b
xorl %eax, %eax
movl %eax, -0x450(%rbp)
jmp 0x22c8
movl -0x444(%rbp), %eax
shrl $0x18, %eax
andl $0xff, %eax
imull $0xff, %eax, %eax
movl -0x444(%rbp), %ecx
shrl $0x0, %ecx
andl $0xff, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0x450(%rbp)
movl -0x450(%rbp), %eax
movl %eax, %eax
movss -0x420(%rbp,%rax,4), %xmm0
addss -0x438(%rbp), %xmm0
movss %xmm0, -0x438(%rbp)
movl -0x440(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x440(%rbp)
jmp 0x216a
jmp 0x22ff
movl -0x43c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x43c(%rbp)
jmp 0x2151
movq -0x8(%rbp), %rax
movq %rax, -0x460(%rbp)
movl -0x42c(%rbp), %eax
movl %eax, -0x458(%rbp)
movl -0x428(%rbp), %eax
movl %eax, -0x454(%rbp)
movss -0x430(%rbp), %xmm0
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss 0x14d5b(%rip), %xmm1    # 0x170b0
callq 0x11a0
movaps %xmm0, %xmm1
movss 0x14ca7(%rip), %xmm0    # 0x1700c
mulss %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2381
xorps %xmm0, %xmm0
movss %xmm0, -0x464(%rbp)
jmp 0x2418
movss -0x430(%rbp), %xmm0
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss 0x14d10(%rip), %xmm1    # 0x170b0
callq 0x11a0
movss 0x14c5f(%rip), %xmm1    # 0x1700c
mulss %xmm1, %xmm0
movss 0x14c53(%rip), %xmm1    # 0x1700c
ucomiss %xmm1, %xmm0
jbe 0x23d0
movss 0x14c46(%rip), %xmm0    # 0x1700c
movss %xmm0, -0x468(%rbp)
jmp 0x2408
movss -0x430(%rbp), %xmm0
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss 0x14cc1(%rip), %xmm1    # 0x170b0
callq 0x11a0
movss 0x14c10(%rip), %xmm1    # 0x1700c
mulss %xmm1, %xmm0
movss %xmm0, -0x468(%rbp)
movss -0x468(%rbp), %xmm0
movss %xmm0, -0x464(%rbp)
movss -0x464(%rbp), %xmm0
cvttss2si %xmm0, %eax
sarl $0x0, %eax
shll $0x8, %eax
movl %eax, -0x46c(%rbp)
movss -0x434(%rbp), %xmm0
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss 0x14c61(%rip), %xmm1    # 0x170b0
callq 0x11a0
movaps %xmm0, %xmm1
movss 0x14bad(%rip), %xmm0    # 0x1700c
mulss %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x247b
xorps %xmm0, %xmm0
movss %xmm0, -0x470(%rbp)
jmp 0x2512
movss -0x434(%rbp), %xmm0
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss 0x14c16(%rip), %xmm1    # 0x170b0
callq 0x11a0
movss 0x14b65(%rip), %xmm1    # 0x1700c
mulss %xmm1, %xmm0
movss 0x14b59(%rip), %xmm1    # 0x1700c
ucomiss %xmm1, %xmm0
jbe 0x24ca
movss 0x14b4c(%rip), %xmm0    # 0x1700c
movss %xmm0, -0x474(%rbp)
jmp 0x2502
movss -0x434(%rbp), %xmm0
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss 0x14bc7(%rip), %xmm1    # 0x170b0
callq 0x11a0
movss 0x14b16(%rip), %xmm1    # 0x1700c
mulss %xmm1, %xmm0
movss %xmm0, -0x474(%rbp)
movss -0x474(%rbp), %xmm0
movss %xmm0, -0x470(%rbp)
movl -0x46c(%rbp), %eax
movss -0x470(%rbp), %xmm0
cvttss2si %xmm0, %ecx
sarl $0x0, %ecx
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x478(%rbp)
movss -0x438(%rbp), %xmm0
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss 0x14b5f(%rip), %xmm1    # 0x170b0
callq 0x11a0
movaps %xmm0, %xmm1
movss 0x14aab(%rip), %xmm0    # 0x1700c
mulss %xmm0, %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm1, %xmm0
jbe 0x257d
xorps %xmm0, %xmm0
movss %xmm0, -0x47c(%rbp)
jmp 0x2614
movss -0x438(%rbp), %xmm0
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss 0x14b14(%rip), %xmm1    # 0x170b0
callq 0x11a0
movss 0x14a63(%rip), %xmm1    # 0x1700c
mulss %xmm1, %xmm0
movss 0x14a57(%rip), %xmm1    # 0x1700c
ucomiss %xmm1, %xmm0
jbe 0x25cc
movss 0x14a4a(%rip), %xmm0    # 0x1700c
movss %xmm0, -0x480(%rbp)
jmp 0x2604
movss -0x438(%rbp), %xmm0
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss 0x14ac5(%rip), %xmm1    # 0x170b0
callq 0x11a0
movss 0x14a14(%rip), %xmm1    # 0x1700c
mulss %xmm1, %xmm0
movss %xmm0, -0x480(%rbp)
movss -0x480(%rbp), %xmm0
movss %xmm0, -0x47c(%rbp)
movl -0x454(%rbp), %edx
movl -0x458(%rbp), %esi
movq -0x460(%rbp), %rdi
movl -0x478(%rbp), %ecx
movss -0x47c(%rbp), %xmm0
cvttss2si %xmm0, %eax
sarl $0x0, %eax
shll $0x18, %eax
orl %eax, %ecx
orl $0xff, %ecx
callq 0xabc0
movl -0x42c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x42c(%rbp)
jmp 0x2111
jmp 0x2662
movl -0x428(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x428(%rbp)
jmp 0x20f1
leaq 0x480(%rsp), %rsp
popq %rbp
retq