// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/polymosttex.c
// Function: ptm_applyeffects
static void ptm_applyeffects(PTTexture * tex, int effects)
{
	int alph = 255;
	int x, y;
	coltype * tptr = tex->pic;

	if (effects == 0 && usegammabrightness) {
		// use a quicker scan for alpha since we don't need
		// to be swizzling texel components
		for (y = tex->tsizy - 1; y >= 0; y--, tptr += tex->sizx) {
			for (x = tex->tsizx - 1; x >= 0; x--) {
				alph &= tptr[x].a;
			}
		}
	} else {
		unsigned char *brit = &britable[usegammabrightness ? 0 : curbrightness][0];
		coltype tcol;

		for (y = tex->tsizy - 1; y >= 0; y--, tptr += tex->sizx) {
			for (x = tex->tsizx - 1; x >= 0; x--) {
				tcol.b = brit[tptr[x].b];
				tcol.g = brit[tptr[x].g];
				tcol.r = brit[tptr[x].r];
				tcol.a = tptr[x].a;
				alph &= tptr[x].a;

				if (effects & HICEFFECT_GREYSCALE) {
					float y;
					y  = 0.3  * (float)tcol.r;
					y += 0.59 * (float)tcol.g;
					y += 0.11 * (float)tcol.b;
					tcol.b = (unsigned char)max(0.0, min(255.0, y));
					tcol.g = tcol.r = tcol.b;
				}
				if (effects & HICEFFECT_INVERT) {
					tcol.b = 255-tcol.b;
					tcol.g = 255-tcol.g;
					tcol.r = 255-tcol.r;
				}

				tptr[x] = tcol;
			}
		}
	}

	tex->hasalpha = (alph != 255);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq (%rdi), %rax
testl %esi, %esi
sete %cl
leaq 0x3ec10(%rip), %rdx     # 0xa378c
movl (%rdx), %edx
testl %edx, %edx
setne %r8b
andb %cl, %r8b
cmpb $0x1, %r8b
jne 0x64bdb
movl 0x14(%rdi), %edx
testl %edx, %edx
jle 0x64d25
movl 0x10(%rdi), %esi
movslq 0x8(%rdi), %r8
movq %rsi, %r9
incq %r9
shlq $0x2, %r8
movl $0xff, %ecx
testl %esi, %esi
jle 0x64bc7
movq %r9, %r10
movzbl -0x5(%rax,%r10,4), %r11d
andl %r11d, %ecx
decq %r10
cmpq $0x1, %r10
jg 0x64bb5
leal -0x1(%rdx), %r10d
addq %r8, %rax
cmpl $0x1, %edx
movl %r10d, %edx
jg 0x64bae
jmp 0x64d2a
xorl %ecx, %ecx
testl %edx, %edx
jne 0x64bea
leaq 0x152e1c(%rip), %rcx    # 0x1b7a04
movl (%rcx), %ecx
movl 0x14(%rdi), %edx
testl %edx, %edx
jle 0x64d25
movslq %ecx, %r8
shlq $0x8, %r8
addq 0x2d3d5(%rip), %r8      # 0x91fd8
xorl %r9d, %r9d
btl $0x1, %esi
sbbl %r9d, %r9d
movl $0xff, %ecx
movsd 0x16106(%rip), %xmm0    # 0x7ad20
movsd 0x16106(%rip), %xmm1    # 0x7ad28
movsd 0x16106(%rip), %xmm2    # 0x7ad30
movsd 0x11326(%rip), %xmm3    # 0x75f58
xorpd %xmm4, %xmm4
movslq 0x10(%rdi), %r10
testq %r10, %r10
jle 0x64d0b
incq %r10
movzbl -0x6(%rax,%r10,4), %r11d
movb (%r8,%r11), %r11b
movzbl -0x7(%rax,%r10,4), %ebx
movb (%r8,%rbx), %bl
movzbl -0x8(%rax,%r10,4), %r14d
movb (%r8,%r14), %bpl
testb $0x1, %sil
je 0x64cdd
movzbl %bpl, %ebp
xorps %xmm5, %xmm5
cvtsi2sd %ebp, %xmm5
mulsd %xmm0, %xmm5
cvtsd2ss %xmm5, %xmm5
movzbl %bl, %ebx
xorps %xmm6, %xmm6
cvtsi2sd %ebx, %xmm6
cvtss2sd %xmm5, %xmm5
mulsd %xmm1, %xmm6
addsd %xmm5, %xmm6
xorps %xmm5, %xmm5
cvtsd2ss %xmm6, %xmm5
movzbl %r11b, %r11d
xorps %xmm6, %xmm6
cvtsi2sd %r11d, %xmm6
cvtss2sd %xmm5, %xmm5
mulsd %xmm2, %xmm6
addsd %xmm5, %xmm6
xorps %xmm5, %xmm5
cvtsd2ss %xmm6, %xmm5
cvtss2sd %xmm5, %xmm5
movapd %xmm3, %xmm6
minsd %xmm5, %xmm6
movapd %xmm6, %xmm5
cmplesd %xmm4, %xmm5
andnpd %xmm6, %xmm5
cvttsd2si %xmm5, %r11d
movl %r11d, %ebx
movl %r11d, %ebp
movzbl -0x5(%rax,%r10,4), %r14d
andl %r14d, %ecx
xorb %r9b, %r11b
xorb %r9b, %bl
xorb %r9b, %bpl
movb %bpl, -0x8(%rax,%r10,4)
movb %bl, -0x7(%rax,%r10,4)
movb %r11b, -0x6(%rax,%r10,4)
decq %r10
cmpq $0x1, %r10
jg 0x64c46
leal -0x1(%rdx), %r10d
movslq 0x8(%rdi), %r11
leaq (%rax,%r11,4), %rax
cmpl $0x1, %edx
movl %r10d, %edx
jg 0x64c36
jmp 0x64d2a
movl $0xff, %ecx
xorl %eax, %eax
cmpl $0xff, %ecx
setne %al
movl %eax, 0x1c(%rdi)
popq %rbx
popq %r14
popq %rbp
retq