// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tga.c
// Function: de_identify_tga
static int de_identify_tga(deark *c)
{
	u8 b[18];
	u8 x;
	int has_tga_ext;
	i64 v2_footer_pos = 0;

	// TGA v1 format has no signature, but there are only a few common types of
	// it. We'll at least try to identify anything that we support.
	de_read(b, 0, 18);

	if(b[1]>1) return 0; // Color map type should be 0 or 1.

	if(b[12]==0 && b[13]==0) return 0; // Width can't be 0.
	if(b[14]==0 && b[15]==0) return 0; // Height can't be 0.

	if(look_for_v2_signature(c, 1, &v2_footer_pos)) {
		return 100;
	}

	// 0 is valid here, but it means "no image", and we need all the
	// can't-be-0 bytes we can find...
	if(b[2]==0) {
		// ...except that we have to allow 0 in .vst format.
		// TODO: .vst should maybe be a separate module.
		if((UI)de_getu32be(20)!=CODE_IGCH) {
			return 0;
		}
	}
	else if(b[2]==1 || b[2]==2 || b[2]==3 ||
		b[2]==9 || b[2]==10 || b[2]==11 || b[2]==32 || b[2]==33)
	{
		;
	}
	else {
		return 0; // Unknown image type
	}

	// bits/pixel:
	if(b[16]!=1 && b[16]!=8 && b[16]!=15 && b[16]!=16 && b[16]!=24 && b[16]!=32) return 0;

	// Bits per palette entry. Supposed to be 0 if there is no palette, but
	// in practice it may be 24 instead.
	if((b[1]==0 && b[7]==0) || b[7]==15 || b[7]==16 || b[7]==24 || b[7]==32) {
		;
	}
	else {
		return 0;
	}

	has_tga_ext = de_input_file_has_ext(c, "tga");

	x = b[17]&0x0f; // Number of attribute bits
	if(x!=0 && x!=1 && x!=8 && !has_tga_ext) return 0;

	if(has_tga_ext) {
		return 100;
	}
	if(de_input_file_has_ext(c, "vst")) {
		return 40;
	}
	return 8;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
movl $0x12, %ecx
callq 0x164d10
movzbl -0x2f(%rbp), %eax
cmpl $0x1, %eax
jle 0x12b1d3
movl $0x0, -0x4(%rbp)
jmp 0x12b3b8
movzbl -0x24(%rbp), %eax
cmpl $0x0, %eax
jne 0x12b1f1
movzbl -0x23(%rbp), %eax
cmpl $0x0, %eax
jne 0x12b1f1
movl $0x0, -0x4(%rbp)
jmp 0x12b3b8
movzbl -0x22(%rbp), %eax
cmpl $0x0, %eax
jne 0x12b20f
movzbl -0x21(%rbp), %eax
cmpl $0x0, %eax
jne 0x12b20f
movl $0x0, -0x4(%rbp)
jmp 0x12b3b8
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq -0x40(%rbp), %rdx
callq 0x12c6b0
cmpl $0x0, %eax
je 0x12b232
movl $0x64, -0x4(%rbp)
jmp 0x12b3b8
movzbl -0x2e(%rbp), %eax
cmpl $0x0, %eax
jne 0x12b262
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x14, %esi
callq 0x165470
cmpl $0x49474348, %eax       # imm = 0x49474348
je 0x12b260
movl $0x0, -0x4(%rbp)
jmp 0x12b3b8
jmp 0x12b2ba
movzbl -0x2e(%rbp), %eax
cmpl $0x1, %eax
je 0x12b2aa
movzbl -0x2e(%rbp), %eax
cmpl $0x2, %eax
je 0x12b2aa
movzbl -0x2e(%rbp), %eax
cmpl $0x3, %eax
je 0x12b2aa
movzbl -0x2e(%rbp), %eax
cmpl $0x9, %eax
je 0x12b2aa
movzbl -0x2e(%rbp), %eax
cmpl $0xa, %eax
je 0x12b2aa
movzbl -0x2e(%rbp), %eax
cmpl $0xb, %eax
je 0x12b2aa
movzbl -0x2e(%rbp), %eax
cmpl $0x20, %eax
je 0x12b2aa
movzbl -0x2e(%rbp), %eax
cmpl $0x21, %eax
jne 0x12b2ac
jmp 0x12b2b8
movl $0x0, -0x4(%rbp)
jmp 0x12b3b8
jmp 0x12b2ba
movzbl -0x20(%rbp), %eax
cmpl $0x1, %eax
je 0x12b2fc
movzbl -0x20(%rbp), %eax
cmpl $0x8, %eax
je 0x12b2fc
movzbl -0x20(%rbp), %eax
cmpl $0xf, %eax
je 0x12b2fc
movzbl -0x20(%rbp), %eax
cmpl $0x10, %eax
je 0x12b2fc
movzbl -0x20(%rbp), %eax
cmpl $0x18, %eax
je 0x12b2fc
movzbl -0x20(%rbp), %eax
cmpl $0x20, %eax
je 0x12b2fc
movl $0x0, -0x4(%rbp)
jmp 0x12b3b8
movzbl -0x2f(%rbp), %eax
cmpl $0x0, %eax
jne 0x12b30e
movzbl -0x29(%rbp), %eax
cmpl $0x0, %eax
je 0x12b332
movzbl -0x29(%rbp), %eax
cmpl $0xf, %eax
je 0x12b332
movzbl -0x29(%rbp), %eax
cmpl $0x10, %eax
je 0x12b332
movzbl -0x29(%rbp), %eax
cmpl $0x18, %eax
je 0x12b332
movzbl -0x29(%rbp), %eax
cmpl $0x20, %eax
jne 0x12b334
jmp 0x12b33d
movl $0x0, -0x4(%rbp)
jmp 0x12b3b8
movq -0x10(%rbp), %rdi
leaq 0x9c3da(%rip), %rsi     # 0x1c7722
callq 0x15d180
movl %eax, -0x38(%rbp)
movzbl -0x1f(%rbp), %eax
andl $0xf, %eax
movb %al, -0x31(%rbp)
movzbl -0x31(%rbp), %eax
cmpl $0x0, %eax
je 0x12b384
movzbl -0x31(%rbp), %eax
cmpl $0x1, %eax
je 0x12b384
movzbl -0x31(%rbp), %eax
cmpl $0x8, %eax
je 0x12b384
cmpl $0x0, -0x38(%rbp)
jne 0x12b384
movl $0x0, -0x4(%rbp)
jmp 0x12b3b8
cmpl $0x0, -0x38(%rbp)
je 0x12b393
movl $0x64, -0x4(%rbp)
jmp 0x12b3b8
movq -0x10(%rbp), %rdi
leaq 0x9caba(%rip), %rsi     # 0x1c7e58
callq 0x15d180
cmpl $0x0, %eax
je 0x12b3b1
movl $0x28, -0x4(%rbp)
jmp 0x12b3b8
movl $0x8, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)