// File: /workspace/github_cpp_makefile_star2_O2/Alcaro[P]bridges/arlib/zip.cpp
// Function: zip::read_idx(unsigned long, array<unsigned char>&, bool, string*, long*) const
bool zip::read_idx(size_t id, array<uint8_t>& out, bool permissive, string* error, time_t * time) const
{
	{
		string discard;
		if (!error) error = &discard;
		else *error = "";
		
		out.reset();
		if (id==(size_t)-1) { *error = "file not found"; goto fail; }
		
		const zip::file& f = filedat[id];
		switch (f.method)
		{
			case 0:
			{
				out = f.data;
				break;
			}
			case 8:
			{
				out.resize(f.decomplen);
				if (!inflator::inflate(out, f.data)) { *error = "corrupt DEFLATE data"; goto fail; }
				break;
			}
			default:
			{
				*error = "unknown compression method 0x"+tostringhex(f.method);
				goto fail;
			}
		}
		
		//APPNOTE.TXT specifies some other generator constant, 0xdebb20e3
		//no idea how to use that, the normal crc32 (0xedb88320) works fine
		if (crc32(out) != f.crc32) { *error = "bad crc32"; goto fail; }
		if (time) *time = fromdosdate(f.dosdate);
		return true;
	}
	
fail:
	if (!permissive) out.reset();
	return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %r14
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
movb $0xf, 0xf(%rsp)
movb $0x0, (%rsp)
testq %r8, %r8
je 0x179f0
movq %r8, %r15
leaq 0x139f3(%rip), %rsi     # 0x2b3d9
movq %r8, %rdi
callq 0x438e
jmp 0x179f3
movq %rsp, %r15
movq %rbx, %rdi
callq 0xbc86
cmpq $-0x1, %r12
je 0x17a50
movq 0x10(%r13), %rax
shlq $0x5, %r12
leaq (%rax,%r12), %r13
movzwl 0x4(%rax,%r12), %eax
cmpl $0x8, %eax
je 0x17a5c
testl %eax, %eax
jne 0x17b1c
leaq 0x8(%r13), %rsi
leaq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0xbcb2
movups (%r12), %xmm0
movq (%rbx), %rdi
movq %rdi, (%r12)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%r12)
movups %xmm0, (%rbx)
callq 0x3430
jmp 0x17a90
leaq 0x114b5(%rip), %rsi     # 0x28f0c
jmp 0x17b89
movl (%r13), %esi
movq %rbx, %rdi
callq 0xbaee
movq (%rbx), %rax
leaq 0x20(%rsp), %rdi
movq %rax, (%rdi)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%rdi)
movq 0x8(%r13), %rsi
movq 0x10(%r13), %rdx
callq 0x7886
testb %al, %al
je 0x17b82
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x17795
cmpl 0x18(%r13), %eax
jne 0x17b79
movb $0x1, %r12b
testq %r14, %r14
je 0x17b94
movl 0x1c(%r13), %eax
testl %eax, %eax
je 0x17bbe
leal (%rax,%rax), %ecx
andl $0x3e, %ecx
leaq 0x40(%rsp), %rdi
movl %ecx, (%rdi)
movl %eax, %ecx
shrl $0x5, %ecx
andl $0x3f, %ecx
movl %ecx, 0x4(%rdi)
movl %eax, %ecx
shrl $0xb, %ecx
andl $0x1f, %ecx
movl %ecx, 0x8(%rdi)
movl %eax, %ecx
shrl $0x10, %ecx
andl $0x1f, %ecx
movl %ecx, 0xc(%rdi)
movl %eax, %ecx
shrl $0x15, %ecx
andl $0xf, %ecx
decl %ecx
movl %ecx, 0x10(%rdi)
shrl $0x19, %eax
addl $0x50, %eax
movl %eax, 0x14(%rdi)
andq $0x0, 0x18(%rdi)
andl $0x0, 0x20(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rdi)
callq 0x3660
jmp 0x17bc0
movzwl %ax, %esi
xorl %r12d, %r12d
leaq 0x10(%rsp), %r14
movq %r14, %rdi
xorl %edx, %edx
callq 0x11f81
movq (%r14), %rdx
movq 0x8(%r14), %rcx
leaq 0x113f1(%rip), %rsi     # 0x28f30
leaq 0x40(%rsp), %r13
movq %r13, %rdi
callq 0x41b8
movq %r15, %rdi
callq 0x56b4
movups (%r13), %xmm0
movups %xmm0, (%r15)
movb $0xf, 0xf(%r13)
movb $0x0, (%r13)
movq %r13, %rdi
callq 0x56b4
movq %r14, %rdi
callq 0x56b4
jmp 0x17b94
leaq 0x113ce(%rip), %rsi     # 0x28f4e
jmp 0x17b89
leaq 0x11392(%rip), %rsi     # 0x28f1b
movq %r15, %rdi
callq 0x438e
xorl %r12d, %r12d
movq %rsp, %rdi
callq 0x56b4
orb %r12b, %bpl
jne 0x17bac
movq %rbx, %rdi
callq 0xbc86
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movq %rax, (%r14)
jmp 0x17b94
nop