// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/jfbuild/src/polymosttex.c
// Function: ptm_fixtransparency
static void ptm_fixtransparency(PTTexture * tex, int clamped)
{
	coltype *wpptr;
	int j, x, y, r, g, b;
	int dox, doy, naxsiz2;
	int daxsiz = tex->tsizx, daysiz = tex->tsizy;
	int daxsiz2 = tex->sizx, daysiz2 = tex->sizy;

	dox = daxsiz2-1;
	doy = daysiz2-1;
	if (clamped) {
		dox = min(dox,daxsiz);
		doy = min(doy,daysiz);
	} else {
		// Make repeating textures duplicate top/left parts
		daxsiz = daxsiz2;
		daysiz = daysiz2;
	}

	daxsiz--; daysiz--; naxsiz2 = -daxsiz2; // Hacks for optimization inside loop

	// Set transparent pixels to average color of neighboring opaque pixels
	// Doing this makes bilinear filtering look much better for masked textures (I.E. sprites)
	for (y = doy; y >= 0; y--) {
		wpptr = &tex->pic[y*daxsiz2+dox];
		for (x = dox; x >= 0; x--, wpptr--) {
			if (wpptr->a) {
				continue;
			}
			r = g = b = j = 0;
			if ((x>     0) && (wpptr[     -1].a)) {
				r += (int)wpptr[     -1].r;
				g += (int)wpptr[     -1].g;
				b += (int)wpptr[     -1].b;
				j++;
			}
			if ((x<daxsiz) && (wpptr[     +1].a)) {
				r += (int)wpptr[     +1].r;
				g += (int)wpptr[     +1].g;
				b += (int)wpptr[     +1].b;
				j++;
			}
			if ((y>     0) && (wpptr[naxsiz2].a)) {
				r += (int)wpptr[naxsiz2].r;
				g += (int)wpptr[naxsiz2].g;
				b += (int)wpptr[naxsiz2].b;
				j++;
			}
			if ((y<daysiz) && (wpptr[daxsiz2].a)) {
				r += (int)wpptr[daxsiz2].r;
				g += (int)wpptr[daxsiz2].g;
				b += (int)wpptr[daxsiz2].b;
				j++;
			}
			switch (j) {
				case 1: wpptr->r =   r            ;
					wpptr->g =   g            ;
					wpptr->b =   b            ;
					break;
				case 2: wpptr->r = ((r   +  1)>>1);
					wpptr->g = ((g   +  1)>>1);
					wpptr->b = ((b   +  1)>>1);
					break;
				case 3: wpptr->r = ((r*85+128)>>8);
					wpptr->g = ((g*85+128)>>8);
					wpptr->b = ((b*85+128)>>8);
					break;
				case 4: wpptr->r = ((r   +  2)>>2);
					wpptr->g = ((g   +  2)>>2);
					wpptr->b = ((b   +  2)>>2);
					break;
				default: break;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x9abd5
movl -0x34(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x9abab
movl -0x34(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x9abb1
movl -0x40(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x9abc7
movl -0x38(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x9abcd
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x9abe1
movl -0x48(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x44(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x44(%rbp)
xorl %eax, %eax
subl -0x48(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x9aed0
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
imull -0x48(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jl 0x9aec0
movq -0x18(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x9ac49
jmp 0x9aea6
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x9acab
movq -0x18(%rbp), %rax
movzbl -0x1(%rax), %eax
cmpl $0x0, %eax
je 0x9acab
movq -0x18(%rbp), %rax
movzbl -0x4(%rax), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movzbl -0x3(%rax), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movzbl -0x2(%rax), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x9acf3
movq -0x18(%rbp), %rax
movzbl 0x7(%rax), %eax
cmpl $0x0, %eax
je 0x9acf3
movq -0x18(%rbp), %rax
movzbl 0x4(%rax), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x5(%rax), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movzbl 0x6(%rax), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x24(%rbp)
jle 0x9ad4c
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzbl 0x3(%rax,%rcx,4), %eax
cmpl $0x0, %eax
je 0x9ad4c
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzbl (%rax,%rcx,4), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzbl 0x1(%rax,%rcx,4), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzbl 0x2(%rax,%rcx,4), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x9ada7
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movzbl 0x3(%rax,%rcx,4), %eax
cmpl $0x0, %eax
je 0x9ada7
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movzbl (%rax,%rcx,4), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movzbl 0x1(%rax,%rcx,4), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movslq -0x48(%rbp), %rcx
movzbl 0x2(%rax,%rcx,4), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x3, %eax
ja 0x9aea2
movq -0x60(%rbp), %rax
leaq 0x1d10e(%rip), %rcx     # 0xb7ed4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x28(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movl -0x2c(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x30(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
jmp 0x9aea4
movl -0x28(%rbp), %eax
addl $0x1, %eax
sarl %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
sarl %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
sarl %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
jmp 0x9aea4
imull $0x55, -0x28(%rbp), %eax
addl $0x80, %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
imull $0x55, -0x2c(%rbp), %eax
addl $0x80, %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
imull $0x55, -0x30(%rbp), %eax
addl $0x80, %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
jmp 0x9aea4
movl -0x28(%rbp), %eax
addl $0x2, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movl -0x2c(%rbp), %eax
addl $0x2, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x30(%rbp), %eax
addl $0x2, %eax
sarl $0x2, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
jmp 0x9aea4
jmp 0x9aea4
jmp 0x9aea6
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $-0x4, %rax
movq %rax, -0x18(%rbp)
jmp 0x9ac30
jmp 0x9aec2
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x9ac01
popq %rbp
retq
nopw %cs:(%rax,%rax)