// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x15b580
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x2, %rsi
callq 0x165540
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
addq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jle 0x8b549
jmp 0x8b685
cmpq $0x36, -0x48(%rbp)
jge 0x8b555
jmp 0x8b685
movq -0x8(%rbp), %rdi
leaq 0x123b21(%rip), %rsi    # 0x1af081
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl $0x18, %esi
callq 0x15b780
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movl $0x2, 0x8(%rax)
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x48(%rbp), %r9
leaq 0x12173c(%rip), %rsi    # 0x1acd07
callq 0x15c9f0
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
je 0x8b64c
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %rax
addq $0x8, %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movq $0x0, (%rax)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
addq $0x8, %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x40(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x28(%rbp), %rax
addq $0x8, %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
jmp 0x8b660
movq -0x8(%rbp), %rdi
leaq 0x123a37(%rip), %rsi    # 0x1af08e
movb $0x0, %al
callq 0x15bfb0
jmp 0x8b685
cmpl $0x0, -0x2c(%rbp)
jne 0x8b683
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
je 0x8b683
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x8bc80
jmp 0x8b685
cmpq $0x0, -0x40(%rbp)
je 0x8b6b6
movq -0x40(%rbp), %rax
movq (%rax), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x15d260
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x15b820
cmpq $0x0, -0x38(%rbp)
je 0x8b6ca
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x15b5a0
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)