// File: /workspace/github_c_makefile_star2_O2/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, %r12d
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x14(%rsp), %rsi
callq 0xdebae
leaq 0x2(%r13), %rsi
movq %r14, %rdi
callq 0xe409f
cmpq $0x36, %rax
jl 0x5e19a
movq %rax, %rbp
addq %r13, %rax
cmpq 0x18(%r14), %rax
jg 0x5e19a
movl %r12d, 0x8(%rsp)
leaq 0xb855c(%rip), %rsi     # 0x116590
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
pushq $0x70
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r12
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movl $0x2, 0x8(%r12)
movq %rax, 0x38(%r12)
leaq 0xb5ffb(%rip), %rsi     # 0x114072
movq %rbx, %rdi
movq %r12, %rdx
movq %r14, %rcx
movq %r13, %r8
movq %rax, %r13
movq %rbp, %r9
callq 0xdf9b8
movq (%r13), %rax
testq %rax, %rax
je 0x5e159
movl 0x8(%rsp), %edx
movl %edx, %ecx
imulq $0x18, %rcx, %rcx
movq %rax, 0x8(%r15,%rcx)
andq $0x0, (%r13)
movq 0x8(%r13), %rax
movq %rax, 0x10(%r15,%rcx)
andq $0x0, 0x8(%r13)
movl 0x10(%r13), %eax
movl %eax, 0x18(%r15,%rcx)
testl %edx, %edx
jne 0x5e16a
cmpb $0x0, (%r15)
je 0x5e16a
addq $0x8, %r15
movq (%r15), %r14
testq %r14, %r14
je 0x5e16a
movq %r13, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %r15, 0x8(%rsp)
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
pushq $0x2
popq %rcx
movq %rbx, %rdi
callq 0xe7437
movq %rax, %r13
xorl %ebp, %ebp
movl $0x808080, %r12d        # imm = 0x808080
cmpq 0x10(%r14), %rbp
jge 0x5e1b5
xorl %r15d, %r15d
cmpq 0x8(%r14), %r15
jge 0x5e154
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xe735f
cmpl $0xff808080, %eax       # imm = 0xFF808080
cmovel %r12d, %eax
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl %eax, %ecx
callq 0xe728c
incq %r15
jmp 0x5e122
incq %rbp
jmp 0x5e115
leaq 0xb843d(%rip), %rsi     # 0x11659d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq (%r13), %rdi
callq 0xe7084
movq 0x8(%r13), %rsi
movq %rbx, %rdi
callq 0xdfd24
movq %rbx, %rdi
movq %r13, %rsi
callq 0xded32
testq %r12, %r12
je 0x5e19a
movq %rbx, %rdi
movq %r12, %rsi
callq 0xded32
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %r14
movq (%r14), %rdi
callq 0xe7084
movq %r13, (%r14)
movq 0x20(%rsp), %r12
movq 0x18(%rsp), %r13
jmp 0x5e16a
nopl (%rax)