// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tiff.c
// Function: detect_and_setup_dexxa
static void detect_and_setup_dexxa(deark *c, lctx *d, struct page_ctx *pg)
{
	if(d->opt_dexxa==0) goto done; // Disabled by user
	if(pg->extrasamples_count!=0 || !pg->have_oldsubfiletype) goto done;
	if(pg->compression!=CMPR_NONE && pg->compression!=CMPR_PACKBITS &&
		pg->compression!=CMPR_CCITTRLE)
	{
		goto done;
	}

	if(pg->planarconfig==2 && pg->samples_per_pixel==4 &&
		(pg->bits_per_sample==1 || pg->bits_per_sample==4) &&
		pg->photometric==2 && pg->have_strip_tags && pg->valcount_bitspersample==1)
	{
		if(d->opt_dexxa==0xff) {
			de_dbg(c, "detected Dexxa variant");
		}
		pg->is_dexxa = 1;
		pg->dexxa_ncolors = 16;
		pg->bits_per_sample = 1; // [E.g. TRAIN1.TIF from PaintShow 1.1]
		goto done;
	}

	if(d->opt_dexxa==0xff) goto done; // No autodetection below this line

	if(pg->planarconfig==1 && pg->samples_per_pixel==1 &&
		pg->photometric==1 && pg->bits_per_sample==2 &&
		pg->compression!=CMPR_CCITTRLE)
	{
		// TODO?: Try to support 4-color CMPR_CCITTRLE. The images are at
		// least partially recoverable, but even the software that created them
		// can't read them back.
		pg->is_dexxa = 1;
		pg->dexxa_ncolors = 4;
		goto done;
	}

done:
	if(pg->is_dexxa) {
		de_dbg(c, "using Dexxa mode");
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x15(%rax), %eax
cmpl $0x0, %eax
jne 0x134e76
jmp 0x134faf
movq -0x18(%rbp), %rax
movzbl 0x9c(%rax), %eax
cmpl $0x0, %eax
jne 0x134e90
movq -0x18(%rbp), %rax
cmpb $0x0, 0x1a(%rax)
jne 0x134e95
jmp 0x134faf
movq -0x18(%rbp), %rax
cmpl $0x1, 0x1c(%rax)
je 0x134ebb
movq -0x18(%rbp), %rax
cmpl $0x8005, 0x1c(%rax)     # imm = 0x8005
je 0x134ebb
movq -0x18(%rbp), %rax
cmpl $0x2, 0x1c(%rax)
je 0x134ebb
jmp 0x134faf
movq -0x18(%rbp), %rax
cmpl $0x2, 0x38(%rax)
jne 0x134f52
movq -0x18(%rbp), %rax
cmpl $0x4, 0x2c(%rax)
jne 0x134f52
movq -0x18(%rbp), %rax
cmpl $0x1, 0x28(%rax)
je 0x134ee7
movq -0x18(%rbp), %rax
cmpl $0x4, 0x28(%rax)
jne 0x134f52
movq -0x18(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x134f52
movq -0x18(%rbp), %rax
movzbl 0x15(%rax), %eax
cmpl $0x0, %eax
je 0x134f52
movq -0x18(%rbp), %rax
movzbl 0x9b(%rax), %eax
cmpl $0x1, %eax
jne 0x134f52
movq -0x10(%rbp), %rax
movzbl 0x15(%rax), %eax
cmpl $0xff, %eax
jne 0x134f2f
movq -0x8(%rbp), %rdi
leaq 0x96916(%rip), %rsi     # 0x1cb83e
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movb $0x1, 0x99(%rax)
movq -0x18(%rbp), %rax
movb $0x10, 0x9a(%rax)
movq -0x18(%rbp), %rax
movl $0x1, 0x28(%rax)
jmp 0x134faf
movq -0x10(%rbp), %rax
movzbl 0x15(%rax), %eax
cmpl $0xff, %eax
jne 0x134f63
jmp 0x134faf
movq -0x18(%rbp), %rax
cmpl $0x1, 0x38(%rax)
jne 0x134fad
movq -0x18(%rbp), %rax
cmpl $0x1, 0x2c(%rax)
jne 0x134fad
movq -0x18(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jne 0x134fad
movq -0x18(%rbp), %rax
cmpl $0x2, 0x28(%rax)
jne 0x134fad
movq -0x18(%rbp), %rax
cmpl $0x2, 0x1c(%rax)
je 0x134fad
movq -0x18(%rbp), %rax
movb $0x1, 0x99(%rax)
movq -0x18(%rbp), %rax
movb $0x4, 0x9a(%rax)
jmp 0x134faf
jmp 0x134faf
movq -0x18(%rbp), %rax
cmpb $0x0, 0x99(%rax)
je 0x134fce
movq -0x8(%rbp), %rdi
leaq 0x9688e(%rip), %rsi     # 0x1cb855
movb $0x0, %al
callq 0x15b0d0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)