// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %r8, %r15
movq %rdx, 0x18(%rsp)
movq %rdi, %rbx
testq %rcx, %rcx
je 0x5d5c8
movq %rcx, %rbp
addq 0x20(%rsi), %rbp
jmp 0x5d5ca
xorl %ebp, %ebp
testq %r15, %r15
je 0x5d5d5
addq 0x20(%rsi), %r15
jmp 0x5d5d8
xorl %r15d, %r15d
xorl %r12d, %r12d
testq %r13, %r13
movq %rsi, 0x20(%rsp)
je 0x5d5eb
addq 0x20(%rsi), %r13
jmp 0x5d5ee
xorl %r13d, %r13d
leaq 0xb8ee1(%rip), %rsi     # 0x1164d6
movq %rbx, %rdi
movq %rbp, %rdx
movq %r15, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0xde896
cmpq %r13, %r15
movl $0x0, %r14d
cmovneq %r15, %r14
testq %rbp, %rbp
je 0x5d7eb
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
cmpq %rax, %r13
jge 0x5d7eb
cmpq %rax, %rbp
jge 0x5d7eb
cmpq %rax, %r14
jge 0x5d7eb
movq 0x20(%rsp), %r15
movq 0x10(%r15), %rsi
movq %rbx, %rdi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0xe0a0b
testl %eax, %eax
je 0x5d76d
movq 0x18(%rsp), %rax
movl (%rax), %ecx
movl %ecx, 0x18(%rsp)
cmpl $0x3, %ecx
sete %al
cmpl $0x100, %ecx            # imm = 0x100
sete %r12b
orb %al, %r12b
pushq $0x50
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r15
cmpl $0x102, 0x18(%rsp)      # imm = 0x102
movb %r12b, 0x1(%rax)
sete 0x2(%rax)
leaq 0xb8e83(%rip), %rsi     # 0x116525
movq %rbx, %rdi
movq %rbp, %rdx
movq %r14, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %r12
movq %rbx, %rdi
movl %r12d, %esi
callq 0xdeba7
movq 0x20(%rsp), %rax
cmpb $0x0, 0x6(%rax)
je 0x5d6e6
cmpb $0x0, 0x1(%r15)
je 0x5d784
movq %r14, %rax
orq %r13, %rax
je 0x5d79b
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x5d900
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0x5d900
pushq $0x2
popq %rcx
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0x5d900
pushq $0x18
popq %r14
cmpq $0x60, %r14
je 0x5d74b
cmpq $0x0, -0x8(%r15,%r14)
jne 0x5d740
movq %rbx, %rdi
callq 0xdfd1a
movq %rax, -0x8(%r15,%r14)
orb $0x2, (%r15,%r14)
addq $0x18, %r14
jmp 0x5d725
movq 0x20(%rsp), %rax
cmpb $0x0, 0x5(%rax)
je 0x5d760
cmpb $0x0, (%r15)
je 0x5d7fd
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5dea4
jmp 0x5d7af
pushq $0x1
popq %r12
leaq 0xb8d90(%rip), %rsi     # 0x116508
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
jmp 0x5d7eb
movq %r14, %rax
orq %r13, %rax
jne 0x5d6e6
cmpb $0x0, 0x2(%r15)
je 0x5d6e6
pushq $0x1
popq %r8
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x5d900
pushq $0x10
popq %r14
cmpq $0x58, %r14
je 0x5d7d5
movq -0x8(%r15,%r14), %rdi
callq 0xe7084
movq (%r15,%r14), %rsi
movq %rbx, %rdi
callq 0xdfd24
addq $0x18, %r14
jmp 0x5d7b3
movq %rbx, %rdi
movq %r15, %rsi
callq 0xded32
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x5d760
movq 0x20(%r15), %rcx
testq %rcx, %rcx
jne 0x5d81e
cmpq $0x0, 0x38(%r15)
je 0x5d760
pushq $0x20
popq %rdx
cmpq $0x50, %rdx
je 0x5d852
movq (%r15,%rdx), %rsi
testq %rsi, %rsi
je 0x5d84c
movq 0x8(%rsi), %rdi
cmpq 0x8(%rax), %rdi
jne 0x5d760
movq 0x10(%rsi), %rsi
cmpq 0x10(%rax), %rsi
jne 0x5d760
addq $0x18, %rdx
jmp 0x5d821
movq 0x8(%rax), %r14
movq 0x10(%rax), %r12
testq %rcx, %rcx
jne 0x5d866
cmpq $0x0, 0x38(%r15)
je 0x5d8e2
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpq $0x30, %r13
je 0x5d8ef
cmpq $0x0, 0x20(%r15,%r13)
je 0x5d8dc
testq %rbp, %rbp
je 0x5d886
movq %rbp, %rdi
callq 0xe7084
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
pushq $0x4
popq %rcx
callq 0xe7437
movq %rax, %rbp
movq 0x8(%r15), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
andl $0x0, 0x10(%rsp)
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
movq %r12, %r9
callq 0xe8314
movq 0x20(%r15,%r13), %rsi
movq %rbp, %rdi
pushq $0x1
popq %rdx
callq 0xe83f8
movq 0x10(%r15), %rsi
movl 0x18(%r15), %edx
movq %rbp, %rdi
callq 0xe70ab
addq $0x18, %r13
jmp 0x5d86b
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5dea4
xorl %ebp, %ebp
movq %rbp, %rdi
callq 0xe7084
pushq $0x1
popq %r12
jmp 0x5d7af