// File: /workspace/github_c_makefile_star2_O3/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 0x3dee2(%rip), %rdx     # 0xa478c
movl (%rdx), %edx
testl %edx, %edx
setne %r8b
andb %cl, %r8b
cmpb $0x1, %r8b
jne 0x66909
movl 0x14(%rdi), %edx
testl %edx, %edx
jle 0x66a54
movl 0x10(%rdi), %esi
movslq 0x8(%rdi), %r8
movq %rsi, %r9
incq %r9
shlq $0x2, %r8
movl $0xff, %ecx
testl %esi, %esi
jle 0x668f5
movq %r9, %r10
movzbl -0x5(%rax,%r10,4), %r11d
andl %r11d, %ecx
decq %r10
cmpq $0x1, %r10
jg 0x668e3
leal -0x1(%rdx), %r10d
addq %r8, %rax
cmpl $0x1, %edx
movl %r10d, %edx
jg 0x668dc
jmp 0x66a59
xorl %ecx, %ecx
testl %edx, %edx
jne 0x66918
leaq 0x1520ee(%rip), %rcx    # 0x1b8a04
movl (%rcx), %ecx
movl 0x14(%rdi), %edx
testl %edx, %edx
jle 0x66a54
movslq %ecx, %r8
shlq $0x8, %r8
addq 0x2c6a7(%rip), %r8      # 0x92fd8
movl %esi, %r9d
shll $0x1e, %r9d
sarl $0x1f, %r9d
movl $0xff, %ecx
movsd 0x15897(%rip), %xmm0    # 0x7c1e0
movsd 0x15897(%rip), %xmm1    # 0x7c1e8
movsd 0x15897(%rip), %xmm2    # 0x7c1f0
movsd 0x1078f(%rip), %xmm3    # 0x770f0
xorpd %xmm4, %xmm4
movslq 0x10(%rdi), %r10
testq %r10, %r10
jle 0x66a3a
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 0x66a0c
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
ja 0x66975
leal -0x1(%rdx), %r10d
movslq 0x8(%rdi), %r11
leaq (%rax,%r11,4), %rax
cmpl $0x1, %edx
movl %r10d, %edx
jg 0x66965
jmp 0x66a59
movl $0xff, %ecx
xorl %eax, %eax
cmpl $0xff, %ecx
setne %al
movl %eax, 0x1c(%rdi)
popq %rbx
popq %r14
popq %rbp
retq