// File: /workspace/github_c_makefile_star2_O3/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 0xe8b2b
movq %rax, %r14
leaq 0xb00b9(%rip), %rsi     # 0x128b34
movq %rbx, %rdi
movl $0xff, %edx
callq 0xe9bd0
movl %eax, %ebp
leaq 0xb00af(%rip), %rsi     # 0x128b40
movq %rbx, %rdi
callq 0xe9b74
movq %rax, %r15
movb $0x1, %r13b
testq %rax, %rax
jne 0x78aba
leaq 0xb00a0(%rip), %rsi     # 0x128b4b
movq %rbx, %rdi
callq 0xe9b74
testq %rax, %rax
sete %r13b
leaq 0xb0097(%rip), %rsi     # 0x128b58
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe9bd0
testl %eax, %eax
je 0x78adb
movw $0x101, 0x2e(%r14)      # imm = 0x101
movb $0x1, 0x30(%r14)
leaq 0xb0088(%rip), %rsi     # 0x128b6a
movq %rbx, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xe9bd0
testl %eax, %eax
je 0x78af9
movb $0x1, %al
jg 0x78afb
jmp 0x78aff
xorl %eax, %eax
movb %al, 0x2e(%r14)
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeed0d
cmpl $0x464f524d, %eax       # imm = 0x464F524D
jne 0x78b8f
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %r12
movl $0x8, %esi
movq %r12, %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0xf1762
movl 0x4(%r12), %eax
movl %eax, 0x4(%r14)
movq %r14, %r12
addq $0x8, %r12
leaq 0x10(%rsp), %rsi
movl $0x8, %edx
movq %r12, %rdi
callq 0xe8219
movq %r12, %rdi
callq 0x180e0
cmpq $0x2, %rax
jb 0x78b6d
cmpb $0x20, -0x1(%r12,%rax)
jne 0x78b6d
movb $0x0, -0x1(%r12,%rax)
movl 0x4(%r14), %eax
cmpl $0x50424d1f, %eax       # imm = 0x50424D1F
jg 0x78bb5
cmpl $0x4143424d, %eax       # imm = 0x4143424D
je 0x78bed
cmpl $0x414e494d, %eax       # imm = 0x414E494D
je 0x78be6
cmpl $0x494c424d, %eax       # imm = 0x494C424D
je 0x78bed
jmp 0x78bca
leaq 0xaffe3(%rip), %rsi     # 0x128b79
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
xorl %edi, %edi
callq 0x1075d3
testq %r14, %r14
jne 0x78ff1
jmp 0x79029
cmpl $0x50424d20, %eax       # imm = 0x50424D20
je 0x78bed
cmpl $0x52474238, %eax       # imm = 0x52474238
je 0x78bed
cmpl $0x5247424e, %eax       # imm = 0x5247424E
je 0x78bed
leaq 0xaffb8(%rip), %rsi     # 0x128b89
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9295
jmp 0x78fe9
movl $0x1, (%r14)
leaq 0xaffbb(%rip), %rsi     # 0x128baf
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xeb152
cmpl $0x0, (%r14)
je 0x78c1c
leaq 0xaffa8(%rip), %rsi     # 0x128bb6
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe9bd0
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 0x78c6b
leaq 0x97931(%rip), %rsi     # 0x110577
movq %r15, %rdi
callq 0x181a0
testl %eax, %eax
je 0x78c74
movb $0x1, %bpl
cmpb $0x0, (%r15)
je 0x78c77
movq %r15, %rdi
callq 0xe9c2a
testl %eax, %eax
je 0x78c70
jg 0x78c77
jmp 0x78c7b
testb %r13b, %r13b
jne 0x78c7b
xorl %ebp, %ebp
jmp 0x78c77
movb $0x2, %bpl
movb %bpl, 0x2c(%r14)
xorl %eax, %eax
cmpl $0x0, (%r14)
setne %al
movl %eax, 0x18(%r14)
movq %rbx, %rdi
callq 0x1075c0
movq %rax, %r15
movb $0x1, 0x5d(%rax)
movq %r14, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xeb220
movl %eax, 0x60(%r15)
leaq 0x383(%rip), %rax       # 0x79038
movq %rax, 0x20(%r15)
leaq 0x758(%rip), %rax       # 0x79418
movq %rax, 0x28(%r15)
leaq 0x857(%rip), %rax       # 0x79522
movq %rax, 0x30(%r15)
leaq 0x95c(%rip), %rax       # 0x79632
movq %rax, 0x38(%r15)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%r15)
movq 0x18(%rax), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x1075e4
cmpq $0x0, 0xb0(%r14)
je 0x78d05
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7963c
movq 0x10(%r14), %rbp
testq %rbp, %rbp
jle 0x78db1
movq %rbp, %rdi
callq 0xe9c7e
movq %rax, %r13
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdx
subq %r13, %rdx
jle 0x78db1
leaq 0xb0846(%rip), %rsi     # 0x12957b
movq %rbx, %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0xe8617
movb 0x43(%r14), %al
testb %al, %al
jne 0x78d6a
movq 0x18(%rbx), %rdi
leaq 0xb08b6(%rip), %rdx     # 0x12960b
movl $0x4, %ecx
movq %rbp, %rsi
callq 0xefc85
testl %eax, %eax
je 0x78d9b
movb 0x43(%r14), %al
cmpq %rbp, %r13
jne 0x78d75
testb %al, %al
jne 0x78da0
jmp 0x78db1
testb %al, %al
jne 0x78da0
movq 0x18(%rbx), %rdi
leaq 0xb0887(%rip), %rdx     # 0x12960b
movl $0x4, %ecx
movq %r13, %rsi
callq 0xefc85
testl %eax, %eax
je 0x78d9b
movb 0x43(%r14), %al
jmp 0x78d6f
movb $0x1, 0x43(%r14)
leaq 0xb080c(%rip), %rsi     # 0x1295b3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
cmpl $0x0, (%rbx)
jle 0x78fde
cmpb $0x0, 0x32(%r14)
je 0x78fde
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r13
leaq 0x9bf88(%rip), %rsi     # 0x114d5f
movq %rax, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x7ceee
movl 0x60(%r14), %edx
leaq 0xb0821(%rip), %rsi     # 0x129610
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
movzbl 0x69(%r14), %edx
testl %edx, %edx
je 0x78e13
leaq 0xb0811(%rip), %rsi     # 0x12961a
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
movzbl 0x68(%r14), %edx
leaq 0xb0806(%rip), %rsi     # 0x129625
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
leaq 0xb07fd(%rip), %r12     # 0x12962d
xorl %ebp, %ebp
cmpb $0x0, 0x8d4(%r14,%rbp)
je 0x78e4c
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x7ceee
incq %rbp
cmpq $0x100, %rbp            # imm = 0x100
jne 0x78e32
cmpb $0x0, 0x46(%r14)
je 0x78e70
leaq 0xb07cf(%rip), %rsi     # 0x129635
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x45(%r14)
je 0x78e88
leaq 0xb07c1(%rip), %rsi     # 0x12963f
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x38(%r14)
je 0x78ea0
leaq 0xb07b7(%rip), %rsi     # 0x12964d
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x3b(%r14)
je 0x78eb8
leaq 0xb079a(%rip), %rsi     # 0x129648
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x3e(%r14)
je 0x78ed0
leaq 0xb0786(%rip), %rsi     # 0x12964c
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x40(%r14)
je 0x78ee8
leaq 0xb0773(%rip), %rsi     # 0x129651
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x3f(%r14)
je 0x78f00
leaq 0xb0760(%rip), %rsi     # 0x129656
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x41(%r14)
je 0x78f18
leaq 0xb074d(%rip), %rsi     # 0x12965b
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x49(%r14)
je 0x78f30
leaq 0xb073a(%rip), %rsi     # 0x129660
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x4a(%r14)
je 0x78f48
leaq 0xb0728(%rip), %rsi     # 0x129666
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x43(%r14)
je 0x78f60
leaq 0xb06b5(%rip), %rsi     # 0x12960b
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x3c(%r14)
je 0x78f78
leaq 0xb06fd(%rip), %rsi     # 0x12966b
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x42(%r14)
je 0x78f90
leaq 0xb06f3(%rip), %rsi     # 0x129679
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x44(%r14)
je 0x78fa8
leaq 0xb3d4c(%rip), %rsi     # 0x12ccea
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
cmpb $0x0, 0x33(%r14)
jne 0x78fc0
leaq 0xb06c8(%rip), %rsi     # 0x12967e
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ceee
movq %r13, %rdi
callq 0xf705c
leaq 0xb06b7(%rip), %rsi     # 0x129686
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
jmp 0x78fe1
xorl %r13d, %r13d
movq %r13, %rdi
callq 0xf6753
movq %r15, %rdi
callq 0x1075d3
movq 0xb0(%r14), %rsi
movq %rbx, %rdi
callq 0x7969e
movq 0xb8(%r14), %rsi
movq %rbx, %rdi
callq 0x7969e
movq 0xc0(%r14), %rsi
movq %rbx, %rdi
callq 0x7969e
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq