// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/jfbuild/src/engine.c
// Function: setbrightness
void setbrightness(int dabrightness, unsigned char *dapal, char noapply)
{
	int i, k, j;

	if (!(noapply&4))
		curbrightness = min(max((int)dabrightness,0),15);

	setgamma(1.f + ((float)curbrightness / 10.f));
	ousegammabrightness = usegammabrightness;

	if (usegammabrightness) j = 0; else j = curbrightness;
	for(k=i=0;i<256;i++)
	{
		if (dapal) {
			// save palette without any brightness adjustment
			curpalette[i].r = dapal[i*3+0] << 2;
			curpalette[i].g = dapal[i*3+1] << 2;
			curpalette[i].b = dapal[i*3+2] << 2;
			curpalette[i].f = 0;
		}

		// brightness adjust the palette
		curpalettefaded[i].b = (tempbuf[k++] = britable[j][ curpalette[i].b ]);
		curpalettefaded[i].g = (tempbuf[k++] = britable[j][ curpalette[i].g ]);
		curpalettefaded[i].r = (tempbuf[k++] = britable[j][ curpalette[i].r ]);
		curpalettefaded[i].f = tempbuf[k++] = 0;
	}

	if ((noapply&1) == 0) setpalette(0,256,(unsigned char*)tempbuf);

#if USE_POLYMOST && USE_OPENGL
	if (rendmode == 3) {
		static unsigned int lastpalettesum = 0;
		unsigned int newpalettesum = crc32once((unsigned char *)curpalettefaded, sizeof(curpalettefaded));

		// only reset the textures if the preserve flag (bit 1 of noapply) is clear and
		// the new palette is different to the last
		if (!(noapply&2) && (newpalettesum != lastpalettesum))
			polymost_texinvalidateall();

		lastpalettesum = newpalettesum;
	}
#endif

	palfadergb.r = palfadergb.g = palfadergb.b = 0;
	palfadedelta = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movl %edx, 0x4(%rsp)
testb $0x4, %dl
jne 0x33776
xorl %eax, %eax
testl %edi, %edi
cmovgl %edi, %eax
cmpl $0xf, %eax
movl $0xf, %ecx
cmovll %eax, %ecx
movl %ecx, 0x18428e(%rip)    # 0x1b7a04
cvtsi2ssl 0x184286(%rip), %xmm0 # 0x1b7a04
divss 0x4280a(%rip), %xmm0    # 0x75f90
addss 0x42806(%rip), %xmm0    # 0x75f94
movss %xmm0, (%rsp)
movl $0x2, %r12d
movss 0x427f3(%rip), %xmm0    # 0x75f94
leaq 0x149940(%rip), %r13    # 0x17d0e8
leaq 0x5e341(%rip), %rbp     # 0x91af0
leaq 0x42e37(%rip), %r15     # 0x765ed
movl %r12d, %ebx
movl 0x6ffcd(%rip), %eax     # 0xa378c
cmpl $0x1, %eax
jne 0x337eb
cmpl $0x0, (%r13)
je 0x3383a
movl %r12d, 0x6ffba(%rip)    # 0xa378c
movq (%rbp,%rbx,8), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x6c31f
movss 0x427ab(%rip), %xmm0    # 0x75f94
jmp 0x337b9
testl %eax, %eax
je 0x3383f
movl $0x2, 0x6ff93(%rip)     # 0xa378c
movss (%rsp), %xmm1
callq 0x6d4f1
testl %eax, %eax
je 0x3384c
xorl %eax, %eax
cmpl $0x0, (%r13)
sete %al
movl %eax, 0x6ff75(%rip)     # 0xa378c
movq (%rbp,%rax,8), %rsi
xorl %r12d, %r12d
leaq 0x42df2(%rip), %rdi     # 0x76618
xorl %eax, %eax
callq 0x6c31f
movss 0x4275f(%rip), %xmm0    # 0x75f94
jmp 0x337b6
movss (%rsp), %xmm0
movss 0x41ad9(%rip), %xmm1    # 0x75320
callq 0x6d4f1
movss (%rsp), %xmm0
movss %xmm0, 0x6ff3b(%rip)    # 0xa3794
movl 0x6ff2d(%rip), %edx     # 0xa378c
movl %edx, 0x6ff2b(%rip)     # 0xa3790
xorl %eax, %eax
movl $0x0, %ecx
testl %edx, %edx
jne 0x33876
movl 0x18418e(%rip), %ecx    # 0x1b7a04
movslq %ecx, %rdi
leaq 0x2(%r14), %rcx
leaq 0x40212c(%rip), %rdx    # 0x4359b0
shlq $0x8, %rdi
leaq 0x402921(%rip), %rsi    # 0x4361b0
addq %rdi, %rsi
leaq 0x3a6f37(%rip), %rdi    # 0x3da7d0
leaq 0x402510(%rip), %r8     # 0x435db0
xorl %r9d, %r9d
testq %r14, %r14
je 0x338d2
movb -0x2(%rcx), %r10b
shlb $0x2, %r10b
movb %r10b, (%rdx,%rax,4)
movb -0x1(%rcx), %r10b
shlb $0x2, %r10b
movb %r10b, 0x1(%rdx,%rax,4)
movb (%rcx), %r10b
shlb $0x2, %r10b
movb %r10b, 0x2(%rdx,%rax,4)
movb $0x0, 0x3(%rdx,%rax,4)
movzbl 0x2(%rdx,%rax,4), %r10d
movb (%r10,%rsi), %r10b
movb %r10b, (%rdi,%rax,4)
movb %r10b, 0x2(%r8,%rax,4)
movzbl 0x1(%rdx,%rax,4), %r10d
movb (%r10,%rsi), %r10b
movb %r10b, 0x1(%rdi,%rax,4)
movb %r10b, 0x1(%r8,%rax,4)
movzbl (%rdx,%rax,4), %r10d
movb (%r10,%rsi), %r10b
movb %r10b, 0x2(%rdi,%rax,4)
movb %r10b, (%r8,%rax,4)
movb %r9b, 0x3(%rdi,%rax,4)
movb %r9b, 0x3(%r8,%rax,4)
incq %rax
addq $0x3, %rcx
cmpq $0x100, %rax            # imm = 0x100
jne 0x338a3
movl 0x4(%rsp), %ebx
testb $0x1, %bl
jne 0x33944
leaq 0x3a6e98(%rip), %rdx    # 0x3da7d0
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
callq 0x6d4ca
leaq 0x5c6005(%rip), %rax    # 0x5f9950
cmpl $0x3, (%rax)
jne 0x3397b
leaq 0x402459(%rip), %rdi    # 0x435db0
movl $0x400, %esi            # imm = 0x400
callq 0x6e4ef
movl %eax, %ebp
testb $0x2, %bl
jne 0x33975
cmpl 0x403842(%rip), %ebp    # 0x4371b0
je 0x33975
callq 0x4d6c1
movl %ebp, 0x403835(%rip)    # 0x4371b0
xorl %eax, %eax
movb %al, 0x1840be(%rip)     # 0x1b7a41
movw $0x0, 0x1840b3(%rip)    # 0x1b7a3f
movb %al, 0x1840b1(%rip)     # 0x1b7a43
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq