// File: /workspace/github_c_makefile_star2_O1/tditlu[P]shadetabler/src/shadetabler.c
// Function: allocate_generate_and_save_shadetable
static int allocate_generate_and_save_shadetable(exq_data *exq, char *path, unsigned char *palette, unsigned int colors, unsigned int shades, int light, int verbose, int force) {
	int write_shadetable = 1;
	if (!force && path_file_exists(path)) {
		fprintf(stderr,"File '%s' already exists. Overwrite? [y/N] ", path);
		fflush(stderr);
		int c = getchar();
		write_shadetable = (c == 'y' || c == 'Y') ? 1 : 0;
		while (c != '\n' && c != EOF) { c = getchar(); }
	}

	if (write_shadetable) {
		unsigned char *buffer_rgba = allocate_and_generate_shadetable(palette, colors, shades, light);
		if (buffer_rgba != NULL) {
			unsigned char *buffer_8bit = malloc(colors * shades * sizeof(unsigned char));
			if (buffer_8bit != NULL) {
				exq_map_image(exq, colors * shades, buffer_rgba, buffer_8bit);

				if (verbose) {
					printf("Saving image \"%s\"\n", path);
				}

				save_image(path, buffer_8bit, colors, shades, palette, colors);
				free(buffer_8bit);
			} else {
				free(buffer_rgba);
				fprintf(stderr, "Unable to allocate memory for shadetable.\n");
				return 0;
			}
			free(buffer_rgba);
		} else {
			fprintf(stderr, "Unable to allocate memory for shadetable.\n");
			return 0;
		}
	} else {
		if (verbose) {
			printf("Skipping image \"%s\"\n", path);
		}
	}
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, 0x18(%rsp)
movl %r8d, %r14d
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movl 0x70(%rsp), %ebp
cmpl $0x0, 0x78(%rsp)
jne 0x113b7
movq %r12, %rdi
callq 0x10498
testl %eax, %eax
jne 0x11587
movq %r13, 0x20(%rsp)
movq %r12, 0x28(%rsp)
movq %rbx, 0x8(%rsp)
imull %r14d, %ebx
movq %rbx, 0x30(%rsp)
leal (,%rbx,4), %edi
callq 0x1140
movq %rax, %r13
testq %rax, %rax
sete %al
movq %r14, (%rsp)
testl %r14d, %r14d
sete %cl
orb %al, %cl
jne 0x114e8
movq (%rsp), %rax
decl %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x14(%rsp)
movq 0x8(%rsp), %rax
movl %eax, %r12d
leal (,%rax,4), %eax
movl %eax, 0x10(%rsp)
xorl %ebp, %ebp
movl $0x3, %ebx
movl $0xff, %r14d
xorl %eax, %eax
movl %eax, 0x1c(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x14(%rsp), %xmm0
mulss 0xbff(%rip), %xmm0      # 0x12040
cvtss2sd %xmm0, %xmm0
addsd 0x2ae3(%rip), %xmm0     # 0x13f30
callq 0x11a0
cvttsd2si %xmm0, %ecx
leal -0xff(%rcx), %eax
cmpl $0x0, 0x18(%rsp)
cmovnel %ecx, %eax
cmpl $0x0, 0x8(%rsp)
je 0x114d5
movl %ebx, %ecx
xorl %edx, %edx
movzbl (%r15,%rdx,4), %esi
addl %eax, %esi
cmpl %r14d, %esi
cmovgel %r14d, %esi
testl %esi, %esi
cmovlel %ebp, %esi
leal -0x3(%rcx), %edi
movb %sil, (%r13,%rdi)
movzbl 0x1(%r15,%rdx,4), %esi
addl %eax, %esi
cmpl %r14d, %esi
cmovgel %r14d, %esi
testl %esi, %esi
cmovlel %ebp, %esi
leal -0x2(%rcx), %edi
movb %sil, (%r13,%rdi)
movzbl 0x2(%r15,%rdx,4), %esi
addl %eax, %esi
cmpl %r14d, %esi
cmovgel %r14d, %esi
testl %esi, %esi
cmovlel %ebp, %esi
leal -0x1(%rcx), %edi
movb %sil, (%r13,%rdi)
movl %ecx, %esi
movb $-0x1, (%r13,%rsi)
incq %rdx
addl $0x4, %ecx
cmpq %rdx, %r12
jne 0x1146f
movl 0x1c(%rsp), %eax
incl %eax
addl 0x10(%rsp), %ebx
cmpl (%rsp), %eax
jne 0x11428
testq %r13, %r13
je 0x11567
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x1140
movq %rax, %rbp
testq %rax, %rax
je 0x1157d
movq 0x20(%rsp), %rdi
movl %ebx, %esi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x2363
cmpl $0x0, 0x70(%rsp)
movq 0x28(%rsp), %rbx
je 0x11531
leaq 0x2d24(%rip), %rdi      # 0x1424b
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10c0
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
movq %r15, %r8
movl %edx, %r9d
callq 0x11218
movq %rbp, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
testq %rbp, %rbp
je 0x1156c
movl $0x1, %eax
jmp 0x1156e
callq 0x1448
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x1425
jmp 0x1155b
movq %r12, %rdi
movl %ebp, %esi
callq 0x13b6
testb $0x1, %al
jne 0x113b7
jmp 0x11560