// File: /workspace/github_c_makefile_star2_O2/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, 0x8(%rsp)
movl %r8d, %ebp
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
cmpl $0x0, 0x78(%rsp)
jne 0xeb77
movq %r14, %rdi
callq 0xdd70
testl %eax, %eax
jne 0xed42
movl %r15d, %eax
imull %ebp, %eax
movq %rax, 0x30(%rsp)
leal (,%rax,4), %edi
callq 0x1130
testq %rax, %rax
je 0xed22
movq %rax, %r13
movq %rbx, 0x18(%rsp)
movq %r14, 0x28(%rsp)
movq %rbp, 0x10(%rsp)
leal -0x1(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, 0x4(%rsp)
movl %r15d, %ebx
movq %r15, 0x20(%rsp)
leal (,%r15,4), %eax
movl %eax, (%rsp)
xorl %r15d, %r15d
pushq $0x3
popq %rbp
movl $0xff, %r14d
xorl %eax, %eax
cmpl 0x10(%rsp), %eax
je 0xec97
movl %eax, 0xc(%rsp)
cvtsi2ss %eax, %xmm0
divss 0x4(%rsp), %xmm0
mulss 0x4a9(%rip), %xmm0      # 0xf0a0
cvtss2sd %xmm0, %xmm0
addsd 0x233d(%rip), %xmm0     # 0x10f40
callq 0x1190
cvttsd2si %xmm0, %ecx
leal -0xff(%rcx), %eax
cmpl $0x0, 0x8(%rsp)
cmovnel %ecx, %eax
movl %ebp, %ecx
xorl %edx, %edx
cmpq %rdx, %rbx
je 0xec89
movzbl (%r12,%rdx,4), %esi
addl %eax, %esi
cmpl %r14d, %esi
cmovgel %r14d, %esi
testl %esi, %esi
cmovlel %r15d, %esi
leal -0x3(%rcx), %edi
movb %sil, (%r13,%rdi)
movzbl 0x1(%r12,%rdx,4), %esi
addl %eax, %esi
cmpl %r14d, %esi
cmovgel %r14d, %esi
testl %esi, %esi
cmovlel %r15d, %esi
leal -0x2(%rcx), %edi
movb %sil, (%r13,%rdi)
movzbl 0x2(%r12,%rdx,4), %esi
addl %eax, %esi
cmpl %r14d, %esi
cmovgel %r14d, %esi
testl %esi, %esi
cmovlel %r15d, %esi
leal -0x1(%rcx), %edi
movb %sil, (%r13,%rdi)
movl %ecx, %esi
movb $-0x1, (%r13,%rsi)
incq %rdx
addl $0x4, %ecx
jmp 0xec1e
movl 0xc(%rsp), %eax
incl %eax
addl (%rsp), %ebp
jmp 0xebd7
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x1130
testq %rax, %rax
je 0xed1a
movq %rax, %rbp
movq 0x18(%rsp), %rdi
movl %ebx, %esi
movq %r13, %rdx
movq %rax, %rcx
callq 0x1e91
cmpl $0x0, 0x70(%rsp)
movq 0x28(%rsp), %rbx
je 0xecdb
leaq 0x25b2(%rip), %rdi      # 0x11283
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10c0
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r12, %r8
movl %edx, %r9d
callq 0xe9db
movq %rbp, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x1030
movq 0x82cf(%rip), %rax      # 0x16ff8
movq (%rax), %rcx
leaq 0x2578(%rip), %rdi      # 0x112ab
pushq $0x2a
popq %rsi
pushq $0x1
popq %rdx
callq 0x11c0
xorl %ebx, %ebx
jmp 0xed09
movq %rbx, %r13
movq 0x82ac(%rip), %rbx      # 0x16ff8
movq (%rbx), %rdi
leaq 0x24d6(%rip), %rsi      # 0x1122c
movq %r14, %rdx
xorl %eax, %eax
callq 0x1100
movq (%rbx), %rdi
callq 0x1140
callq 0x10f0
movl %eax, %ebx
andl $-0x21, %ebx
cmpl $-0x1, %eax
je 0xed83
cmpl $0xa, %eax
je 0xed83
callq 0x10f0
jmp 0xed72
cmpl $0x59, %ebx
movq %r13, %rbx
je 0xeb77
pushq $0x1
popq %rbx
cmpl $0x0, 0x70(%rsp)
je 0xed09
leaq 0x24f2(%rip), %rdi      # 0x11296
movq %r14, %rsi
xorl %eax, %eax
callq 0x10c0
jmp 0xed09