// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movq %rdi, %rbx
movl $0x28, %esi
callq 0xe8b2b
movq %rax, %r14
leaq 0xb9a10(%rip), %rsi     # 0x1259a4
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe9bd0
movb %al, (%r14)
movq $0xa0, 0x8(%r14)
movq $0x78, 0x10(%r14)
movl $0xa0, %esi
movl $0x78, %edx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0xf266a
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0xf266a
movq %rax, 0x20(%r14)
movq 0x18(%rbx), %rdi
movl $0x8, %esi
callq 0xeed61
movq %rax, %r15
leaq 0x1(%rax), %rdx
leaq 0xb6f49(%rip), %rsi     # 0x122f4a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
testq %r15, %r15
js 0x6c150
xorl %ebp, %ebp
imulq $0x960, %rbp, %r12      # imm = 0x960
leaq 0x96c(%r12), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jg 0x6c150
orq $0xc, %r12
movq %rbx, %rdi
leaq 0xb997b(%rip), %rsi     # 0x1259bc
movq %rbp, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq 0x20(%r14), %rcx
movl $0x14, %edx
movq %r12, %rsi
xorl %r8d, %r8d
callq 0xf2a40
movb $0x0, 0x1(%r14)
movq 0x10(%r14), %rcx
testq %rcx, %rcx
jle 0x6c0fd
movq 0x8(%r14), %rax
xorl %r13d, %r13d
testq %rax, %rax
jle 0x6c0eb
xorl %r12d, %r12d
movq 0x20(%r14), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xf2592
testl $0xff0000, %eax         # imm = 0xFF0000
je 0x6c0db
movq 0x18(%r14), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xf2592
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 0xf2405
movb $0x1, 0x1(%r14)
incq %r12
movq 0x8(%r14), %rax
cmpq %rax, %r12
jl 0x6c090
movq 0x10(%r14), %rcx
incq %r13
cmpq %rcx, %r13
jl 0x6c088
cmpb $0x0, 0x1(%r14)
sete %al
jmp 0x6c0ff
movb $0x1, %al
testq %rbp, %rbp
je 0x6c10e
testb %al, %al
je 0x6c10e
cmpb $0x0, (%r14)
je 0x6c13d
movq 0x18(%r14), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0xf22dc
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
leaq 0x1(%rbp), %rax
cmpq %r15, %rbp
movq %rax, %rbp
jne 0x6c016
jmp 0x6c150
movq %rbx, %rdi
leaq 0xb9886(%rip), %rsi     # 0x1259cd
xorl %eax, %eax
callq 0xe8617
jmp 0x6c11e
movq 0x20(%r14), %rdi
callq 0xf228d
movq 0x18(%r14), %rdi
callq 0xf228d
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe8be2