// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/comicchat.c
// Function: read_bmp_to_img
static void read_bmp_to_img(deark *c, lctx *d, dbuf *inf, i64 pos1,
	struct image_highlevel_ctx *ih, int itype)
{
	de_module_params *mparams = NULL;
	struct fmtutil_bmp_mparams_indata *idata = NULL;
	i64 bmplen;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	bmplen = dbuf_getu32le(inf, pos1+2);
	if(pos1+bmplen > inf->len) goto done;
	if(bmplen < 54) goto done;

	de_dbg(c, "decoding BMP");
	de_dbg_indent(c, 1);
	mparams = de_malloc(c, sizeof(de_module_params));
	idata = de_malloc(c, sizeof(struct fmtutil_bmp_mparams_indata));
	mparams->in_params.flags = 0x2;
	mparams->in_params.obj1 = (void*)idata;
	de_run_module_by_id_on_slice(c, "bmp", mparams, inf, pos1, bmplen);
	if(idata->img) {
		ih->llimg[itype].img = idata->img;
		idata->img = NULL;
		ih->llimg[itype].fi = idata->fi;
		idata->fi = NULL;
		ih->llimg[itype].createflags = idata->createflags;
	}
	else {
		de_err(c, "Failed to decode BMP image");
		goto done;
	}

	if(itype==0 && ih->special_2bpp_transparency) {
		fixup_2bpp_transparency(c, d, ih);
	}

done:
	if(idata) {
		de_bitmap_destroy(idata->img);
		de_finfo_destroy(c, idata->fi);
		de_free(c, idata);
	}
	if(mparams) {
		de_free(c, mparams);
	}
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %ebp
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x14(%rsp), %rsi
callq 0xe8a1c
leaq 0x2(%r13), %rsi
movq %r14, %rdi
callq 0xeed61
cmpq $0x36, %rax
jl 0x614aa
movq %rax, %r15
addq %r13, %rax
cmpq 0x18(%r14), %rax
jg 0x614aa
movl %ebp, 0x8(%rsp)
leaq 0xc243a(%rip), %rsi     # 0x123750
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %rbp
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe8b2b
movl $0x2, 0x8(%rbp)
movq %rax, 0x38(%rbp)
leaq 0xbfe06(%rip), %rsi     # 0x121162
movq %rbx, %rdi
movq %rbp, 0x20(%rsp)
movq %rbp, %rdx
movq %r14, %rcx
movq %rax, %r14
movq %r13, %r8
movq %r15, %r9
callq 0xe9aa3
movq (%r14), %rax
testq %rax, %rax
je 0x61468
movl 0x8(%rsp), %esi
movl %esi, %ecx
leaq (%rcx,%rcx,2), %rcx
movq %rax, 0x8(%r12,%rcx,8)
xorl %eax, %eax
movq %rax, (%r14)
movq 0x8(%r14), %rdx
movq %rdx, 0x10(%r12,%rcx,8)
movq %rax, 0x8(%r14)
movl 0x10(%r14), %eax
movl %eax, 0x18(%r12,%rcx,8)
testl %esi, %esi
jne 0x61479
cmpb $0x0, (%r12)
je 0x61479
addq $0x8, %r12
movq (%r12), %r13
testq %r13, %r13
je 0x61479
movq %r14, 0x18(%rsp)
movq %r12, 0x8(%rsp)
movq 0x8(%r13), %rsi
movq 0x10(%r13), %rdx
movq %rbx, %rdi
movl $0x2, %ecx
callq 0xf266a
movq %rax, %rbp
movq 0x10(%r13), %rcx
testq %rcx, %rcx
jle 0x61451
movq 0x8(%r13), %rax
xorl %r14d, %r14d
movl $0x808080, %r12d        # imm = 0x808080
testq %rax, %rax
jle 0x61449
xorl %r15d, %r15d
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xf2592
cmpl $0xff808080, %eax       # imm = 0xFF808080
cmovel %r12d, %eax
movq %rbp, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %eax, %ecx
callq 0xf24bf
incq %r15
movq 0x8(%r13), %rax
cmpq %rax, %r15
jl 0x61412
movq 0x10(%r13), %rcx
incq %r14
cmpq %rcx, %r14
jl 0x6140a
movq 0x8(%rsp), %r14
movq (%r14), %rdi
callq 0xf228d
movq %rbp, (%r14)
movq 0x18(%rsp), %r14
jmp 0x61479
leaq 0xc22ee(%rip), %rsi     # 0x12375d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq (%r14), %rdi
callq 0xf228d
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0xea50e
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0x614aa
movq %rbx, %rdi
callq 0xe8be2
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq