// File: /workspace/github_c_makefile_star2_O0/tditlu[P]shadetabler/src/shadetabler.c
// Function: allocate_and_generate_shadetable
static unsigned char *allocate_and_generate_shadetable(unsigned char *palette, unsigned int colors, unsigned int shades, int light) {
	unsigned char *buffer = malloc(colors * shades * 4 * sizeof(unsigned char));
	if (buffer != NULL) {
		for (unsigned int y = 0; y < shades; y++) {
			int shade = (int)floor((((float)y) / ((float)(shades - 1)) * 255.0f) + 0.5);
			if (!light) { shade = shade - 255; }
			for (unsigned int x = 0; x < colors; x++) {
				buffer[((y * colors * 4) + (x * 4)) + 0] = (unsigned char)CLAMP(((int)palette[(x * 4) + 0]) + shade, 0, 255);
				buffer[((y * colors * 4) + (x * 4)) + 1] = (unsigned char)CLAMP(((int)palette[(x * 4) + 1]) + shade, 0, 255);
				buffer[((y * colors * 4) + (x * 4)) + 2] = (unsigned char)CLAMP(((int)palette[(x * 4) + 2]) + shade, 0, 255);
				buffer[((y * colors * 4) + (x * 4)) + 3] = 255;
			}
		}
	}
	return buffer;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl -0xc(%rbp), %eax
imull -0x10(%rbp), %eax
shll $0x2, %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x0, %rdi
callq 0x1120
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1af16
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x1af14
movl -0x24(%rbp), %eax
cvtsi2ss %rax, %xmm0
movl -0x10(%rbp), %eax
decl %eax
cvtsi2ss %rax, %xmm1
divss %xmm1, %xmm0
movss 0x31c(%rip), %xmm1      # 0x1b008
mulss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1c14(%rip), %xmm1     # 0x1c910
addsd %xmm1, %xmm0
callq 0x1180
cvttsd2si %xmm0, %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1ad1d
movl -0x28(%rbp), %eax
subl $0xff, %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x1af04
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
addl -0x28(%rbp), %eax
cmpl $0x0, %eax
jge 0x1ad52
xorl %eax, %eax
movl %eax, -0x30(%rbp)
jmp 0x1ad9a
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
addl -0x28(%rbp), %ecx
movl $0xff, %eax
cmpl %ecx, %eax
jge 0x1ad7b
movl $0xff, %eax
movl %eax, -0x34(%rbp)
jmp 0x1ad94
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
imull -0xc(%rbp), %ecx
shll $0x2, %ecx
movl -0x2c(%rbp), %esi
shll $0x2, %esi
addl %esi, %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
addl -0x28(%rbp), %eax
cmpl $0x0, %eax
jge 0x1addf
xorl %eax, %eax
movl %eax, -0x38(%rbp)
jmp 0x1ae27
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
addl -0x28(%rbp), %ecx
movl $0xff, %eax
cmpl %ecx, %eax
jge 0x1ae08
movl $0xff, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1ae21
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
imull -0xc(%rbp), %ecx
shll $0x2, %ecx
movl -0x2c(%rbp), %esi
shll $0x2, %esi
addl %esi, %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
addl -0x28(%rbp), %eax
cmpl $0x0, %eax
jge 0x1ae6c
xorl %eax, %eax
movl %eax, -0x40(%rbp)
jmp 0x1aeb4
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %ecx
addl -0x28(%rbp), %ecx
movl $0xff, %eax
cmpl %ecx, %eax
jge 0x1ae95
movl $0xff, %eax
movl %eax, -0x44(%rbp)
jmp 0x1aeae
movq -0x8(%rbp), %rax
movl -0x2c(%rbp), %ecx
shll $0x2, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
imull -0xc(%rbp), %ecx
shll $0x2, %ecx
movl -0x2c(%rbp), %esi
shll $0x2, %esi
addl %esi, %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
imull -0xc(%rbp), %ecx
shll $0x2, %ecx
movl -0x2c(%rbp), %edx
shll $0x2, %edx
addl %edx, %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movb $-0x1, (%rax,%rcx)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1ad24
jmp 0x1af06
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1acc2
jmp 0x1af16
movq -0x20(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq