// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %r9, %r15
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
movb $0xf, 0x1f(%rsp)
movb $0x0, 0x10(%rsp)
testq %r8, %r8
je 0x1cafc
movq %r8, %r14
leaq 0x158dc(%rip), %rsi     # 0x323cc
movq %r8, %rdi
xorl %edx, %edx
callq 0x193dc
jmp 0x1cb01
leaq 0x10(%rsp), %r14
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1cb28
cmpq $0x9, %rax
jb 0x1cb20
movq (%rbx), %rdi
movl $0x8, %esi
callq 0x157b7
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
cmpq $-0x1, %r12
je 0x1cb9c
movq %r15, 0x8(%rsp)
movq 0x10(%r13), %rax
shlq $0x5, %r12
leaq (%rax,%r12), %r15
movzwl 0x4(%rax,%r12), %eax
cmpl $0x8, %eax
je 0x1cbad
testl %eax, %eax
jne 0x1cc7d
movq 0x10(%r15), %r12
leaq -0x1(%r12), %rax
bsrq %rax, %rcx
movl $0x2, %eax
shlq %cl, %rax
cmpq $0x8, %r12
movl $0x8, %edi
cmovaeq %rax, %rdi
callq 0x1573c
movq %rax, %r13
movq 0x8(%r15), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x3280
movq (%rbx), %rdi
movq %r13, (%rbx)
movq %r12, 0x8(%rbx)
callq 0x3430
jmp 0x1cbe6
leaq 0x133d9(%rip), %rsi     # 0x2ff7c
movl $0xe, %edx
jmp 0x1cd2f
movl (%r15), %esi
movq %rbx, %rdi
callq 0xda72
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdi
movaps %xmm0, (%rdi)
movq (%rbx), %rax
movq %rax, (%rdi)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%rdi)
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdx
callq 0x8e50
testb %al, %al
je 0x1cd23
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %edx, %edx
callq 0x7990
cmpl 0x18(%r15), %eax
jne 0x1cd15
movb $0x1, %r14b
cmpq $0x0, 0x8(%rsp)
je 0x1cd3a
movl 0x1c(%r15), %eax
testl %eax, %eax
je 0x1cd8f
leal (%rax,%rax), %ecx
andl $0x3e, %ecx
leaq 0x50(%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)
movq $0x0, 0x18(%rdi)
movl $0x0, 0x20(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rdi)
callq 0x3660
jmp 0x1cd91
movzwl 0x4(%r15), %esi
leaq 0x30(%rsp), %r15
movq %r15, %rdi
xorl %edx, %edx
callq 0x1b7eb
movq (%r15), %r12
movq 0x8(%r15), %r13
leaq 0x13301(%rip), %rsi     # 0x2ffa0
leaq 0x20(%rsp), %r15
movl $0x1d, %edx
movq %r15, %rdi
callq 0x19316
leaq 0x50(%rsp), %rax
movq %r12, (%rax)
movq %r13, 0x8(%rax)
movzbl 0xf(%rax), %ecx
movq %rcx, %rsi
xorq $0xf, %rsi
testb %cl, %cl
movl %r13d, %edx
cmovnsq %rax, %r12
cmovnsq %rsi, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x19466
cmpb $0x0, 0xf(%r14)
jns 0x1ccef
movq (%r14), %rdi
callq 0x3430
movups 0x20(%rsp), %xmm0
movups %xmm0, (%r14)
movb $0xf, 0x2f(%rsp)
movb $0x0, 0x20(%rsp)
cmpb $0x0, 0x3f(%rsp)
jns 0x1cd37
movq 0x30(%rsp), %rdi
callq 0x3430
jmp 0x1cd37
leaq 0x132a2(%rip), %rsi     # 0x2ffbe
movl $0x9, %edx
jmp 0x1cd2f
leaq 0x13261(%rip), %rsi     # 0x2ff8b
movl $0x14, %edx
movq %r14, %rdi
callq 0x193dc
xorl %r14d, %r14d
cmpb $0x0, 0x1f(%rsp)
jns 0x1cd4b
movq 0x10(%rsp), %rdi
callq 0x3430
orb %r14b, %bpl
jne 0x1cd7a
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1cd77
cmpq $0x9, %rax
jb 0x1cd6f
movq (%rbx), %rdi
movl $0x8, %esi
callq 0x157b7
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x1cd3a
nop