// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/ilbm.c
// Function: de_run_ilbm_or_anim
static void de_run_ilbm_or_anim(deark *c, de_module_params *mparams)
{
	u32 id;
	u8 opt_notrans = 0;
	u8 opt_fixpal;
	int opt;
	const char *opt_trans_str;
	lctx *d = NULL;
	struct de_iffctx *ictx = NULL;
	struct de_fourcc formtype_4cc;

	d = de_malloc(c, sizeof(lctx));
	opt_fixpal = (u8)de_get_ext_option_bool(c, "ilbm:fixpal", 0xff);

	opt_trans_str = de_get_ext_option(c, "ilbm:trans");

	if(!opt_trans_str) {
		if(de_get_ext_option(c, "ilbm:notrans")) { // Deprecated option
			opt_notrans = 1;
		}
	}

	if(de_get_ext_option_bool(c, "ilbm:allowspecial", 0)) {
		d->opt_allowsham = 1;
		d->opt_allowdctv = 1;
		d->opt_allowhame = 1;
	}
	// allowsham is deprecated
	opt = de_get_ext_option_bool(c, "ilbm:allowsham", -1);
	if(opt==0) d->opt_allowsham = 0;
	else if(opt>0) d->opt_allowsham = 1;

	id = (u32)de_getu32be(0);
	if(id!=CODE_FORM) {
		de_err(c, "Not an IFF file");
		goto done;
	}

	dbuf_read_fourcc(c->infile, 8, &formtype_4cc, 4, 0);
	d->formtype = formtype_4cc.id;
	de_strlcpy(d->formtype_sanitized_sz, formtype_4cc.id_sanitized_sz, sizeof(d->formtype_sanitized_sz));

	// A quick hack, so we have "PBM" instead of "PBM ".
	// TODO: Maybe dbuf_read_fourcc should do this, or have an option to.
	strip_trailing_space_sz(d->formtype_sanitized_sz);

	switch(d->formtype) {
	case CODE_ANIM:
		d->is_anim = 1;
		break;
	case CODE_ILBM:
	case CODE_ACBM:
	case CODE_PBM:
	case CODE_RGBN:
	case CODE_RGB8:
		break;
	default:
		de_err(c, "Not a supported ILBM-like format (%s)", d->formtype_sanitized_sz);
		goto done;
	}
	de_declare_fmtf(c, "IFF-%s", d->formtype_sanitized_sz);

	if(d->is_anim) {
		d->opt_anim_includedups = (u8)de_get_ext_option_bool(c, "anim:includedups", 0);
	}

	if(opt_fixpal==0xff) {
		// Fixpal option defaults to No for ANIM format, othersize Yes.
		// (The concern with ANIM is that we don't want frame 1's colors
		// to fail to match frame 2's colors.)
		d->fixpal_setting = (d->is_anim ? 0 : 1);
	}
	else {
		d->fixpal_setting = opt_fixpal;
	}

	// Default for d->trans_setting
	if(d->is_anim) {
		// I don't think AUTO makes sense for ANIM.
		d->trans_setting = TRANS_RESPECT;
	}
	else {
		d->trans_setting = TRANS_AUTO;
	}

	if(opt_trans_str) {
		if(!de_strcmp(opt_trans_str, "auto")) {
			d->trans_setting = TRANS_AUTO;
		}
		else if(!de_strcmp(opt_trans_str, "")) {
			d->trans_setting = TRANS_RESPECT;
		}
		else {
			int opt_trans_n;

			opt_trans_n = de_atoi(opt_trans_str);
			if(opt_trans_n==0) {
				d->trans_setting = TRANS_REMOVE;
			}
			else if(opt_trans_n>0) {
				d->trans_setting = TRANS_RESPECT;
			}
		}
	}
	else if(opt_notrans) {
		d->trans_setting = TRANS_REMOVE;
	}

	d->FORM_level = d->is_anim ? 1 : 0;

	ictx = fmtutil_create_iff_decoder(c);
	ictx->has_standard_iff_chunks = 1;
	ictx->userdata = (void*)d;
	ictx->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_ASCII);
	ictx->handle_chunk_fn = my_iff_chunk_handler;
	ictx->preprocess_chunk_fn = my_preprocess_iff_chunk_fn;
	ictx->on_std_container_start_fn = my_on_std_container_start_fn;
	ictx->on_container_end_fn = my_on_container_end_fn;
	ictx->f = c->infile;
	fmtutil_read_iff_format(ictx, 0, c->infile->len);

	if(d->frctx) {
		on_frame_end(c, d);
	}
	do_eof_stuff(c, d);
	print_summary(c, d);

done:
	fmtutil_destroy_iff_decoder(ictx);
	if(d) {
		destroy_frame(c, d, d->frctx);
		destroy_frame(c, d, d->oldfrctx[0]);
		destroy_frame(c, d, d->oldfrctx[1]);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movl $0x9d8, %esi            # imm = 0x9D8
callq 0xe969b
movq %rax, %r14
leaq 0xafaad(%rip), %rsi     # 0x128904
movq %rbx, %rdi
movl $0xff, %edx
callq 0xea727
movl %eax, %ebp
leaq 0xafaa3(%rip), %rsi     # 0x128910
movq %rbx, %rdi
callq 0xea6cb
movq %rax, %r15
movb $0x1, %r13b
testq %rax, %rax
jne 0x78e96
leaq 0xafa94(%rip), %rsi     # 0x12891b
movq %rbx, %rdi
callq 0xea6cb
testq %rax, %rax
sete %r13b
leaq 0xafa8b(%rip), %rsi     # 0x128928
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
testl %eax, %eax
je 0x78eb7
movw $0x101, 0x2e(%r14)      # imm = 0x101
movb $0x1, 0x30(%r14)
leaq 0xafa7c(%rip), %rsi     # 0x12893a
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xea727
testl %eax, %eax
je 0x78ed5
movb $0x1, %al
jg 0x78ed7
jmp 0x78edb
xorl %eax, %eax
movb %al, 0x2e(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef32a
cmpl $0x464f524d, %eax       # imm = 0x464F524D
jne 0x78f68
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r12
movl $0x8, %esi
movq %r12, %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0xf1d74
movl 0x4(%r12), %eax
movl %eax, 0x4(%r14)
leaq 0x8(%r14), %r12
leaq 0x10(%rsp), %rsi
movl $0x8, %edx
movq %r12, %rdi
callq 0xe8ded
movq %r12, %rdi
callq 0x180e0
cmpq $0x2, %rax
jb 0x78f46
cmpb $0x20, -0x1(%r12,%rax)
jne 0x78f46
movb $0x0, -0x1(%r12,%rax)
movl 0x4(%r14), %eax
cmpl $0x50424d1f, %eax       # imm = 0x50424D1F
jg 0x78f81
cmpl $0x4143424d, %eax       # imm = 0x4143424D
je 0x78fb9
cmpl $0x414e494d, %eax       # imm = 0x414E494D
je 0x78fb2
cmpl $0x494c424d, %eax       # imm = 0x494C424D
je 0x78fb9
jmp 0x78f96
leaq 0xaf9da(%rip), %rsi     # 0x128949
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x793b3
cmpl $0x50424d20, %eax       # imm = 0x50424D20
je 0x78fb9
cmpl $0x52474238, %eax       # imm = 0x52474238
je 0x78fb9
cmpl $0x5247424e, %eax       # imm = 0x5247424E
je 0x78fb9
leaq 0xaf9bc(%rip), %rsi     # 0x128959
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9df7
jmp 0x793b3
movl $0x1, (%r14)
leaq 0xaf9bf(%rip), %rsi     # 0x12897f
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xeb703
cmpl $0x0, (%r14)
je 0x78fe8
leaq 0xaf9ac(%rip), %rsi     # 0x128986
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
movb %al, 0x31(%r14)
cmpb $-0x1, %bpl
jne 0x78ff6
cmpl $0x0, (%r14)
sete %bpl
xorl %eax, %eax
cmpl $0x1, (%r14)
adcb $0x1, %al
movb %bpl, 0x2d(%r14)
movb %al, 0x2c(%r14)
testq %r15, %r15
je 0x79037
leaq 0x97579(%rip), %rsi     # 0x11058b
movq %r15, %rdi
callq 0x181a0
testl %eax, %eax
je 0x79040
movb $0x1, %bpl
cmpb $0x0, (%r15)
je 0x79043
movq %r15, %rdi
callq 0xea781
testl %eax, %eax
je 0x7903c
jg 0x79043
jmp 0x79047
testb %r13b, %r13b
jne 0x79047
xorl %ebp, %ebp
jmp 0x79043
movb $0x2, %bpl
movb %bpl, 0x2c(%r14)
xorl %eax, %eax
cmpl $0x0, (%r14)
setne %al
movl %eax, 0x18(%r14)
movq %rbx, %rdi
callq 0x107b04
movq %rax, %r15
movb $0x1, 0x5d(%rax)
movq %r14, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xeb7d1
movl %eax, 0x60(%r15)
leaq 0x3b9(%rip), %rax       # 0x7943a
movq %rax, 0x20(%r15)
leaq 0x78f(%rip), %rax       # 0x7981b
movq %rax, 0x28(%r15)
leaq 0x8a2(%rip), %rax       # 0x79939
movq %rax, 0x30(%r15)
leaq 0x9a7(%rip), %rax       # 0x79a49
movq %rax, 0x38(%r15)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%r15)
movq 0x18(%rax), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x107b28
cmpq $0x0, 0xb0(%r14)
je 0x790d1
movq %rbx, %rdi
movq %r14, %rsi
callq 0x79a53
movq 0x10(%r14), %rbp
testq %rbp, %rbp
jle 0x7917b
movq %rbp, %rdi
callq 0xea7d5
movq %rax, %r13
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdx
subq %r13, %rdx
jle 0x7917b
leaq 0xb024a(%rip), %rsi     # 0x12934b
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xe9226
cmpb $0x0, 0x43(%r14)
jne 0x79136
movq 0x18(%rbx), %rdi
leaq 0xb02bb(%rip), %rdx     # 0x1293db
movl $0x4, %ecx
movq %rbp, %rsi
callq 0xf025e
testl %eax, %eax
jne 0x79136
movb $0x1, 0x43(%r14)
cmpq %rbp, %r13
je 0x79163
cmpb $0x0, 0x43(%r14)
jne 0x79163
movq 0x18(%rbx), %rdi
leaq 0xb028e(%rip), %rdx     # 0x1293db
movl $0x4, %ecx
movq %r13, %rsi
callq 0xf025e
testl %eax, %eax
jne 0x79163
movb $0x1, 0x43(%r14)
cmpb $0x0, 0x43(%r14)
je 0x7917b
leaq 0xb0212(%rip), %rsi     # 0x129383
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
cmpl $0x0, (%rbx)
jle 0x793a8
cmpb $0x0, 0x32(%r14)
je 0x793a8
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r13
leaq 0x9bb0e(%rip), %rsi     # 0x114caf
movq %rax, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x7d504
movl 0x60(%r14), %edx
leaq 0xb0227(%rip), %rsi     # 0x1293e0
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
movzbl 0x69(%r14), %edx
testl %edx, %edx
je 0x791dd
leaq 0xb0217(%rip), %rsi     # 0x1293ea
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
movzbl 0x68(%r14), %edx
leaq 0xb020c(%rip), %rsi     # 0x1293f5
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
leaq 0xb0203(%rip), %r12     # 0x1293fd
xorl %ebp, %ebp
cmpb $0x0, 0x8d4(%r14,%rbp)
je 0x79216
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x7d504
incq %rbp
cmpq $0x100, %rbp            # imm = 0x100
jne 0x791fc
cmpb $0x0, 0x46(%r14)
je 0x7923a
leaq 0xb01d5(%rip), %rsi     # 0x129405
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x45(%r14)
je 0x79252
leaq 0xb01c7(%rip), %rsi     # 0x12940f
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x38(%r14)
je 0x7926a
leaq 0xb01bd(%rip), %rsi     # 0x12941d
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x3b(%r14)
je 0x79282
leaq 0xb01a0(%rip), %rsi     # 0x129418
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x3e(%r14)
je 0x7929a
leaq 0xb018c(%rip), %rsi     # 0x12941c
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x40(%r14)
je 0x792b2
leaq 0xb0179(%rip), %rsi     # 0x129421
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x3f(%r14)
je 0x792ca
leaq 0xb0166(%rip), %rsi     # 0x129426
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x41(%r14)
je 0x792e2
leaq 0xb0153(%rip), %rsi     # 0x12942b
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x49(%r14)
je 0x792fa
leaq 0xb0140(%rip), %rsi     # 0x129430
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x4a(%r14)
je 0x79312
leaq 0xb012e(%rip), %rsi     # 0x129436
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x43(%r14)
je 0x7932a
leaq 0xb00bb(%rip), %rsi     # 0x1293db
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x3c(%r14)
je 0x79342
leaq 0xb0103(%rip), %rsi     # 0x12943b
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x42(%r14)
je 0x7935a
leaq 0xb00f9(%rip), %rsi     # 0x129449
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x44(%r14)
je 0x79372
leaq 0xb369a(%rip), %rsi     # 0x12ca02
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
cmpb $0x0, 0x33(%r14)
jne 0x7938a
leaq 0xb00ce(%rip), %rsi     # 0x12944e
movq %r13, %rdi
xorl %eax, %eax
callq 0x7d504
movq %r13, %rdi
callq 0xf74bd
leaq 0xb00bd(%rip), %rsi     # 0x129456
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
jmp 0x793ab
xorl %r13d, %r13d
movq %r13, %rdi
callq 0xf6bb0
movq %r15, %rdi
callq 0x107b17
testq %r14, %r14
je 0x7942b
movq 0xb0(%r14), %r15
testq %r15, %r15
je 0x793e0
movq 0x20(%r15), %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
movq 0xb8(%r14), %r15
testq %r15, %r15
je 0x79400
movq 0x20(%r15), %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
movq 0xc0(%r14), %r15
testq %r15, %r15
je 0x79420
movq 0x20(%r15), %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq