// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/ilbm.c
// Function: do_before_image_chunk
static void do_before_image_chunk(deark *c, lctx *d)
{
	if(d->bmhd_changed_flag || d->camg_changed_flag) {
		if(d->ham_flag) {
			if(d->planes_raw==6 || d->planes_raw==5) {
				d->is_ham6 = 1;
			}
			else if(d->planes_raw==8 || d->planes_raw==7) {
				d->is_ham8 = 1;
			}
			else {
				de_warn(c, "Invalid bit depth (%d) for HAM image.", (int)d->planes_raw);
			}
		}

		if(!d->found_cmap && d->planes_raw<=8) {
			de_make_grayscale_palette(d->pal, (i64)1<<(UI)d->planes_raw, 0);
		}

		if(d->planes_raw==6 && d->pal_ncolors==32 && !d->ehb_flag && !d->ham_flag) {
			de_warn(c, "Assuming this is an EHB image");
			d->ehb_flag = 1;
		}
	}

	if(d->cmap_changed_flag) {
		de_memcpy(d->pal, d->pal_raw, (size_t)d->pal_ncolors * sizeof(d->pal_raw[0]));
	}

	if(d->cmap_changed_flag && d->ehb_flag && d->planes_raw==6) {
		UI k;

		// TODO: Should we still do this if the palette already has 64 colors
		// (as it often does)?
		for(k=0; k<32; k++) {
			u8 cr, cg, cb;

			cr = DE_COLOR_R(d->pal[k]);
			cg = DE_COLOR_G(d->pal[k]);
			cb = DE_COLOR_B(d->pal[k]);
			d->pal[k+32] = DE_MAKE_RGB(cr/2, cg/2, cb/2);
		}
	}

	if(d->fixpal_setting && d->cmap_changed_flag) {
		fixup_palette(c, d);
	}

	if(d->cmap_changed_flag) {
		d->pal_is_grayscale = de_is_grayscale_palette(d->pal, 256);
	}

	d->cmap_changed_flag = 0;
	d->bmhd_changed_flag = 0;
	d->camg_changed_flag = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x35(%rax), %eax
cmpl $0x0, %eax
jne 0xb203e
movq -0x10(%rbp), %rax
movzbl 0x36(%rax), %eax
cmpl $0x0, %eax
je 0xb212c
movq -0x10(%rbp), %rax
cmpb $0x0, 0x38(%rax)
je 0xb20a8
movq -0x10(%rbp), %rax
cmpq $0x6, 0x60(%rax)
je 0xb205e
movq -0x10(%rbp), %rax
cmpq $0x5, 0x60(%rax)
jne 0xb2068
movq -0x10(%rbp), %rax
movb $0x1, 0x39(%rax)
jmp 0xb20a6
movq -0x10(%rbp), %rax
cmpq $0x8, 0x60(%rax)
je 0xb207e
movq -0x10(%rbp), %rax
cmpq $0x7, 0x60(%rax)
jne 0xb2088
movq -0x10(%rbp), %rax
movb $0x1, 0x3a(%rax)
jmp 0xb20a4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl %eax, %edx
leaq 0x1026e2(%rip), %rsi    # 0x1b477f
movb $0x0, %al
callq 0x15bc10
jmp 0xb20a6
jmp 0xb20a8
movq -0x10(%rbp), %rax
cmpb $0x0, 0x33(%rax)
jne 0xb20e3
movq -0x10(%rbp), %rax
cmpq $0x8, 0x60(%rax)
jg 0xb20e3
movq -0x10(%rbp), %rdi
addq $0x4d4, %rdi            # imm = 0x4D4
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %esi
shlq %cl, %rsi
xorl %edx, %edx
callq 0x16d580
movq -0x10(%rbp), %rax
cmpq $0x6, 0x60(%rax)
jne 0xb212a
movq -0x10(%rbp), %rax
cmpq $0x20, 0xc8(%rax)
jne 0xb212a
movq -0x10(%rbp), %rax
cmpb $0x0, 0x3b(%rax)
jne 0xb212a
movq -0x10(%rbp), %rax
cmpb $0x0, 0x38(%rax)
jne 0xb212a
movq -0x8(%rbp), %rdi
leaq 0x10268a(%rip), %rsi    # 0x1b47a5
movb $0x0, %al
callq 0x15bc10
movq -0x10(%rbp), %rax
movb $0x1, 0x3b(%rax)
jmp 0xb212c
movq -0x10(%rbp), %rax
cmpb $0x0, 0x34(%rax)
je 0xb2160
movq -0x10(%rbp), %rdi
addq $0x4d4, %rdi            # imm = 0x4D4
movq -0x10(%rbp), %rsi
addq $0xd4, %rsi
movq -0x10(%rbp), %rax
movq 0xc8(%rax), %rdx
shlq $0x2, %rdx
callq 0x191e0
movq -0x10(%rbp), %rax
movzbl 0x34(%rax), %eax
cmpl $0x0, %eax
je 0xb224e
movq -0x10(%rbp), %rax
movzbl 0x3b(%rax), %eax
cmpl $0x0, %eax
je 0xb224e
movq -0x10(%rbp), %rax
cmpq $0x6, 0x60(%rax)
jne 0xb224e
movl $0x0, -0x14(%rbp)
cmpl $0x20, -0x14(%rbp)
jae 0xb224c
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl 0x4d4(%rax,%rcx,4), %eax
shrl $0x10, %eax
andl $0xff, %eax
movb %al, -0x15(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl 0x4d4(%rax,%rcx,4), %eax
shrl $0x8, %eax
andl $0xff, %eax
movb %al, -0x16(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
movl 0x4d4(%rax,%rcx,4), %eax
andl $0xff, %eax
movb %al, -0x17(%rbp)
movzbl -0x15(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
shll $0x10, %eax
orl $0xff000000, %eax       # imm = 0xFF000000
movl %eax, -0x20(%rbp)
movzbl -0x16(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x20(%rbp), %eax
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, -0x1c(%rbp)
movzbl -0x17(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl -0x1c(%rbp), %edx
orl %eax, %edx
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x20, %ecx
movl %ecx, %ecx
movl %edx, 0x4d4(%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb2198
jmp 0xb224e
movq -0x10(%rbp), %rax
movzbl 0x2d(%rax), %eax
cmpl $0x0, %eax
je 0xb2275
movq -0x10(%rbp), %rax
movzbl 0x34(%rax), %eax
cmpl $0x0, %eax
je 0xb2275
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xb3680
movq -0x10(%rbp), %rax
cmpb $0x0, 0x34(%rax)
je 0xb22a0
movq -0x10(%rbp), %rdi
addq $0x4d4, %rdi            # imm = 0x4D4
movl $0x100, %esi            # imm = 0x100
callq 0x16aa20
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xd0(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x34(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x35(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x36(%rax)
addq $0x20, %rsp
popq %rbp
retq
nop