// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movl %r9d, 0x24(%rsp)
movl %r8d, %r14d
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movl 0x80(%rsp), %ebp
cmpl $0x0, 0x88(%rsp)
jne 0x10f20
movq %r12, %rdi
callq 0x100bc
testl %eax, %eax
jne 0x110f6
movq %r13, 0x30(%rsp)
movq %r12, 0x38(%rsp)
movq %rbx, 0x10(%rsp)
imull %r14d, %ebx
movq %rbx, 0x40(%rsp)
leal (,%rbx,4), %edi
callq 0x1140
movq %rax, %r13
testq %rax, %rax
sete %al
movq %r14, 0x8(%rsp)
testl %r14d, %r14d
sete %cl
orb %al, %cl
jne 0x11054
movq 0x8(%rsp), %rax
decl %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x20(%rsp)
movq 0x10(%rsp), %rax
movl %eax, %r12d
leal (,%rax,4), %eax
movl %eax, 0x1c(%rsp)
xorl %ebp, %ebp
movl $0x3, %ebx
movl $0xff, %r14d
xorl %eax, %eax
movl %eax, 0x28(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x20(%rsp), %xmm0
mulss 0x10f4(%rip), %xmm0     # 0x120a0
cvtss2sd %xmm0, %xmm0
addsd 0x3070(%rip), %xmm0     # 0x14028
callq 0x11a0
cvttsd2si %xmm0, %ecx
leal -0xff(%rcx), %eax
cmpl $0x0, 0x24(%rsp)
cmovnel %ecx, %eax
cmpl $0x0, 0x10(%rsp)
je 0x11040
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 0x10fda
movl 0x28(%rsp), %eax
incl %eax
addl 0x1c(%rsp), %ebx
cmpl 0x8(%rsp), %eax
jne 0x10f93
testq %r13, %r13
je 0x110e3
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x1140
testq %rax, %rax
je 0x110ea
movq %rax, %rbp
movq 0x30(%rsp), %rdi
movl %ebx, %esi
movq %r13, %rdx
movq %rax, %rcx
callq 0x217d
cmpl $0x0, 0x80(%rsp)
movq 0x38(%rsp), %rbx
je 0x110a4
leaq 0x32d9(%rip), %rdi      # 0x14373
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10c0
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %r15, %r8
movl %edx, %r9d
callq 0x10d7b
movq %rbp, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
movl $0x1, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x145a
jmp 0x110f2
movq %r13, %rdi
callq 0x1437
xorl %eax, %eax
jmp 0x110d4
leaq 0x2c(%rsp), %rdx
movq %r12, %rdi
movl %ebp, %esi
callq 0x13b6
testb $0x1, %al
jne 0x10f20
movl 0x2c(%rsp), %eax
jmp 0x110d4