// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/atari-img.c
// Function: is_degas_elite
static int is_degas_elite(deark *c, degasctx *d)
{
	i64 n;
	i64 x;
	i64 pos;
	int all_zero = 1;

	if(d->compression_code) return 1; // Only DEGAS Elite supports compression.
	if(c->infile->len < 32066) return 0;

	// Test if the animation segment seems to have valid values, to try to distinguish
	// it from meaningless padding. (This is overkill.)
	pos = 32034;
	for(n=0; n<8; n++) {
		// The first 8 fields are "color numbers".
		// Guessing that they should be 0-15.
		x = de_getu16be(pos+n*2);
		if(x>0x0f) return 0;
		if(x) all_zero = 0;
	}
	pos += 8*2;
	for(n=0; n<4; n++) {
		// The next 4 fields (channel direction) should be 0, 1, or 2.
		x = de_getu16be(pos+n*2);
		if(x>2) return 0;
		if(x) all_zero = 0;
	}
	pos += 4*2;
	for(n=0; n<4; n++) {
		// The next 4 fields (delay) must be from 0 to 128.
		x = de_getu16be(pos+n*2);
		if(x>128) return 0;
		if(x) all_zero = 0;
	}

	if(all_zero && c->infile->len>32068) {
		// If every field was 0, and the file size doesn't suggest Elite,
		// just assume it's not valid.
		return 0;
	}

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x1, -0x34(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2aa5c
movl $0x1, -0x4(%rbp)
jmp 0x2abdf
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x7d42, 0x18(%rax)     # imm = 0x7D42
jge 0x2aa7a
movl $0x0, -0x4(%rbp)
jmp 0x2abdf
movq $0x7d22, -0x30(%rbp)    # imm = 0x7D22
movq $0x0, -0x20(%rbp)
cmpq $0x8, -0x20(%rbp)
jge 0x2aae1
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rax
shlq %rax
addq %rax, %rsi
callq 0x1651d0
movq %rax, -0x28(%rbp)
cmpq $0xf, -0x28(%rbp)
jle 0x2aac3
movl $0x0, -0x4(%rbp)
jmp 0x2abdf
cmpq $0x0, -0x28(%rbp)
je 0x2aad1
movl $0x0, -0x34(%rbp)
jmp 0x2aad3
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2aa8a
movq -0x30(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
cmpq $0x4, -0x20(%rbp)
jge 0x2ab4c
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rax
shlq %rax
addq %rax, %rsi
callq 0x1651d0
movq %rax, -0x28(%rbp)
cmpq $0x2, -0x28(%rbp)
jle 0x2ab2e
movl $0x0, -0x4(%rbp)
jmp 0x2abdf
cmpq $0x0, -0x28(%rbp)
je 0x2ab3c
movl $0x0, -0x34(%rbp)
jmp 0x2ab3e
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2aaf5
movq -0x30(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
cmpq $0x4, -0x20(%rbp)
jge 0x2abb7
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rax
shlq %rax
addq %rax, %rsi
callq 0x1651d0
movq %rax, -0x28(%rbp)
cmpq $0x80, -0x28(%rbp)
jle 0x2ab99
movl $0x0, -0x4(%rbp)
jmp 0x2abdf
cmpq $0x0, -0x28(%rbp)
je 0x2aba7
movl $0x0, -0x34(%rbp)
jmp 0x2aba9
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2ab60
cmpl $0x0, -0x34(%rbp)
je 0x2abd8
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x7d44, 0x18(%rax)     # imm = 0x7D44
jle 0x2abd8
movl $0x0, -0x4(%rbp)
jmp 0x2abdf
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)