// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: ZipExtract
static sxi32 ZipExtract(SyArchive *pArch, const unsigned char *zCentral, sxu32 nLen, void *pSrc)
{
	SyArchiveEntry *pEntry, *pDup;
	const unsigned char *zEnd ; /* End of central directory */
	sxu32 nIncr, nOfft;          /* Central Offset */
	SyString *pName;	        /* Entry name */
	char *zName;
	sxi32 rc;
	
	nOfft = nIncr = 0;
	zEnd = &zCentral[nLen];
	
	for(;;){
		if( &zCentral[nOfft] >= zEnd ){
			break;
		}
		/* Add a new entry */
		pEntry = (SyArchiveEntry *)SyMemBackendPoolAlloc(pArch->pAllocator, sizeof(SyArchiveEntry));
		if( pEntry == 0 ){
			break;
		}
		SyZero(pEntry, sizeof(SyArchiveEntry)); 
		pEntry->nMagic = SXARCH_MAGIC;
		nIncr = 0;
		rc = GetCentralDirectoryEntry(&(*pArch), pEntry, &zCentral[nOfft], &nIncr);
		if( rc == SXRET_OK ){
			/* Fix the starting record offset so we can access entry contents correctly */
			rc = ZipFixOffset(pEntry, pSrc);
		}
		if(rc != SXRET_OK ){
			sxu32 nJmp = 0;
			SyMemBackendPoolFree(pArch->pAllocator, pEntry);
			/* Try to recover by brute-forcing for a valid central directory record */
			if( SXRET_OK == SyBlobSearch((const void *)&zCentral[nOfft + nIncr], (sxu32)(zEnd - &zCentral[nOfft + nIncr]), 
				(const void *)"PK\001\002", sizeof(sxu32), &nJmp)){
					nOfft += nIncr + nJmp; /* Check next entry */
					continue;
			}
			break; /* Giving up, archive is hopelessly corrupted */
		}
		pName = &pEntry->sFileName;
		pName->zString = (const char *)&zCentral[nOfft + SXZIP_CENTRAL_HDRSZ];
		if( pName->nByte <= 0 || ( pEntry->nByte <= 0 && pName->zString[pName->nByte - 1] != '/') ){
			/* Ignore zero length records (except folders) and records without names */
			SyMemBackendPoolFree(pArch->pAllocator, pEntry); 
		 	nOfft += nIncr; /* Check next entry */
			continue;
		}
		zName = SyMemBackendStrDup(pArch->pAllocator, pName->zString, pName->nByte);
 	 	if( zName == 0 ){
 	 		 SyMemBackendPoolFree(pArch->pAllocator, pEntry); 
		 	 nOfft += nIncr; /* Check next entry */
			continue;
 	 	}
		pName->zString = (const char *)zName;
		/* Check for duplicates */
		rc = ArchiveHashGetEntry(&(*pArch), pName->zString, pName->nByte, &pDup);
		if( rc == SXRET_OK ){
			/* Another entry with the same name exists ; link them together */
			pEntry->pNextName = pDup->pNextName;
			pDup->pNextName = pEntry;
			pDup->nDup++;
		}else{
			/* Insert in hashtable */
			ArchiveHashInstallEntry(pArch, pEntry);
		}	
		nOfft += nIncr;	/* Check next record */
	}
	pArch->pCursor = pArch->pList;
	
	return pArch->nLoaded > 0 ? SXRET_OK : SXERR_EMPTY;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl -0x40(%rbp), %ecx
addq %rcx, %rax
cmpq -0x38(%rbp), %rax
jb 0xaa0b8
jmp 0xaa2ce
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movl $0xa8, %esi
callq 0x541f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xaa0d9
jmp 0xaa2ce
movq -0x28(%rbp), %rdi
movl $0xa8, %esi
callq 0x54280
movq -0x28(%rbp), %rax
movl $0xdead635a, 0xa0(%rax) # imm = 0xDEAD635A
movl $0x0, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdx
movl -0x40(%rbp), %eax
addq %rax, %rdx
leaq -0x3c(%rbp), %rcx
callq 0xaa3c0
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jne 0xaa130
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xaa5e0
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
je 0xaa1a7
movl $0x0, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x54490
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, %eax
addq %rax, %rdi
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %edx
addl -0x3c(%rbp), %edx
movl %edx, %edx
addq %rdx, %rcx
subq %rcx, %rax
movl %eax, %esi
leaq 0x1b9cc(%rip), %rdx     # 0xc5b47
movl $0x4, %ecx
leaq -0x58(%rbp), %r8
callq 0x98fe0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xaa1a2
movl -0x3c(%rbp), %eax
addl -0x58(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0xaa0a3
jmp 0xaa2ce
movq -0x28(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rcx
movl -0x40(%rbp), %eax
addl $0x2e, %eax
movl %eax, %eax
addq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jbe 0xaa1f8
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
ja 0xaa216
movq -0x48(%rbp), %rax
movq (%rax), %rax
movq -0x48(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
je 0xaa216
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x54490
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0xaa0a3
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movq -0x48(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x6da40
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xaa259
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x54490
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0xaa0a3
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movq (%rax), %rsi
movq -0x48(%rbp), %rax
movl 0x8(%rax), %edx
leaq -0x30(%rbp), %rcx
callq 0xaa690
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jne 0xaa2b3
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x30(%rbp), %rax
movl 0x60(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x60(%rax)
jmp 0xaa2c0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xaa760
movl -0x3c(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0xaa0a3
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movl 0x38(%rax), %edx
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
xorl %ecx, %ecx
cmpl $0x0, %edx
cmoval %ecx, %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)