// File: /workspace/github_c_makefile_star2_O3/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 %rdx, 0x18(%rsp)
movq %rdi, %rbx
testq %rcx, %rcx
je 0x6094e
movq %rcx, %r13
addq 0x20(%rsi), %r13
jmp 0x60951
xorl %r13d, %r13d
testq %r15, %r15
je 0x6095c
addq 0x20(%rsi), %r15
jmp 0x6095f
xorl %r15d, %r15d
xorl %r14d, %r14d
testq %r12, %r12
movq %rsi, 0x20(%rsp)
je 0x60972
addq 0x20(%rsi), %r12
jmp 0x60975
xorl %r12d, %r12d
leaq 0xc2d1a(%rip), %rsi     # 0x123696
movq %rbx, %rdi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0xe8617
cmpq %r12, %r15
movl $0x0, %ebp
cmovneq %r15, %rbp
testq %r13, %r13
je 0x60b7d
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
cmpq %rax, %r12
jge 0x60b7d
cmpq %rax, %r13
jge 0x60b7d
cmpq %rax, %rbp
jge 0x60b7d
movq 0x20(%rsp), %r14
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0xeb3ad
testl %eax, %eax
je 0x60af9
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 0xe8b2b
movq %rax, %r14
cmpl $0x102, 0x18(%rsp)      # imm = 0x102
movb %r15b, 0x1(%rax)
sete 0x2(%rax)
leaq 0xc2cbb(%rip), %rsi     # 0x1236e5
movq %rbx, %rdi
movq %r13, %rdx
movq %rbp, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x20(%rsp), %rax
cmpb $0x0, 0x6(%rax)
je 0x60a6c
cmpb $0x0, 0x1(%r14)
je 0x60b0c
movq %rbp, %rax
orq %r12, %rax
je 0x60b23
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x60c9a
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movl $0x1, %ecx
xorl %r8d, %r8d
callq 0x60c9a
movq %rbx, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl $0x2, %ecx
xorl %r8d, %r8d
callq 0x60c9a
movl $0x18, %r15d
movq 0x20(%rsp), %r12
cmpq $0x0, -0x8(%r14,%r15)
jne 0x60acb
movq %rbx, %rdi
callq 0xea504
movq %rax, -0x8(%r14,%r15)
orb $0x2, (%r14,%r15)
addq $0x18, %r15
cmpq $0x60, %r15
jne 0x60ab6
cmpb $0x0, 0x5(%r12)
je 0x60aec
cmpb $0x0, (%r14)
je 0x60b8f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6118e
jmp 0x60b39
leaq 0xc2bc8(%rip), %rsi     # 0x1236c8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
jmp 0x60b77
movq %rbp, %rax
orq %r12, %rax
jne 0x60a6c
cmpb $0x0, 0x2(%r14)
je 0x60a6c
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x60c9a
movl $0x10, %r15d
movq -0x8(%r14,%r15), %rdi
callq 0xf228d
movq (%r14,%r15), %rsi
movq %rbx, %rdi
callq 0xea50e
addq $0x18, %r15
cmpq $0x58, %r15
jne 0x60b3f
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
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 0x60aec
movq 0x20(%r14), %rcx
testq %rcx, %rcx
jne 0x60bb0
cmpq $0x0, 0x38(%r14)
je 0x60aec
movl $0x20, %edx
movq (%r14,%rdx), %rsi
testq %rsi, %rsi
je 0x60bda
movq 0x8(%rsi), %rdi
cmpq 0x8(%rax), %rdi
jne 0x60aec
movq 0x10(%rsi), %rsi
cmpq 0x10(%rax), %rsi
jne 0x60aec
addq $0x18, %rdx
cmpq $0x50, %rdx
jne 0x60bb5
movq 0x8(%rax), %r15
movq 0x10(%rax), %r12
testq %rcx, %rcx
jne 0x60bfc
cmpq $0x0, 0x38(%r14)
je 0x60c8a
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq $0x0, 0x20(%r14,%rbp)
je 0x60c73
testq %r13, %r13
je 0x60c16
movq %r13, %rdi
callq 0xf228d
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl $0x4, %ecx
callq 0xf266a
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 0xf36d0
movq 0x20(%r14,%rbp), %rsi
movq %r13, %rdi
movl $0x1, %edx
callq 0xf37bd
movq 0x10(%r14), %rsi
movl 0x18(%r14), %edx
movq %r13, %rdi
callq 0xf22d0
addq $0x18, %rbp
cmpq $0x30, %rbp
jne 0x60c01
movq %r13, %rdi
callq 0xf228d
jmp 0x60b39
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6118e
xorl %r13d, %r13d
jmp 0x60c7d