// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/polymosttex.c
// Function: ptm_mipscale
static void ptm_mipscale(PTTexture * tex)
{
	GLsizei newx, newy;
	GLsizei x, y;
	coltype *wpptr, *rpptr;
	int r, g, b, a, k;

	newx = max(1, (tex->sizx >> 1));
	newy = max(1, (tex->sizy >> 1));

	for (y = 0; y < newy; y++) {
		wpptr = &tex->pic[y * newx];
		rpptr = &tex->pic[(y << 1) * tex->sizx];

		for (x = 0; x < newx; x++, wpptr++, rpptr += 2) {
			r = g = b = a = k = 0;
			if (rpptr[0].a) {
				r += (int)rpptr[0].r;
				g += (int)rpptr[0].g;
				b += (int)rpptr[0].b;
				a += (int)rpptr[0].a;
				k++;
			}
			if ((x+x+1 < tex->sizx) && (rpptr[1].a)) {
				r += (int)rpptr[1].r;
				g += (int)rpptr[1].g;
				b += (int)rpptr[1].b;
				a += (int)rpptr[1].a;
				k++;
			}
			if (y+y+1 < tex->sizy) {
				if (rpptr[tex->sizx].a) {
					r += (int)rpptr[tex->sizx  ].r;
					g += (int)rpptr[tex->sizx  ].g;
					b += (int)rpptr[tex->sizx  ].b;
					a += (int)rpptr[tex->sizx  ].a;
					k++;
				}
				if ((x+x+1 < tex->sizx) && (rpptr[tex->sizx+1].a)) {
					r += (int)rpptr[tex->sizx+1].r;
					g += (int)rpptr[tex->sizx+1].g;
					b += (int)rpptr[tex->sizx+1].b;
					a += (int)rpptr[tex->sizx+1].a;
					k++;
				}
			}
			switch(k) {
				case 0:
				case 1: wpptr->r = r;
					wpptr->g = g;
					wpptr->b = b;
					wpptr->a = a;
					break;
				case 2: wpptr->r = ((r+1)>>1);
					wpptr->g = ((g+1)>>1);
					wpptr->b = ((b+1)>>1);
					wpptr->a = ((a+1)>>1);
					break;
				case 3: wpptr->r = ((r*85+128)>>8);
					wpptr->g = ((g*85+128)>>8);
					wpptr->b = ((b*85+128)>>8);
					wpptr->a = ((a*85+128)>>8);
					break;
				case 4: wpptr->r = ((r+2)>>2);
					wpptr->g = ((g+2)>>2);
					wpptr->b = ((b+2)>>2);
					wpptr->a = ((a+2)>>2);
					break;
				default: break;
			}
			//if (wpptr->a) wpptr->a = 255;
		}
	}

	tex->sizx = newx;
	tex->sizy = newy;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
sarl %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jle 0x9af04
movl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x9af10
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
sarl %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %ecx
sarl %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jle 0x9af32
movl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x9af3e
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
sarl %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x9b326
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x18(%rbp), %ecx
imull -0xc(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x18(%rbp), %ecx
shll %ecx
movq -0x8(%rbp), %rdx
imull 0x8(%rdx), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x9b316
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x28(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x9b015
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x1(%rax), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x2(%rax), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x3(%rax), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
addl -0x14(%rbp), %eax
addl $0x1, %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x9b075
movq -0x28(%rbp), %rax
movzbl 0x7(%rax), %eax
cmpl $0x0, %eax
je 0x9b075
movq -0x28(%rbp), %rax
movzbl 0x4(%rax), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x5(%rax), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x6(%rax), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movzbl 0x7(%rax), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x18(%rbp), %eax
addl -0x18(%rbp), %eax
addl $0x1, %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0x9b1ad
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x8(%rcx), %rcx
cmpb $0x0, 0x3(%rax,%rcx,4)
je 0x9b102
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x8(%rcx), %rcx
movzbl (%rax,%rcx,4), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x8(%rcx), %rcx
movzbl 0x1(%rax,%rcx,4), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x8(%rcx), %rcx
movzbl 0x2(%rax,%rcx,4), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0x8(%rcx), %rcx
movzbl 0x3(%rax,%rcx,4), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x14(%rbp), %eax
addl -0x14(%rbp), %eax
addl $0x1, %eax
movq -0x8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x9b1ab
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl 0x3(%rax,%rcx,4), %eax
cmpl $0x0, %eax
je 0x9b1ab
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx,4), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl 0x1(%rax,%rcx,4), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl 0x2(%rax,%rcx,4), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl 0x3(%rax,%rcx,4), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x9b1ad
movl -0x3c(%rbp), %eax
movq %rax, -0x50(%rbp)
subq $0x4, %rax
ja 0x9b2ec
movq -0x50(%rbp), %rax
leaq 0x1cd1b(%rip), %rcx     # 0xb7ee4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x2c(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movl -0x30(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x34(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x38(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x3(%rax)
jmp 0x9b2ee
movl -0x2c(%rbp), %eax
addl $0x1, %eax
sarl %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
sarl %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
sarl %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
sarl %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x3(%rax)
jmp 0x9b2ee
imull $0x55, -0x2c(%rbp), %eax
addl $0x80, %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
imull $0x55, -0x30(%rbp), %eax
addl $0x80, %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x1(%rax)
imull $0x55, -0x34(%rbp), %eax
addl $0x80, %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x2(%rax)
imull $0x55, -0x38(%rbp), %eax
addl $0x80, %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x3(%rax)
jmp 0x9b2ee
movl -0x2c(%rbp), %eax
addl $0x2, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movl -0x30(%rbp), %eax
addl $0x2, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x34(%rbp), %eax
addl $0x2, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x38(%rbp), %eax
addl $0x2, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, 0x3(%rax)
jmp 0x9b2ee
jmp 0x9b2ee
jmp 0x9b2f0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x28(%rbp)
jmp 0x9af9c
jmp 0x9b318
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x9af4b
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x10(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
popq %rbp
retq
nopl (%rax)