// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/insetpix.c
// Function: de_identify_insetpix
static int de_identify_insetpix(deark *c)
{
	UI pix_version;
	i64 item_count;
	i64 item;
	i64 item_loc, item_len;
	u8 has_ext;
	u8 has_typical_1st_item;

	if(c->detection_data->best_confidence_so_far>20) return 0;

	pix_version = (UI)de_getu16le(0);
	// Other versions exist, but I don't know anything about them.
	if(pix_version!=3) return 0;

	has_ext = (u8)de_input_file_has_ext(c, "pix");
	has_typical_1st_item = (u8)((u32)de_getu32le(4)==(u32)0x00200000);
	if(!has_ext && !has_typical_1st_item) return 0;

	item_count = de_getu16le(2);
	// Need at least 4 items (image info, palette info, tile info, and 1 tile).
	if(item_count<4 || item_count>500) return 0;

	if(4 + 8*item_count >= c->infile->len) return 0;

	for(item=0; item<item_count && item<16; item++) {
		item_len = de_getu16le(4+8*item+2);
		item_loc = de_getu32le(4+8*item+4);
		if(item_loc < 4 + 8*item_count) return 0;
		if(item_loc+item_len > c->infile->len) return 0;
	}

	return 20;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
cmpl $0x14, (%rax)
jle 0xb7925
movl $0x0, -0x4(%rbp)
jmp 0xb7ab8
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x165280
movl %eax, -0x14(%rbp)
cmpl $0x3, -0x14(%rbp)
je 0xb794b
movl $0x0, -0x4(%rbp)
jmp 0xb7ab8
movq -0x10(%rbp), %rdi
leaq 0xfeb30(%rip), %rsi     # 0x1b6486
callq 0x15d180
movb %al, -0x39(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x4, %esi
callq 0x165540
cmpl $0x200000, %eax         # imm = 0x200000
sete %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x3a(%rbp)
cmpb $0x0, -0x39(%rbp)
jne 0xb7998
cmpb $0x0, -0x3a(%rbp)
jne 0xb7998
movl $0x0, -0x4(%rbp)
jmp 0xb7ab8
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x2, %esi
callq 0x165280
movq %rax, -0x20(%rbp)
cmpq $0x4, -0x20(%rbp)
jl 0xb79bf
cmpq $0x1f4, -0x20(%rbp)     # imm = 0x1F4
jle 0xb79cb
movl $0x0, -0x4(%rbp)
jmp 0xb7ab8
movq -0x20(%rbp), %rax
shlq $0x3, %rax
addq $0x4, %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0xb79f1
movl $0x0, -0x4(%rbp)
jmp 0xb7ab8
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x3b(%rbp)
jge 0xb7a13
cmpq $0x10, -0x28(%rbp)
setl %al
movb %al, -0x3b(%rbp)
movb -0x3b(%rbp), %al
testb $0x1, %al
jne 0xb7a1f
jmp 0xb7ab1
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
shlq $0x3, %rsi
addq $0x4, %rsi
addq $0x2, %rsi
callq 0x165280
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
shlq $0x3, %rsi
addq $0x4, %rsi
addq $0x4, %rsi
callq 0x165540
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
shlq $0x3, %rcx
addq $0x4, %rcx
cmpq %rcx, %rax
jge 0xb7a7f
movl $0x0, -0x4(%rbp)
jmp 0xb7ab8
movq -0x30(%rbp), %rax
addq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xb7a9e
movl $0x0, -0x4(%rbp)
jmp 0xb7ab8
jmp 0xb7aa0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0xb79f9
movl $0x14, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)