// File: /workspace/github_c_makefile_star2_O0/tditlu[P]shadetabler/src/shadetabler.c
// Function: save_image
static void save_image(const char *filename, unsigned char *buffer, unsigned int width, unsigned int height, unsigned char *palette, unsigned int colors) {
	LodePNGState state;
	lodepng_state_init(&state);
	state.info_raw.colortype = LCT_PALETTE;
	state.info_raw.bitdepth = 8;
	state.info_png.color.colortype = LCT_PALETTE;
	state.info_png.color.bitdepth = 8;

	state.encoder.filter_palette_zero = 0;
	state.encoder.filter_strategy = LFS_ZERO;
	state.encoder.auto_convert = 0;
	state.encoder.force_palette = 1;

	unsigned char *p = palette;
	for (unsigned int i = 0; i < colors; i++) {
		lodepng_palette_add(&state.info_png.color, p[0], p[1], p[2], p[3]);
		lodepng_palette_add(&state.info_raw, p[0], p[1], p[2], p[3]);
		p += 4;
	}

	unsigned char *output_file_data;
	size_t output_file_size;
	unsigned int status = lodepng_encode(&output_file_data, &output_file_size, buffer, width, height, &state);
	if (status) {
		fprintf(stderr, "Can't encode image: %s\n", lodepng_error_text(status));
		goto error;
	}

	FILE *fp = fopen(filename, "wb");
	if (!fp) {
		fprintf(stderr, "Unable to write to %s\n", filename);
		goto error;
	}
	fwrite(output_file_data, 1, output_file_size, fp);
	fclose(fp);

error:
	lodepng_state_cleanup(&state);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
leaq -0x220(%rbp), %rdi
callq 0xd100
movl $0x3, -0x190(%rbp)
movl $0x8, -0x18c(%rbp)
movl $0x3, -0x158(%rbp)
movl $0x8, -0x154(%rbp)
movl $0x0, -0x1b4(%rbp)
movl $0x0, -0x1b0(%rbp)
movl $0x0, -0x1b8(%rbp)
movl $0x1, -0x1a0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x228(%rbp)
movl $0x0, -0x22c(%rbp)
movl -0x22c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x1a8a9
leaq -0x220(%rbp), %rdi
addq $0xb8, %rdi
addq $0x10, %rdi
movq -0x228(%rbp), %rax
movb (%rax), %sil
movq -0x228(%rbp), %rax
movb 0x1(%rax), %dl
movq -0x228(%rbp), %rax
movb 0x2(%rax), %cl
movq -0x228(%rbp), %rax
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl 0x3(%rax), %r8d
callq 0x64d0
leaq -0x220(%rbp), %rdi
addq $0x90, %rdi
movq -0x228(%rbp), %rax
movb (%rax), %sil
movq -0x228(%rbp), %rax
movb 0x1(%rax), %dl
movq -0x228(%rbp), %rax
movb 0x2(%rax), %cl
movq -0x228(%rbp), %rax
movzbl %sil, %esi
movzbl %dl, %edx
movzbl %cl, %ecx
movzbl 0x3(%rax), %r8d
callq 0x64d0
movq -0x228(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x228(%rbp)
movl -0x22c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x22c(%rbp)
jmp 0x1a7e2
movq -0x10(%rbp), %rdx
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
leaq -0x238(%rbp), %rdi
leaq -0x240(%rbp), %rsi
leaq -0x220(%rbp), %r9
callq 0xd4f0
movl %eax, -0x244(%rbp)
cmpl $0x0, -0x244(%rbp)
je 0x1a913
movq 0x7714(%rip), %rax      # 0x21ff8
movq (%rax), %rax
movq %rax, -0x258(%rbp)
movl -0x244(%rbp), %edi
callq 0xff00
movq -0x258(%rbp), %rdi
movq %rax, %rdx
leaq 0x27b6(%rip), %rsi      # 0x1d0c0
movb $0x0, %al
callq 0x10e0
jmp 0x1a97d
movq -0x8(%rbp), %rdi
leaq 0xc67(%rip), %rsi       # 0x1b585
callq 0x1170
movq %rax, -0x250(%rbp)
cmpq $0x0, -0x250(%rbp)
jne 0x1a952
movq 0x76bd(%rip), %rax      # 0x21ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x278f(%rip), %rsi      # 0x1d0d8
movb $0x0, %al
callq 0x10e0
jmp 0x1a97d
movq -0x238(%rbp), %rdi
movq -0x240(%rbp), %rdx
movq -0x250(%rbp), %rcx
movl $0x1, %esi
callq 0x11b0
movq -0x250(%rbp), %rdi
callq 0x1070
leaq -0x220(%rbp), %rdi
callq 0xd160
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
nopw %cs:(%rax,%rax)