// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/zip.c
// Function: de_identify_zip
static int de_identify_zip(deark *c)
{
	u32 bof_sig;
	int has_zip_ext;
	int has_mz_sig = 0;
	i64 eocd_pos;

	has_zip_ext = de_input_file_has_ext(c, "zip");

	// Fast tests:

	bof_sig = (u32)de_getu32be(0);
	if(bof_sig==CODE_PK34 || bof_sig==CODE_PK00) {
		return has_zip_ext ? 100 : 90;
	}
	if((bof_sig>>16)==0x4d5a || (bof_sig>>16)==0x5a4d) {
		has_mz_sig = 1;
	}

	// First try "fast" mode. Note that we won't update c->detection_data
	// if this fails, because a later full search might succeed.
	if(fmtutil_find_zip_eocd(c, c->infile, 0x1, &eocd_pos)) {
		c->detection_data->zip_eocd_looked_for = 1;
		c->detection_data->zip_eocd_found = 1;
		c->detection_data->zip_eocd_pos = eocd_pos;
		return has_zip_ext ? 100 : 19;
	}

	// Things to consider:
	// * We want de_fmtutil_find_zip_eocd() to be called no more than once, and
	// only on files that for some reason we suspect could be ZIP files.
	// * If the user disables exe format detection (e.g. with "-onlydetect zip"),
	// we want self-extracting-ZIP .exe files to be detected as ZIP instead.
	// * And we want the above to work even if the file has a ZIP file comment,
	// making it expensive to detect as ZIP.

	// Tests below can't return a confidence higher than this.
	if(c->detection_data->best_confidence_so_far >= 19) return 0;

	// Slow tests:

	if(has_mz_sig || has_zip_ext) {
		c->detection_data->zip_eocd_looked_for = 1;
		if(fmtutil_find_zip_eocd(c, c->infile, 0, &eocd_pos)) {
			c->detection_data->zip_eocd_found = 1;
			c->detection_data->zip_eocd_pos = eocd_pos;
			return 19;
		}
	}

	if(has_zip_ext && bof_sig==CODE_PK78) {
		return 10; // First segment of a mult-segment archive
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x8d6b9(%rip), %rsi     # 0x1d4ac7
callq 0x15d180
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x165470
movl %eax, -0x14(%rbp)
cmpl $0x504b0304, -0x14(%rbp) # imm = 0x504B0304
je 0x14743c
cmpl $0x504b3030, -0x14(%rbp) # imm = 0x504B3030
jne 0x147457
movl -0x18(%rbp), %edx
movl $0x5a, %eax
movl $0x64, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x14756a
movl -0x14(%rbp), %eax
shrl $0x10, %eax
cmpl $0x4d5a, %eax           # imm = 0x4D5A
je 0x147471
movl -0x14(%rbp), %eax
shrl $0x10, %eax
cmpl $0x5a4d, %eax           # imm = 0x5A4D
jne 0x147478
movl $0x1, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movl $0x1, %edx
leaq -0x28(%rbp), %rcx
callq 0x1750a0
cmpl $0x0, %eax
je 0x1474da
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movb $0x1, 0x6(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movb $0x1, 0x7(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x8(%rax)
movl -0x18(%rbp), %edx
movl $0x13, %eax
movl $0x64, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x14756a
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
cmpl $0x13, (%rax)
jl 0x1474f0
movl $0x0, -0x4(%rbp)
jmp 0x14756a
cmpl $0x0, -0x1c(%rbp)
jne 0x1474fc
cmpl $0x0, -0x18(%rbp)
je 0x14754b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movb $0x1, 0x6(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
xorl %edx, %edx
leaq -0x28(%rbp), %rcx
callq 0x1750a0
cmpl $0x0, %eax
je 0x147549
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movb $0x1, 0x7(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x8(%rax)
movl $0x13, -0x4(%rbp)
jmp 0x14756a
jmp 0x14754b
cmpl $0x0, -0x18(%rbp)
je 0x147563
cmpl $0x504b0708, -0x14(%rbp) # imm = 0x504B0708
jne 0x147563
movl $0xa, -0x4(%rbp)
jmp 0x14756a
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)