// File: /workspace/github_c_makefile_star2_O0/inflex[P]ripMIME/ripOLE/olestream-unwrap.c
// Function: OLEUNWRAP_seach_for_file_sig
int OLEUNWRAP_seach_for_file_sig( struct OLEUNWRAP_object *oleuw, char *block, size_t block_len )
{
	int result = -1;
	int hit = 0;
	char *p;		/** signature pointer **/
	char *bp; /** pointer in the block **/
	struct typesig sigs[]= {
		{ "\x89\x50\x4e\x47", 4, 0 }, /** PNG **/
		{ "\xff\xd8\xff", 3, 0 }, /** JPEG **/
		{ NULL, -1, -1 } /** End of array **/
	};

	bp = block;
	block_len -= 4;

	/** While there's more data in the block and we're not found a match **/
	while ((block_len > 0)&&(hit==0)) {
		struct typesig *tsp; /** Type signature pointer **/

		block_len--;

		tsp = sigs; /** tsp points to the first signature in the array **/

		/** While there's more valid signatures in the array **/
		while (tsp->length > 0) {
			int cmpresult = 0;

			p = tsp->sequence; /** set p to point to the start of the image signature sequence **/
			cmpresult = memcmp(bp, p, 3);
			if (cmpresult == 0) {
				DUW LOGGER_log("%s:%d:OLEUNWRAP_seach_for_file_sig:DEBUG: Hit at offset %d for signature %d",FL,(bp-block),(tsp -sigs));
				hit = 1;
				break;
			} /** If we had a match in the signatures **/

			tsp++; /** go to the next signature **/

		} /** While more signatures **/

		if (hit == 0) bp++; /** If we didn't get a hit, move to the next byte in the file **/

	} /** while more data in the block **/

	if (hit == 1) {
		result =  bp -block;
	} else { 
		result = -1;
	}

	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x20(%rbp)
leaq -0x60(%rbp), %rdi
leaq 0xe563(%rip), %rsi      # 0x25db0
movl $0x30, %edx
callq 0x2250
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
subq $0x4, %rax
movq %rax, -0x18(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0x6d(%rbp)
jbe 0x17881
cmpl $0x0, -0x20(%rbp)
sete %al
movb %al, -0x6d(%rbp)
movb -0x6d(%rbp), %al
testb $0x1, %al
jne 0x1788d
jmp 0x1794b
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jle 0x17934
movl $0x0, -0x6c(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x3, %edx
callq 0x21c0
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
jne 0x17923
movq -0x8(%rbp), %rax
cmpl $0x0, 0x8(%rax)
je 0x1791a
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
subq %rax, %rcx
movq -0x68(%rbp), %r8
leaq -0x60(%rbp), %rax
subq %rax, %r8
sarq $0x4, %r8
leaq 0x9b0e(%rip), %rdi      # 0x21415
leaq 0x99ce(%rip), %rsi      # 0x212dc
movl $0x10f, %edx            # imm = 0x10F
movb $0x0, %al
callq 0x117c0
movl $0x1, -0x20(%rbp)
jmp 0x17934
movq -0x68(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x68(%rbp)
jmp 0x178a1
cmpl $0x0, -0x20(%rbp)
jne 0x17946
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1786b
cmpl $0x1, -0x20(%rbp)
jne 0x17961
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x1c(%rbp)
jmp 0x17968
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl -0x1c(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)