// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x28
popq %rsi
callq 0xdecaf
movq %rax, %r14
leaq 0xb0491(%rip), %rsi     # 0x1187a4
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
movb %al, (%r14)
movq $0xa0, 0x8(%r14)
movq $0x78, 0x10(%r14)
pushq $0x78
popq %rdx
pushq $0x1
popq %rbp
movl $0xa0, %esi
movq %rbx, %rdi
movl %ebp, %ecx
callq 0xe7437
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq %rbx, %rdi
movl %ebp, %ecx
callq 0xe7437
movq %rax, 0x20(%r14)
movq 0x18(%rbx), %rdi
pushq $0x8
popq %rsi
callq 0xe409f
movq %rax, %r15
leaq 0x1(%rax), %rdx
leaq 0xada11(%rip), %rsi     # 0x115d8a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
xorl %r12d, %r12d
cmpq %r15, %r12
jg 0x68498
imulq $0x960, %r12, %r13      # imm = 0x960
leaq 0x96c(%r13), %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jg 0x68498
orq $0xc, %r13
movq %rbx, %rdi
leaq 0xb0403(%rip), %rsi     # 0x1187bc
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq 0x20(%r14), %rcx
movq %r13, %rsi
pushq $0x14
popq %rdx
xorl %r8d, %r8d
callq 0xe77b7
movb $0x0, 0x1(%r14)
xorl %r13d, %r13d
cmpq 0x10(%r14), %r13
jge 0x68452
xorl %ebp, %ebp
cmpq 0x8(%r14), %rbp
jge 0x6844d
movq 0x20(%r14), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xe735f
testl $0xff0000, %eax         # imm = 0xFF0000
je 0x68448
movq 0x18(%r14), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xe735f
andl $0xff0000, %eax         # imm = 0xFF0000
cmpl $0x1, %eax
movl $0x0, %eax
sbbl %eax, %eax
movq 0x18(%r14), %rdi
movzbl %al, %ecx
movq %rbp, %rsi
movq %r13, %rdx
callq 0xe71da
movb $0x1, 0x1(%r14)
incq %rbp
jmp 0x683f7
incq %r13
jmp 0x683ef
testq %r12, %r12
je 0x68464
cmpb $0x0, 0x1(%r14)
jne 0x68464
cmpb $0x0, (%r14)
je 0x68485
movq 0x18(%r14), %rdi
xorl %esi, %esi
pushq $0x8
popq %rdx
callq 0xe70b7
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
incq %r12
jmp 0x68386
movq %rbx, %rdi
leaq 0xb033e(%rip), %rsi     # 0x1187cd
xorl %eax, %eax
callq 0xde896
jmp 0x68472
movq 0x20(%r14), %rdi
callq 0xe7084
movq 0x18(%r14), %rdi
callq 0xe7084
movq %rbx, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xded32