// File: /workspace/github_c_makefile_star2_O1/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, %r14d
movq %rcx, 0x10(%rsp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x1c(%rsp), %rsi
callq 0xe958c
leaq 0x2(%r13), %rsi
movq %r12, %rdi
callq 0xef37e
xorl %r15d, %r15d
cmpq $0x36, %rax
jl 0x615b8
movq %rax, %rbp
movl %r14d, 0x8(%rsp)
addq %r13, %rax
movl $0x0, %r14d
cmpq 0x18(%r12), %rax
jg 0x615ce
leaq 0xc210a(%rip), %rsi     # 0x123570
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movl $0x70, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r15
movl $0x2, 0x8(%r14)
movq %rax, 0x38(%r14)
leaq 0xbfba2(%rip), %rsi     # 0x121052
movq %rbx, %rdi
movq %r14, %rdx
movq %r12, %rcx
movq %r13, %r8
movq %rbp, %r9
callq 0xea5fa
movq (%r15), %rax
testq %rax, %rax
je 0x615bd
movl 0x8(%rsp), %edi
movl %edi, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rsp), %rsi
movq %rax, 0x8(%rsi,%rcx,8)
xorl %eax, %eax
movq %rax, (%r15)
movq 0x8(%r15), %rdx
movq %rdx, 0x10(%rsi,%rcx,8)
movq %rax, 0x8(%r15)
movl 0x10(%r15), %eax
movl %eax, 0x18(%rsi,%rcx,8)
testl %edi, %edi
jne 0x615ce
cmpb $0x0, (%rsi)
je 0x615ce
addq $0x8, %rsi
movq (%rsi), %r12
testq %r12, %r12
je 0x615ce
movq %rsi, 0x10(%rsp)
movq %r14, 0x20(%rsp)
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdx
movq %rbx, 0x8(%rsp)
movq %rbx, %rdi
movl $0x2, %ecx
callq 0xf2cab
movq %rax, %r13
cmpq $0x0, 0x10(%r12)
jle 0x6159c
xorl %ebp, %ebp
movl $0x808080, %ebx         # imm = 0x808080
cmpq $0x0, 0x8(%r12)
jle 0x61592
xorl %r14d, %r14d
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0xf2bd3
cmpl $0xff808080, %eax       # imm = 0xFF808080
cmovel %ebx, %eax
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movl %eax, %ecx
callq 0xf2b02
incq %r14
cmpq 0x8(%r12), %r14
jl 0x61562
incq %rbp
cmpq 0x10(%r12), %rbp
jl 0x61557
movq 0x10(%rsp), %rbx
movq (%rbx), %rdi
callq 0xf28d4
movq %r13, (%rbx)
movq 0x8(%rsp), %rbx
movq 0x20(%rsp), %r14
jmp 0x615ce
xorl %r14d, %r14d
jmp 0x615ce
leaq 0xc1fb9(%rip), %rsi     # 0x12357d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
testq %r15, %r15
je 0x615f2
movq (%r15), %rdi
callq 0xf28d4
movq 0x8(%r15), %rsi
movq %rbx, %rdi
callq 0xea9b3
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
testq %r14, %r14
je 0x61602
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq