// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movb %dl, %al
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movsbl -0x11(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
jne 0x4ca2d
cmpl $0x0, -0x4(%rbp)
jle 0x4c9ee
movl -0x4(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x4c9f5
xorl %eax, %eax
movl %eax, -0x28(%rbp)
jmp 0x4c9f5
movl -0x28(%rbp), %eax
cmpl $0xf, %eax
jge 0x4ca1a
cmpl $0x0, -0x4(%rbp)
jle 0x4ca0b
movl -0x4(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x4ca12
xorl %eax, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4ca12
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x4ca24
movl $0xf, %eax
movl %eax, -0x30(%rbp)
jmp 0x4ca24
movl -0x30(%rbp), %eax
movl %eax, 0x1a8b37(%rip)    # 0x1f5564
cvtsi2ssl 0x1a8b2f(%rip), %xmm1 # 0x1f5564
movss 0x663c7(%rip), %xmm0    # 0xb2e04
divss %xmm0, %xmm1
movss 0x663b7(%rip), %xmm0    # 0xb2e00
addss %xmm1, %xmm0
callq 0x57a80
movl 0x94224(%rip), %eax     # 0xe0c7c
movl %eax, 0x94222(%rip)     # 0xe0c80
cmpl $0x0, 0x94217(%rip)     # 0xe0c7c
je 0x4ca70
movl $0x0, -0x20(%rbp)
jmp 0x4ca79
movl 0x1a8aee(%rip), %eax    # 0x1f5564
movl %eax, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x100, -0x18(%rbp)     # imm = 0x100
jge 0x4cc39
cmpq $0x0, -0x10(%rbp)
je 0x4cb20
movq -0x10(%rbp), %rax
imull $0x3, -0x18(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x2, %eax
movb %al, %dl
movslq -0x18(%rbp), %rcx
leaq 0x42473f(%rip), %rax    # 0x471200
movb %dl, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
imull $0x3, -0x18(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x2, %eax
movb %al, %dl
movslq -0x18(%rbp), %rcx
leaq 0x42471a(%rip), %rax    # 0x471200
movb %dl, 0x1(%rax,%rcx,4)
movq -0x10(%rbp), %rax
imull $0x3, -0x18(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x2, %eax
movb %al, %dl
movslq -0x18(%rbp), %rcx
leaq 0x4246f4(%rip), %rax    # 0x471200
movb %dl, 0x2(%rax,%rcx,4)
movslq -0x18(%rbp), %rcx
leaq 0x4246e5(%rip), %rax    # 0x471200
movb $0x0, 0x3(%rax,%rcx,4)
movslq -0x20(%rbp), %rcx
leaq 0x424ed5(%rip), %rax    # 0x471a00
shlq $0x8, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rdx
leaq 0x4246c3(%rip), %rcx    # 0x471200
movzbl 0x2(%rcx,%rdx,4), %ecx
movb (%rax,%rcx), %dl
movl -0x1c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x1c(%rbp)
movslq %eax, %rcx
leaq 0x3c99d6(%rip), %rax    # 0x416530
movb %dl, (%rax,%rcx)
movslq -0x18(%rbp), %rcx
leaq 0x424a98(%rip), %rax    # 0x471600
movb %dl, 0x2(%rax,%rcx,4)
movslq -0x20(%rbp), %rcx
leaq 0x424e89(%rip), %rax    # 0x471a00
shlq $0x8, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rdx
leaq 0x424677(%rip), %rcx    # 0x471200
movzbl 0x1(%rcx,%rdx,4), %ecx
movb (%rax,%rcx), %dl
movl -0x1c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x1c(%rbp)
movslq %eax, %rcx
leaq 0x3c998a(%rip), %rax    # 0x416530
movb %dl, (%rax,%rcx)
movslq -0x18(%rbp), %rcx
leaq 0x424a4c(%rip), %rax    # 0x471600
movb %dl, 0x1(%rax,%rcx,4)
movslq -0x20(%rbp), %rcx
leaq 0x424e3d(%rip), %rax    # 0x471a00
shlq $0x8, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rdx
leaq 0x42462b(%rip), %rcx    # 0x471200
movzbl (%rcx,%rdx,4), %ecx
movb (%rax,%rcx), %dl
movl -0x1c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x1c(%rbp)
movslq %eax, %rcx
leaq 0x3c993f(%rip), %rax    # 0x416530
movb %dl, (%rax,%rcx)
movslq -0x18(%rbp), %rcx
leaq 0x424a01(%rip), %rax    # 0x471600
movb %dl, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x1c(%rbp)
movslq %eax, %rcx
leaq 0x3c9919(%rip), %rax    # 0x416530
movb $0x0, (%rax,%rcx)
movslq -0x18(%rbp), %rcx
leaq 0x4249da(%rip), %rax    # 0x471600
movb $0x0, 0x3(%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x4ca87
movsbl -0x11(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x4cc58
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
leaq 0x3c98dd(%rip), %rdx    # 0x416530
callq 0xa6950
leaq 0x5a0cc1(%rip), %rax    # 0x5ed920
cmpl $0x3, (%rax)
jne 0x4cc9d
leaq 0x424995(%rip), %rdi    # 0x471600
movl $0x400, %esi            # imm = 0x400
callq 0xa8430
movl %eax, -0x24(%rbp)
movsbl -0x11(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x4cc94
movl -0x24(%rbp), %eax
cmpl 0x425d73(%rip), %eax    # 0x472a00
je 0x4cc94
callq 0x72460
movl -0x24(%rbp), %eax
movl %eax, 0x425d63(%rip)    # 0x472a00
movb $0x0, 0x1a88fd(%rip)    # 0x1f55a1
movb $0x0, 0x1a88f5(%rip)    # 0x1f55a0
movb $0x0, 0x1a88ed(%rip)    # 0x1f559f
movb $0x0, 0x1a88ea(%rip)    # 0x1f55a3
addq $0x30, %rsp
popq %rbp
retq
nop