// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/dlmaker.c
// Function: de_identify_dlmaker
static int de_identify_dlmaker(deark *c)
{
	u8 v;
	i64 nscrn;
	i64 hsize;
	i64 ctlsize;
	i64 expected_filesize;

	if(!de_input_file_has_ext(c, "dl")) return 0;
	v = de_getbyte(0);
	if(v==1) {
		nscrn = (i64)de_getbyte(21);
		ctlsize = de_getu16le(22); // num frames * 1 byte
		hsize = 792;
	}
	else if(v==2) {
		if(de_getbyte(1)>2) return 0;
		nscrn = (i64)de_getbyte(42);
		ctlsize = de_getu32le(43) * 2;
		hsize = 815;
	}
	else if(v==3) {
		nscrn = (i64)de_getbyte(132);
		ctlsize = de_getu16le(134) * 2;
		hsize = 906;
	}
	else {
		return 0;
	}

	if(nscrn==0 || ctlsize==0) return 0;
	if(v==3) {
		// This is just a minimum file size. v3 is hard to identify.
		expected_filesize = hsize + nscrn*5 + ctlsize;
		if(c->infile->len < expected_filesize) return 0;
		return 10;
	}
	expected_filesize = hsize + V12_SCREEN_SIZE_IN_BYTES*nscrn + ctlsize;
	if(c->infile->len == expected_filesize) return 90;
	if(c->infile->len < expected_filesize) return 0;
	// Allow for some padding or other unknown data at EOF.
	if(c->infile->len > expected_filesize+511) return 0;
	return 10;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x12853d(%rip), %rsi    # 0x1ae9f4
callq 0x15d180
cmpl $0x0, %eax
jne 0x864cd
movl $0x0, -0x4(%rbp)
jmp 0x866bd
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x165060
movb %al, -0x11(%rbp)
movzbl -0x11(%rbp), %eax
cmpl $0x1, %eax
jne 0x86526
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x15, %esi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x16, %esi
callq 0x165280
movq %rax, -0x30(%rbp)
movq $0x318, -0x28(%rbp)     # imm = 0x318
jmp 0x865e6
movzbl -0x11(%rbp), %eax
cmpl $0x2, %eax
jne 0x86591
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x1, %esi
callq 0x165060
movzbl %al, %eax
cmpl $0x2, %eax
jle 0x86555
movl $0x0, -0x4(%rbp)
jmp 0x866bd
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x2a, %esi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x2b, %esi
callq 0x165540
shlq %rax
movq %rax, -0x30(%rbp)
movq $0x32f, -0x28(%rbp)     # imm = 0x32F
jmp 0x865e4
movzbl -0x11(%rbp), %eax
cmpl $0x3, %eax
jne 0x865d6
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x84, %esi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x86, %esi
callq 0x165280
shlq %rax
movq %rax, -0x30(%rbp)
movq $0x38a, -0x28(%rbp)     # imm = 0x38A
jmp 0x865e2
movl $0x0, -0x4(%rbp)
jmp 0x866bd
jmp 0x865e4
jmp 0x865e6
cmpq $0x0, -0x20(%rbp)
je 0x865f4
cmpq $0x0, -0x30(%rbp)
jne 0x86600
movl $0x0, -0x4(%rbp)
jmp 0x866bd
movzbl -0x11(%rbp), %eax
cmpl $0x3, %eax
jne 0x86644
movq -0x28(%rbp), %rax
imulq $0x5, -0x20(%rbp), %rcx
addq %rcx, %rax
addq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
cmpq -0x38(%rbp), %rax
jge 0x8663b
movl $0x0, -0x4(%rbp)
jmp 0x866bd
movl $0xa, -0x4(%rbp)
jmp 0x866bd
movq -0x28(%rbp), %rax
imulq $0xfa00, -0x20(%rbp), %rcx # imm = 0xFA00
addq %rcx, %rax
addq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
cmpq -0x38(%rbp), %rax
jne 0x86676
movl $0x5a, -0x4(%rbp)
jmp 0x866bd
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
cmpq -0x38(%rbp), %rax
jge 0x86691
movl $0x0, -0x4(%rbp)
jmp 0x866bd
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq -0x38(%rbp), %rcx
addq $0x1ff, %rcx            # imm = 0x1FF
cmpq %rcx, %rax
jle 0x866b6
movl $0x0, -0x4(%rbp)
jmp 0x866bd
movl $0xa, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)