// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl $0x28, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x1169df(%rip), %rsi    # 0x1b0e14
xorl %edx, %edx
callq 0x15cbc0
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, (%rax)
movq -0x18(%rbp), %rax
movq $0xa0, 0x8(%rax)
movq -0x18(%rbp), %rax
movq $0x78, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x18(%rbp), %rcx
imulq 0x10(%rcx), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x1, %ecx
callq 0x16b750
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
movl $0x1, %ecx
callq 0x16b750
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x8, %esi
callq 0x165540
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x11449c(%rip), %rsi    # 0x1ae99a
movb $0x0, %al
callq 0x15b0d0
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x9a60a
movq -0x28(%rbp), %rax
imulq -0x38(%rbp), %rax
addq $0xc, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x9a547
jmp 0x9a60c
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
leaq 0x1168d2(%rip), %rsi    # 0x1b0e2c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
xorl %r8d, %r8d
callq 0x16bee0
movq -0x18(%rbp), %rax
movb $0x0, 0x1(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x9d2a0
movq -0x18(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x9a5d5
cmpq $0x0, -0x38(%rbp)
je 0x9a5d5
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x9a5d5
movq -0x8(%rbp), %rdi
leaq 0x116871(%rip), %rsi    # 0x1b0e3d
movb $0x0, %al
callq 0x15b0d0
jmp 0x9a5eb
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x8, %edx
callq 0x16afd0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x9a50d
jmp 0x9a60c
cmpq $0x0, -0x18(%rbp)
je 0x9a63a
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x16af60
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq