// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x15(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl $0x9d8, %esi            # imm = 0x9D8
callq 0x15b780
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x1050be(%rip), %rsi    # 0x1b4462
movl $0xff, %edx
callq 0x15cbc0
movb %al, -0x16(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x1050b2(%rip), %rsi    # 0x1b446e
callq 0x15cb30
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xaf3e8
movq -0x8(%rbp), %rdi
leaq 0x1050a2(%rip), %rsi    # 0x1b4479
callq 0x15cb30
cmpq $0x0, %rax
je 0xaf3e6
movb $0x1, -0x15(%rbp)
jmp 0xaf3e8
movq -0x8(%rbp), %rdi
leaq 0x105093(%rip), %rsi    # 0x1b4486
xorl %edx, %edx
callq 0x15cbc0
cmpl $0x0, %eax
je 0xaf417
movq -0x30(%rbp), %rax
movb $0x1, 0x2e(%rax)
movq -0x30(%rbp), %rax
movb $0x1, 0x2f(%rax)
movq -0x30(%rbp), %rax
movb $0x1, 0x30(%rax)
movq -0x8(%rbp), %rdi
leaq 0x105076(%rip), %rsi    # 0x1b4498
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x15cbc0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0xaf43f
movq -0x30(%rbp), %rax
movb $0x0, 0x2e(%rax)
jmp 0xaf44f
cmpl $0x0, -0x1c(%rbp)
jle 0xaf44d
movq -0x30(%rbp), %rax
movb $0x1, 0x2e(%rax)
jmp 0xaf44f
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x165470
movl %eax, -0x14(%rbp)
cmpl $0x464f524d, -0x14(%rbp) # imm = 0x464F524D
je 0xaf483
movq -0x8(%rbp), %rdi
leaq 0x105030(%rip), %rsi    # 0x1b44a7
movb $0x0, %al
callq 0x15bfb0
jmp 0xaf750
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x8, %esi
movq %rsi, -0x78(%rbp)
leaq -0x68(%rbp), %rdx
movl $0x4, %ecx
xorl %r8d, %r8d
callq 0x169860
movq -0x78(%rbp), %rdx
movl -0x64(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
leaq -0x60(%rbp), %rsi
callq 0x15aa30
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
callq 0xaf7c0
movq -0x30(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x70(%rbp)
subl $0x4143424d, %eax       # imm = 0x4143424D
je 0xaf52c
jmp 0xaf4e4
movl -0x70(%rbp), %eax
subl $0x414e494d, %eax       # imm = 0x414E494D
je 0xaf520
jmp 0xaf4f0
movl -0x70(%rbp), %eax
subl $0x494c424d, %eax       # imm = 0x494C424D
je 0xaf52c
jmp 0xaf4fc
movl -0x70(%rbp), %eax
subl $0x50424d20, %eax       # imm = 0x50424D20
je 0xaf52c
jmp 0xaf508
movl -0x70(%rbp), %eax
subl $0x52474238, %eax       # imm = 0x52474238
je 0xaf52c
jmp 0xaf514
movl -0x70(%rbp), %eax
subl $0x5247424e, %eax       # imm = 0x5247424E
je 0xaf52c
jmp 0xaf52e
movq -0x30(%rbp), %rax
movl $0x1, (%rax)
jmp 0xaf54d
jmp 0xaf54d
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
addq $0x8, %rdx
leaq 0x104f76(%rip), %rsi    # 0x1b44b7
movb $0x0, %al
callq 0x15bfb0
jmp 0xaf750
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
addq $0x8, %rdx
leaq 0x104f7d(%rip), %rsi    # 0x1b44dd
movb $0x0, %al
callq 0x15e3d0
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xaf58b
movq -0x8(%rbp), %rdi
leaq 0x104f69(%rip), %rsi    # 0x1b44e4
xorl %edx, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x31(%rax)
movzbl -0x16(%rbp), %eax
cmpl $0xff, %eax
jne 0xaf5b4
movq -0x30(%rbp), %rax
movl (%rax), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x2d(%rax)
jmp 0xaf5be
movb -0x16(%rbp), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x2d(%rax)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0xaf5d1
movq -0x30(%rbp), %rax
movb $0x1, 0x2c(%rax)
jmp 0xaf5d9
movq -0x30(%rbp), %rax
movb $0x2, 0x2c(%rax)
cmpq $0x0, -0x28(%rbp)
je 0xaf650
movq -0x28(%rbp), %rdi
leaq 0xecf88(%rip), %rsi     # 0x19c573
callq 0x191a0
cmpl $0x0, %eax
jne 0xaf5ff
movq -0x30(%rbp), %rax
movb $0x2, 0x2c(%rax)
jmp 0xaf64e
movq -0x28(%rbp), %rdi
leaq 0x1215c6(%rip), %rsi    # 0x1d0bd0
callq 0x191a0
cmpl $0x0, %eax
jne 0xaf61e
movq -0x30(%rbp), %rax
movb $0x1, 0x2c(%rax)
jmp 0xaf64c
movq -0x28(%rbp), %rdi
callq 0x15cca0
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jne 0xaf63a
movq -0x30(%rbp), %rax
movb $0x0, 0x2c(%rax)
jmp 0xaf64a
cmpl $0x0, -0x6c(%rbp)
jle 0xaf648
movq -0x30(%rbp), %rax
movb $0x1, 0x2c(%rax)
jmp 0xaf64a
jmp 0xaf64c
jmp 0xaf64e
jmp 0xaf660
cmpb $0x0, -0x15(%rbp)
je 0xaf65e
movq -0x30(%rbp), %rax
movb $0x0, 0x2c(%rax)
jmp 0xaf660
movq -0x30(%rbp), %rax
movl (%rax), %edx
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x8(%rbp), %rdi
callq 0x18c8b0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movb $0x1, 0x5d(%rax)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x38(%rbp), %rax
leaq 0x14f(%rip), %rcx       # 0xaf810
movq %rcx, 0x20(%rax)
movq -0x38(%rbp), %rax
leaq 0x810(%rip), %rcx       # 0xafee0
movq %rcx, 0x28(%rax)
movq -0x38(%rbp), %rax
leaq 0x9b1(%rip), %rcx       # 0xb0090
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rax
leaq 0xae2(%rip), %rcx       # 0xb01d0
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x18c920
movq -0x30(%rbp), %rax
cmpq $0x0, 0xb0(%rax)
je 0xaf736
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xb0200
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xb02c0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xb0380
movq -0x38(%rbp), %rdi
callq 0x18c8f0
cmpq $0x0, -0x30(%rbp)
je 0xaf7b5
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0xb0(%rax), %rdx
callq 0xb0660
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0xb8(%rax), %rdx
callq 0xb0660
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x30(%rbp), %rax
movq 0xc0(%rax), %rdx
callq 0xb0660
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x15b820
addq $0x80, %rsp
popq %rbp
retq
nop