// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/comicchat.c
// Function: found_image
static int found_image(deark *c, lctx *d, struct chunk_ctx *cctx,
	i64 imgpos, i64 m1pos, i64 m2pos)
{
	int retval = 0;
	int ret;
	u8 is_icon;
	u8 is_bkgd;

	if(imgpos) imgpos += d->img_ptr_bias;
	if(m1pos) m1pos += d->img_ptr_bias;
	if(m2pos) m2pos += d->img_ptr_bias;
	de_dbg(c, "pointer: image at %"I64_FMT", mask1 at %"I64_FMT", mask2 at %"I64_FMT,
		imgpos, m1pos, m2pos);
	if(m1pos==m2pos) m1pos = 0;
	if(imgpos==0 || imgpos>=c->infile->len || m1pos>=c->infile->len ||
		m2pos>=c->infile->len)
	{
		goto done;
	}
	retval = 1;

	ret = de_inthashtable_add_item(c, d->images_seen, imgpos, NULL);
	if(!ret) {
		de_dbg(c, "[already handled this image]");
		goto done;
	}

	is_icon = (cctx->ck_type==0x0003 || cctx->ck_type==0x0100);
	is_bkgd = (cctx->ck_type==0x0102);
	extract_image_highlevel(c, d, imgpos, m1pos, m2pos, is_icon, is_bkgd);

done:
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r12
movq %r8, %r15
movq %rdi, %rbx
testq %rcx, %rcx
je 0x60a89
movq %rcx, %r13
addq 0x20(%rsi), %r13
jmp 0x60a8c
xorl %r13d, %r13d
testq %r15, %r15
je 0x60a97
addq 0x20(%rsi), %r15
jmp 0x60a9a
xorl %r15d, %r15d
xorl %r14d, %r14d
testq %r12, %r12
movq %rsi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
je 0x60ab2
addq 0x20(%rsi), %r12
jmp 0x60ab5
xorl %r12d, %r12d
leaq 0xc29fa(%rip), %rsi     # 0x1234b6
movq %rbx, %rdi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0xe9226
cmpq %r12, %r15
movl $0x0, %ebp
cmovneq %r15, %rbp
testq %r13, %r13
je 0x60cc2
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
cmpq %rax, %r12
jge 0x60cc2
cmpq %rax, %r13
jge 0x60cc2
cmpq %rax, %rbp
jge 0x60cc2
movq 0x20(%rsp), %r14
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xeb96a
testl %eax, %eax
je 0x60c39
movq 0x18(%rsp), %rax
movl (%rax), %ecx
movl %ecx, 0x18(%rsp)
cmpl $0x3, %ecx
sete %al
cmpl $0x100, %ecx            # imm = 0x100
sete %r15b
orb %al, %r15b
movl $0x50, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
cmpl $0x102, 0x18(%rsp)      # imm = 0x102
movb %r15b, 0x1(%rax)
sete 0x2(%rax)
leaq 0xc299b(%rip), %rsi     # 0x123505
movq %rbx, %rdi
movq %r13, %rdx
movq %rbp, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x20(%rsp), %rax
cmpb $0x0, 0x6(%rax)
je 0x60bac
cmpb $0x0, 0x1(%r14)
je 0x60c4c
movq %rbp, %rax
orq %r12, %rax
je 0x60c63
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x60ddf
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x60ddf
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl $0x2, %ecx
xorl %r8d, %r8d
callq 0x60ddf
movl $0x18, %r15d
movq 0x20(%rsp), %r12
cmpq $0x0, -0x8(%r14,%r15)
jne 0x60c0b
movq %rbx, %rdi
callq 0xea9a9
movq %rax, -0x8(%r14,%r15)
orb $0x2, (%r14,%r15)
addq $0x18, %r15
cmpq $0x60, %r15
jne 0x60bf6
cmpb $0x0, 0x5(%r12)
je 0x60c2c
cmpb $0x0, (%r14)
je 0x60cd4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x612d3
jmp 0x60c79
leaq 0xc28a8(%rip), %rsi     # 0x1234e8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
jmp 0x60cbc
movq %rbp, %rax
orq %r12, %rax
jne 0x60bac
cmpb $0x0, 0x2(%r14)
je 0x60bac
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x60ddf
testq %r14, %r14
je 0x60caf
movl $0x10, %r15d
movq -0x8(%r14,%r15), %rdi
callq 0xf28d4
movq (%r14,%r15), %rsi
movq %rbx, %rdi
callq 0xea9b3
addq $0x18, %r15
cmpq $0x58, %r15
jne 0x60c84
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movl $0x1, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x60c2c
movq 0x20(%r14), %rcx
testq %rcx, %rcx
jne 0x60cf5
cmpq $0x0, 0x38(%r14)
je 0x60c2c
movl $0x20, %edx
movq (%r14,%rdx), %rsi
testq %rsi, %rsi
je 0x60d1f
movq 0x8(%rsi), %rdi
cmpq 0x8(%rax), %rdi
jne 0x60c2c
movq 0x10(%rsi), %rsi
cmpq 0x10(%rax), %rsi
jne 0x60c2c
addq $0x18, %rdx
cmpq $0x50, %rdx
jne 0x60cfa
movq 0x8(%rax), %r15
movq 0x10(%rax), %r12
testq %rcx, %rcx
jne 0x60d41
cmpq $0x0, 0x38(%r14)
je 0x60dcf
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq $0x0, 0x20(%r14,%rbp)
je 0x60db8
testq %r13, %r13
je 0x60d5b
movq %r13, %rdi
callq 0xf28d4
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl $0x4, %ecx
callq 0xf2cab
movq %rax, %r13
movq 0x8(%r14), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
movl $0x0, 0x10(%rsp)
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r15, %r8
movq %r12, %r9
callq 0xf3d2f
movq 0x20(%r14,%rbp), %rsi
movq %r13, %rdi
movl $0x1, %edx
callq 0xf3e1c
movq 0x10(%r14), %rsi
movl 0x18(%r14), %edx
movq %r13, %rdi
callq 0xf2917
addq $0x18, %rbp
cmpq $0x30, %rbp
jne 0x60d46
movq %r13, %rdi
callq 0xf28d4
jmp 0x60c79
movq %rbx, %rdi
movq %r14, %rsi
callq 0x612d3
xorl %r13d, %r13d
jmp 0x60dc2