// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/misc2.c
// Function: de_run_fmtowns_hel
static void de_run_fmtowns_hel(deark *c, de_module_params *mparams)
{
	struct hel_ctx *d = NULL;
	i64 rowspan;
	i64 framesize;
	i64 nframes;
	i64 frame_idx;

	d = de_malloc(c, sizeof(struct hel_ctx));
	d->includedups = (u8)de_get_ext_option_bool(c, "fmtowns_hel:includedups", 0);
	d->w = 160;
	d->h = 120;
	rowspan = d->w/8;
	framesize = rowspan*d->h;
	d->canvas = de_bitmap_create(c, d->w, d->h, 1);
	d->frame_data = de_bitmap_create(c, d->w, d->h, 1);

	nframes = de_getu32le(8) + 1;
	de_dbg(c, "num frames: %"I64_FMT, nframes);
	for(frame_idx=0; frame_idx<nframes; frame_idx++) {
		i64 framestart = 12 + framesize*frame_idx;

		if(framestart+framesize > c->infile->len) goto done;
		de_dbg(c, "frame %"I64_FMT" at %"I64_FMT, frame_idx, framestart);
		de_dbg_indent(c, 1);
		de_convert_image_bilevel(c->infile, framestart, rowspan, d->frame_data, 0);
		d->change_flag = 0;
		hel_apply_frame(c, d);
		if(d->change_flag==0 && frame_idx!=0 && !d->includedups) {
			de_dbg(c, "[suppressing duplicate frame]");
		}
		else {
			de_bitmap_write_to_file(d->canvas, NULL, DE_CREATEFLAG_IS_BWIMG);
		}
		de_dbg_indent(c, -1);
	}

done:
	if(d) {
		de_bitmap_destroy(d->frame_data);
		de_bitmap_destroy(d->canvas);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r13
movl $0x28, %esi
callq 0xe969b
movq %rax, %r14
leaq 0xb9591(%rip), %rsi     # 0x125774
movq %r13, %rdi
xorl %edx, %edx
callq 0xea727
movb %al, (%r14)
movq $0xa0, 0x8(%r14)
movq $0x78, 0x10(%r14)
movl $0xa0, %esi
movl $0x78, %edx
movq %r13, %rdi
movl $0x1, %ecx
callq 0xf2cab
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %r13, %rdi
movl $0x1, %ecx
callq 0xf2cab
movq %rax, 0x20(%r14)
movq 0x18(%r13), %rdi
movl $0x8, %esi
callq 0xef37e
movq %rax, %rbx
leaq 0x1(%rax), %rdx
leaq 0xb6ad6(%rip), %rsi     # 0x122d26
movq %r13, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, 0x10(%rsp)
testq %rbx, %rbx
js 0x6c3aa
xorl %ebp, %ebp
movq %r13, 0x8(%rsp)
imulq $0x960, %rbp, %r12      # imm = 0x960
leaq 0x96c(%r12), %r15
movq 0x18(%r13), %rax
movq 0x18(%rax), %rbx
cmpq %rbx, %r15
jg 0x6c3aa
orq $0xc, %r12
movq %r13, %rdi
leaq 0xb94ef(%rip), %rsi     # 0x12578c
movq %rbp, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe9226
movq %r13, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%r13), %rdi
movq 0x20(%r14), %rcx
movl $0x14, %edx
movq %r12, %rsi
xorl %r8d, %r8d
callq 0xf3081
movb $0x0, 0x1(%r14)
cmpq $0x0, 0x10(%r14)
jle 0x6c345
xorl %r13d, %r13d
cmpq $0x0, 0x8(%r14)
jle 0x6c33c
xorl %r12d, %r12d
movq 0x20(%r14), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xf2bd3
testl $0xff0000, %eax         # imm = 0xFF0000
je 0x6c333
movq 0x18(%r14), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xf2bd3
andl $0xff0000, %eax         # imm = 0xFF0000
cmpl $0x1, %eax
movl $0x0, %eax
sbbl %eax, %eax
movq 0x18(%r14), %rdi
movzbl %al, %ecx
movq %r12, %rsi
movq %r13, %rdx
callq 0xf2a4a
movb $0x1, 0x1(%r14)
incq %r12
cmpq 0x8(%r14), %r12
jl 0x6c2e8
incq %r13
cmpq 0x10(%r14), %r13
jl 0x6c2de
testq %rbp, %rbp
je 0x6c357
cmpb $0x0, 0x1(%r14)
jne 0x6c357
cmpb $0x0, (%r14)
je 0x6c392
movq 0x18(%r14), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0xf2923
movq 0x8(%rsp), %r13
movq %r13, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
cmpq %rbx, %r15
jg 0x6c3aa
leaq 0x1(%rbp), %rax
cmpq 0x10(%rsp), %rbp
movq %rax, %rbp
jne 0x6c26f
jmp 0x6c3aa
movq 0x8(%rsp), %r13
movq %r13, %rdi
leaq 0xb93fc(%rip), %rsi     # 0x12579d
xorl %eax, %eax
callq 0xe9226
jmp 0x6c36c
movq 0x20(%r14), %rdi
callq 0xf28d4
movq 0x18(%r14), %rdi
callq 0xf28d4
movq %r13, %rdi
movq %r14, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9752