// File: /workspace/github_c_makefile_star2_O2/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 0xdecaf
movq %rax, %r14
leaq 0xa72bc(%rip), %rsi     # 0x11b8f4
movq %rbx, %rdi
movl $0xff, %edx
callq 0xdfae5
movl %eax, %ebp
leaq 0xa72b2(%rip), %rsi     # 0x11b900
movq %rbx, %rdi
callq 0xdfa87
movq %rax, %r15
movb $0x1, %r12b
testq %rax, %rax
jne 0x74677
leaq 0xa72a3(%rip), %rsi     # 0x11b90b
movq %rbx, %rdi
callq 0xdfa87
testq %rax, %rax
sete %r12b
leaq 0xa729a(%rip), %rsi     # 0x11b918
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
testl %eax, %eax
je 0x74698
movw $0x101, 0x2e(%r14)      # imm = 0x101
movb $0x1, 0x30(%r14)
leaq 0xa728b(%rip), %rsi     # 0x11b92a
pushq $-0x1
popq %rdx
movq %rbx, %rdi
callq 0xdfae5
testl %eax, %eax
je 0x746b4
movb $0x1, %al
jg 0x746b6
jmp 0x746ba
xorl %eax, %eax
movb %al, 0x2e(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xe404f
cmpl $0x464f524d, %eax       # imm = 0x464F524D
jne 0x747e2
movb %r12b, 0x7(%rsp)
movq 0x18(%rbx), %rdi
pushq $0x8
popq %r12
leaq 0x8(%rsp), %r13
pushq $0x4
popq %rcx
movq %r12, %rsi
movq %r13, %rdx
xorl %r8d, %r8d
callq 0xe657c
movl 0x4(%r13), %eax
movl %eax, 0x4(%r14)
leaq 0x8(%r14), %r13
leaq 0x10(%rsp), %rsi
movq %r13, %rdi
movq %r12, %rdx
callq 0xde492
movq %r13, %rdi
callq 0x180e0
cmpq $0x2, %rax
jb 0x7472b
cmpb $0x20, -0x1(%r13,%rax)
jne 0x7472b
movb $0x0, -0x1(%r13,%rax)
movl 0x4(%r14), %eax
cmpl $0x4143424d, %eax       # imm = 0x4143424D
je 0x74764
cmpl $0x5247424e, %eax       # imm = 0x5247424E
je 0x74764
cmpl $0x494c424d, %eax       # imm = 0x494C424D
je 0x74764
cmpl $0x50424d20, %eax       # imm = 0x50424D20
je 0x74764
cmpl $0x52474238, %eax       # imm = 0x52474238
je 0x74764
cmpl $0x414e494d, %eax       # imm = 0x414E494D
jne 0x74b94
movl $0x1, (%r14)
leaq 0xa7204(%rip), %rsi     # 0x11b96f
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe0824
cmpl $0x0, (%r14)
je 0x74793
leaq 0xa71f1(%rip), %rsi     # 0x11b976
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
movb %al, 0x31(%r14)
xorl %eax, %eax
cmpl $0x0, (%r14)
sete %al
cmpb $-0x1, %bpl
movzbl %bpl, %ecx
cmovel %eax, %ecx
incb %al
movb %cl, 0x2d(%r14)
movb %al, 0x2c(%r14)
testq %r15, %r15
je 0x747fb
leaq 0x8edba(%rip), %rsi     # 0x103577
movq %r15, %rdi
callq 0x181a0
testl %eax, %eax
je 0x74806
movb $0x1, %bpl
cmpb $0x0, (%r15)
je 0x74809
movq %r15, %rdi
callq 0xdfb36
testl %eax, %eax
je 0x74802
jg 0x74809
jmp 0x7480d
leaq 0xa7150(%rip), %rsi     # 0x11b939
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x74b40
cmpb $0x0, 0x7(%rsp)
jne 0x7480d
xorl %ebp, %ebp
jmp 0x74809
movb $0x2, %bpl
movb %bpl, 0x2c(%r14)
xorl %eax, %eax
cmpl $0x0, (%r14)
setne %al
movl %eax, 0x18(%r14)
movq %rbx, %rdi
callq 0xfacc0
movq %rax, %r15
movb $0x1, 0x5d(%rax)
movq %r14, 0x10(%rax)
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, 0x60(%r15)
leaq 0x368(%rip), %rax       # 0x74bad
movq %rax, 0x20(%r15)
leaq 0x1e8a(%rip), %rax      # 0x766da
movq %rax, 0x28(%r15)
leaq 0x1f64(%rip), %rax      # 0x767bf
movq %rax, 0x30(%r15)
leaq 0x205b(%rip), %rax      # 0x768c1
movq %rax, 0x38(%r15)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%r15)
movq 0x18(%rax), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0xface4
cmpq $0x0, 0xb0(%r14)
je 0x74895
movq %rbx, %rdi
movq %r14, %rsi
callq 0x768cb
movq 0x10(%r14), %r12
testq %r12, %r12
jle 0x74903
movq %r12, %rdi
callq 0xdfb87
movq %rax, %rbp
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdx
subq %rbp, %rdx
jle 0x74903
leaq 0xa7a7e(%rip), %rsi     # 0x11c33b
movq %rbx, %rdi
movq %rbp, %rcx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x785df
cmpq %r12, %rbp
je 0x748eb
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x785df
cmpb $0x0, 0x43(%r14)
je 0x74903
leaq 0xa7a7a(%rip), %rsi     # 0x11c373
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
cmpl $0x0, (%rbx)
jle 0x749ac
cmpb $0x0, 0x32(%r14)
je 0x749ac
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r12
leaq 0x933d6(%rip), %rsi     # 0x107cff
movq %rax, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x7860d
movl 0x60(%r14), %edx
leaq 0xa7a8f(%rip), %rsi     # 0x11c3d0
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
movzbl 0x69(%r14), %edx
testl %edx, %edx
je 0x74965
leaq 0xa7a7f(%rip), %rsi     # 0x11c3da
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
movzbl 0x68(%r14), %edx
leaq 0xa7a74(%rip), %rsi     # 0x11c3e5
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
leaq 0xa7a6b(%rip), %r13     # 0x11c3ed
xorl %ebp, %ebp
cmpq $0x100, %rbp            # imm = 0x100
je 0x749b4
cmpb $0x0, 0x8d4(%r14,%rbp)
je 0x749a7
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x7860d
incq %rbp
jmp 0x74984
xorl %r12d, %r12d
jmp 0x74b38
cmpb $0x0, 0x46(%r14)
je 0x749cc
leaq 0xa7a33(%rip), %rsi     # 0x11c3f5
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x45(%r14)
je 0x749e4
leaq 0xa7a25(%rip), %rsi     # 0x11c3ff
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x38(%r14)
je 0x749fc
leaq 0xa7a1b(%rip), %rsi     # 0x11c40d
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x3b(%r14)
je 0x74a14
leaq 0xa79fe(%rip), %rsi     # 0x11c408
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x3e(%r14)
je 0x74a2c
leaq 0xa79ea(%rip), %rsi     # 0x11c40c
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x40(%r14)
je 0x74a44
leaq 0xa79d7(%rip), %rsi     # 0x11c411
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x3f(%r14)
je 0x74a5c
leaq 0xa79c4(%rip), %rsi     # 0x11c416
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x41(%r14)
je 0x74a74
leaq 0xa79b1(%rip), %rsi     # 0x11c41b
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x49(%r14)
je 0x74a8c
leaq 0xa799e(%rip), %rsi     # 0x11c420
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x4a(%r14)
je 0x74aa4
leaq 0xa798c(%rip), %rsi     # 0x11c426
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x43(%r14)
je 0x74abc
leaq 0xa7919(%rip), %rsi     # 0x11c3cb
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x3c(%r14)
je 0x74ad4
leaq 0xa7961(%rip), %rsi     # 0x11c42b
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x42(%r14)
je 0x74aec
leaq 0xa7957(%rip), %rsi     # 0x11c439
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x44(%r14)
je 0x74b04
leaq 0xaaf80(%rip), %rsi     # 0x11fa7a
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
cmpb $0x0, 0x33(%r14)
jne 0x74b1c
leaq 0xa792c(%rip), %rsi     # 0x11c43e
movq %r12, %rdi
xorl %eax, %eax
callq 0x7860d
movq %r12, %rdi
callq 0xeb7e4
leaq 0xa791b(%rip), %rsi     # 0x11c446
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %r12, %rdi
callq 0xeaf3c
movq %r15, %rdi
callq 0xfacd3
testq %r14, %r14
je 0x74b85
movq 0xb0(%r14), %rsi
movq %rbx, %rdi
callq 0x7692a
movq 0xb8(%r14), %rsi
movq %rbx, %rdi
callq 0x7692a
movq 0xc0(%r14), %rsi
movq %rbx, %rdi
callq 0x7692a
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa6dae(%rip), %rsi     # 0x11b949
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xdf2a5
jmp 0x74b40