// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/ilbm.c
// Function: init_imgbody_info
static int init_imgbody_info(deark *c, lctx *d, struct imgbody_info *ibi, int is_thumb)
{
	int retval = 0;

	ibi->is_thumb = is_thumb;

	// Unlike ACBM, it would be messy and slow to convert PBM to the standard ILBM
	// frame buffer format (and back). So we support a special frame buffer format
	// just for PBM.
	ibi->is_pbm = (d->formtype==CODE_PBM);
	// We also have a special nonplanar RGB24 format (is_rgb24).

	if(d->formtype==CODE_RGBN || d->formtype==CODE_RGB8) {
		ibi->is_rgb24 = 1;
		if(((d->formtype==CODE_RGBN && d->planes_raw==13) ||
			(d->formtype==CODE_RGB8 && d->planes_raw==25)) &&
			(d->compression==3 || d->compression==4) &&
			d->masking_code==MASKINGTYPE_NONE)
		{
			;
		}
		else {
			de_err(c, "Unsupported RGBN/RGB8 format");
			goto done;
		}
	}

	if(is_thumb) {
		ibi->width = d->thumb_width;
		ibi->height = d->thumb_height;
	}
	else {
		ibi->width = d->width;
		ibi->height = d->height;
	}

	// Quick & dirty support for -padpix.
	// TODO: Some of these conditions could be removed, with care.
	if(c->padpix && (d->width%16) && !is_thumb && !d->is_anim && d->formtype==CODE_ILBM &&
		!d->ham_flag)
	{
		ibi->width = de_pad_to_n(ibi->width, 16);
	}

	ibi->compression = d->compression;

	ibi->masking_code = d->masking_code;
	// Based on what little data I have, it seems that TINY images do not have
	// a transparency mask, even if the main image does.
	if(is_thumb && ibi->masking_code==MASKINGTYPE_1BITMASK) {
		ibi->masking_code = MASKINGTYPE_NONE;
	}

	if(d->planes_raw==24) {
		ibi->colortype = COLORTYPE_RGB24;
	}
	else {
		ibi->colortype = COLORTYPE_DEFAULT;
	}

	if(ibi->is_pbm || ibi->is_rgb24) {
		ibi->planes_fg = 1;
		ibi->planes_total = 1;
	}
	else {
		ibi->planes_fg = d->planes_raw;
		ibi->planes_total = d->planes_raw;
		if(ibi->masking_code==MASKINGTYPE_1BITMASK) {
			ibi->planes_total++;
		}
	}
	ibi->transparent_color = d->transparent_color;
	ibi->x_aspect = d->x_aspect;
	ibi->y_aspect = d->y_aspect;

	if(ibi->is_pbm) {
		if(d->planes_raw!=8 || d->masking_code==MASKINGTYPE_1BITMASK) {
			de_err(c, "Not a supported PBM format");
			goto done;
		}
	}

	if(ibi->is_pbm) {
		ibi->bytes_per_row_per_plane = ibi->width;
		if(ibi->bytes_per_row_per_plane%2) {
			ibi->bytes_per_row_per_plane++;
		}
		ibi->bits_per_row_per_plane = ibi->bytes_per_row_per_plane * 8;
		// Note: The PBM row size might be adjusted later, after decompression.
	}
	else if(ibi->is_rgb24) {
		ibi->bytes_per_row_per_plane = ibi->width*3;
		ibi->bits_per_row_per_plane = ibi->bytes_per_row_per_plane * 8;
	}
	else {
		ibi->bits_per_row_per_plane = de_pad_to_n(ibi->width, 16);
		ibi->bytes_per_row_per_plane = ibi->bits_per_row_per_plane/8;
	}
	ibi->frame_buffer_rowspan = ibi->bytes_per_row_per_plane * ibi->planes_total;
	ibi->frame_buffer_size = ibi->frame_buffer_rowspan * ibi->height;

	if(ibi->masking_code==MASKINGTYPE_NONE) {
		;
	}
	else if(ibi->masking_code==MASKINGTYPE_COLORKEY) {
		if(ibi->planes_fg<=8 && !d->ham_flag) {
			ibi->use_colorkey_transparency = 1;
		}
	}
	else if(ibi->masking_code==MASKINGTYPE_1BITMASK) {
		;
	}
	else {
		de_warn(c, "This type of transparency is not supported");
	}

	if(ibi->use_colorkey_transparency && ibi->transparent_color<=255) {
		d->pal[ibi->transparent_color] = DE_SET_ALPHA(d->pal[ibi->transparent_color], 0);
	}

	if(ibi->colortype==COLORTYPE_RGB24) {
		;
	}
	else if(ibi->planes_fg<1 || ibi->planes_fg>8) {
		de_err(c, "Bad or unsupported number of planes: %d", (int)ibi->planes_fg);
		goto done;
	}
	retval = 1;

done:
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x10(%rbp), %rax
cmpl $0x50424d20, 0x4(%rax)  # imm = 0x50424D20
sete %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x60(%rax)
movq -0x10(%rbp), %rax
cmpl $0x5247424e, 0x4(%rax)  # imm = 0x5247424E
je 0xb231e
movq -0x10(%rbp), %rax
cmpl $0x52474238, 0x4(%rax)  # imm = 0x52474238
jne 0xb2398
movq -0x18(%rbp), %rax
movb $0x1, 0x61(%rax)
movq -0x10(%rbp), %rax
cmpl $0x5247424e, 0x4(%rax)  # imm = 0x5247424E
jne 0xb233e
movq -0x10(%rbp), %rax
cmpq $0xd, 0x60(%rax)
je 0xb2356
movq -0x10(%rbp), %rax
cmpl $0x52474238, 0x4(%rax)  # imm = 0x52474238
jne 0xb237f
movq -0x10(%rbp), %rax
cmpq $0x19, 0x60(%rax)
jne 0xb237f
movq -0x10(%rbp), %rax
movzbl 0x68(%rax), %eax
cmpl $0x3, %eax
je 0xb2370
movq -0x10(%rbp), %rax
movzbl 0x68(%rax), %eax
cmpl $0x4, %eax
jne 0xb237f
movq -0x10(%rbp), %rax
movzbl 0x69(%rax), %eax
cmpl $0x0, %eax
jne 0xb237f
jmp 0xb2396
movq -0x8(%rbp), %rdi
leaq 0x102477(%rip), %rsi    # 0x1b4801
movb $0x0, %al
callq 0x15bfb0
jmp 0xb2767
jmp 0xb2398
cmpl $0x0, -0x1c(%rbp)
je 0xb23c5
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xb23e4
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movzbl 0xd5(%rax), %eax
cmpl $0x0, %eax
je 0xb244d
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl $0x10, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0xb244d
cmpl $0x0, -0x1c(%rbp)
jne 0xb244d
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xb244d
movq -0x10(%rbp), %rax
cmpl $0x494c424d, 0x4(%rax)  # imm = 0x494C424D
jne 0xb244d
movq -0x10(%rbp), %rax
cmpb $0x0, 0x38(%rax)
jne 0xb244d
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0x10, %esi
callq 0x15ce90
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movb 0x68(%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x20(%rax)
movq -0x10(%rbp), %rax
movb 0x69(%rax), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x21(%rax)
cmpl $0x0, -0x1c(%rbp)
je 0xb2484
movq -0x18(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x1, %eax
jne 0xb2484
movq -0x18(%rbp), %rax
movb $0x0, 0x21(%rax)
movq -0x10(%rbp), %rax
cmpq $0x18, 0x60(%rax)
jne 0xb249c
movq -0x18(%rbp), %rax
movl $0x1, 0x58(%rax)
jmp 0xb24a7
movq -0x18(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x18(%rbp), %rax
movzbl 0x60(%rax), %eax
cmpl $0x0, %eax
jne 0xb24c1
movq -0x18(%rbp), %rax
movzbl 0x61(%rax), %eax
cmpl $0x0, %eax
je 0xb24db
movq -0x18(%rbp), %rax
movq $0x1, 0x10(%rax)
movq -0x18(%rbp), %rax
movq $0x1, 0x18(%rax)
jmp 0xb251a
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x1, %eax
jne 0xb2518
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
jmp 0xb251a
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x60(%rax)
je 0xb2583
movq -0x10(%rbp), %rax
cmpq $0x8, 0x60(%rax)
jne 0xb256a
movq -0x10(%rbp), %rax
movzbl 0x69(%rax), %eax
cmpl $0x1, %eax
jne 0xb2581
movq -0x8(%rbp), %rdi
leaq 0x1022a9(%rip), %rsi    # 0x1b481e
movb $0x0, %al
callq 0x15bfb0
jmp 0xb2767
jmp 0xb2583
movq -0x18(%rbp), %rax
cmpb $0x0, 0x60(%rax)
je 0xb25da
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movl $0x2, %ecx
cqto
idivq %rcx
cmpq $0x0, %rdx
je 0xb25c4
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
shlq $0x3, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
jmp 0xb2645
movq -0x18(%rbp), %rax
cmpb $0x0, 0x61(%rax)
je 0xb260a
movq -0x18(%rbp), %rax
imulq $0x3, (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
shlq $0x3, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
jmp 0xb2643
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movl $0x10, %esi
callq 0x15ce90
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0xb2645
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x18(%rbp), %rax
imulq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x18(%rbp), %rax
imulq 0x8(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x0, %eax
jne 0xb2686
jmp 0xb26d7
movq -0x18(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x2, %eax
jne 0xb26b2
movq -0x18(%rbp), %rax
cmpq $0x8, 0x10(%rax)
jg 0xb26b0
movq -0x10(%rbp), %rax
cmpb $0x0, 0x38(%rax)
jne 0xb26b0
movq -0x18(%rbp), %rax
movb $0x1, 0x22(%rax)
jmp 0xb26d5
movq -0x18(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x1, %eax
jne 0xb26c1
jmp 0xb26d3
movq -0x8(%rbp), %rdi
leaq 0x10216d(%rip), %rsi    # 0x1b4839
movb $0x0, %al
callq 0x15bc10
jmp 0xb26d5
jmp 0xb26d7
movq -0x18(%rbp), %rax
movzbl 0x22(%rax), %eax
cmpl $0x0, %eax
je 0xb271e
movq -0x18(%rbp), %rax
cmpl $0xff, 0x24(%rax)
ja 0xb271e
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x24(%rcx), %ecx
movl 0x4d4(%rax,%rcx,4), %edx
andl $0xffffff, %edx         # imm = 0xFFFFFF
orl $0x0, %edx
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x24(%rcx), %ecx
movl %edx, 0x4d4(%rax,%rcx,4)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x58(%rax)
jne 0xb272a
jmp 0xb2760
movq -0x18(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jl 0xb2740
movq -0x18(%rbp), %rax
cmpq $0x8, 0x10(%rax)
jle 0xb275e
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %edx
leaq 0x10210f(%rip), %rsi    # 0x1b4864
movb $0x0, %al
callq 0x15bfb0
jmp 0xb2767
jmp 0xb2760
movl $0x1, -0x20(%rbp)
movl -0x20(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq