// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/comicchat.c
// Function: extract_image_highlevel
static void extract_image_highlevel(deark *c, lctx *d, i64 imgpos, i64 m1pos, i64 m2pos,
	u8 is_icon, u8 is_bkgd)
{
	struct image_highlevel_ctx *ih = NULL;
	size_t k;
	u8 direct_to_bmp = 0;

	ih = de_malloc(c, sizeof(struct image_highlevel_ctx));
	ih->is_icon = is_icon;
	ih->is_bkgd = is_bkgd;

	de_dbg(c, "[extracting image at %"I64_FMT" : %"I64_FMT" : %"I64_FMT"]",
		imgpos, m1pos, m2pos);
	de_dbg_indent(c, 1);

	if(d->prefer_bmp_output) {
		// The direct_to_bmp flag is a bit of a hack, but I don't see any
		// elegant way to do it.
		if((ih->is_icon || ih->is_bkgd) && m1pos==0 && m2pos==0) {
			direct_to_bmp = 1;
		}
	}

	read_image_lowlevel(c, d, imgpos, ih, 0, direct_to_bmp);
	if(direct_to_bmp) goto done;

	read_image_lowlevel(c, d, m1pos, ih, 1, 0);
	read_image_lowlevel(c, d, m2pos, ih, 2, 0);

	for(k=0; k<3; k++) {
		if(!ih->llimg[k].fi) {
			ih->llimg[k].fi = de_finfo_create(c);
		}
		ih->llimg[k].createflags |= DE_CREATEFLAG_OPT_IMAGE;
	}

	if(should_apply_masks(c, d, ih)) {
		emit_images_highlevel_applymasks(c, d, ih);
	}
	else {
		emit_images_highlevel_separate(c, d, ih);
	}

done:
	if(ih) {
		for(k=0; k<3; k++) {
			de_bitmap_destroy(ih->llimg[k].img);
			de_finfo_destroy(c, ih->llimg[k].fi);
		}
		de_free(c, ih);
	}
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %r9b, %al
movb 0x10(%rbp), %r9b
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movb %al, -0x29(%rbp)
movq $0x0, -0x38(%rbp)
movb $0x0, -0x41(%rbp)
movq -0x8(%rbp), %rdi
movl $0x50, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movb -0x29(%rbp), %cl
movq -0x38(%rbp), %rax
movb %cl, 0x1(%rax)
movb 0x10(%rbp), %cl
movq -0x38(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
leaq 0x1242e7(%rip), %rsi    # 0x1af016
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
cmpb $0x0, 0x6(%rax)
je 0x8ad7c
movq -0x38(%rbp), %rax
movzbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x8ad68
movq -0x38(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x0, %eax
je 0x8ad7a
cmpq $0x0, -0x20(%rbp)
jne 0x8ad7a
cmpq $0x0, -0x28(%rbp)
jne 0x8ad7a
movb $0x1, -0x41(%rbp)
jmp 0x8ad7c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rcx
xorl %r8d, %r8d
movzbl -0x41(%rbp), %r9d
callq 0x8af10
cmpb $0x0, -0x41(%rbp)
je 0x8ada4
jmp 0x8ae89
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x8af10
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x2, %r8d
xorl %r9d, %r9d
callq 0x8af10
movq $0x0, -0x40(%rbp)
cmpq $0x3, -0x40(%rbp)
jae 0x8ae4d
movq -0x38(%rbp), %rax
addq $0x8, %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0x8ae26
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, %rcx
movq -0x38(%rbp), %rax
addq $0x8, %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
addq $0x8, %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x8ade8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x8b060
cmpl $0x0, %eax
je 0x8ae76
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x8b180
jmp 0x8ae87
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x8b2f0
jmp 0x8ae89
cmpq $0x0, -0x38(%rbp)
je 0x8aeef
movq $0x0, -0x40(%rbp)
cmpq $0x3, -0x40(%rbp)
jae 0x8aee2
movq -0x38(%rbp), %rax
addq $0x8, %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x16af60
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
addq $0x8, %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
callq 0x15d260
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x8ae98
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)