// File: /workspace/github_cpp_makefile_star2_O3/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 0x1c398
movq %r8, %r14
leaq 0x160e0(%rip), %rsi     # 0x3246c
movq %r8, %rdi
xorl %edx, %edx
callq 0x195fc
jmp 0x1c39d
leaq 0x10(%rsp), %r14
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1c3c4
cmpq $0x9, %rax
jb 0x1c3bc
movq (%rbx), %rdi
movl $0x8, %esi
callq 0x159f7
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
cmpq $-0x1, %r12
je 0x1c438
movq %r15, 0x8(%rsp)
movq 0x10(%r13), %rax
shlq $0x5, %r12
leaq (%rax,%r12), %r15
movzwl 0x4(%rax,%r12), %esi
cmpl $0x8, %esi
je 0x1c449
testl %esi, %esi
jne 0x1c513
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 0x1597c
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 0x1c47c
leaq 0x13b8d(%rip), %rsi     # 0x2ffcc
movl $0xe, %edx
jmp 0x1c5c1
movl (%r15), %esi
movq %rbx, %rdi
callq 0xdea4
movq (%rbx), %rax
leaq 0x40(%rsp), %rdi
movq %rax, (%rdi)
movq 0x8(%rbx), %rax
movq %rax, 0x8(%rdi)
movq 0x8(%r15), %rsi
movq 0x10(%r15), %rdx
callq 0x9306
testb %al, %al
je 0x1c5b5
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %edx, %edx
callq 0x7f18
cmpl 0x18(%r15), %eax
jne 0x1c5a7
movb $0x1, %r14b
cmpq $0x0, 0x8(%rsp)
je 0x1c5cc
movl 0x1c(%r15), %eax
testl %eax, %eax
je 0x1c621
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 0x1c623
leaq 0x30(%rsp), %r15
movq %r15, %rdi
xorl %edx, %edx
callq 0x1b137
movq (%r15), %r12
movq 0x8(%r15), %r13
leaq 0x13ac0(%rip), %rsi     # 0x2fff0
leaq 0x20(%rsp), %r15
movl $0x1d, %edx
movq %r15, %rdi
callq 0x19536
leaq 0x50(%rsp), %rax
movq %r12, (%rax)
movq %r13, 0x8(%rax)
movq %r13, %rcx
shrq $0x38, %rcx
xorq $0xf, %rcx
testq %r13, %r13
movl %r13d, %edx
cmovnsq %rcx, %rdx
cmovnsq %rax, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x1967e
cmpb $0x0, 0xf(%r14)
jns 0x1c581
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 0x1c5c9
movq 0x30(%rsp), %rdi
callq 0x3430
jmp 0x1c5c9
leaq 0x13a60(%rip), %rsi     # 0x3000e
movl $0x9, %edx
jmp 0x1c5c1
leaq 0x13a1f(%rip), %rsi     # 0x2ffdb
movl $0x14, %edx
movq %r14, %rdi
callq 0x195fc
xorl %r14d, %r14d
cmpb $0x0, 0x1f(%rsp)
jns 0x1c5dd
movq 0x10(%rsp), %rdi
callq 0x3430
orb %r14b, %bpl
jne 0x1c60c
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x1c609
cmpq $0x9, %rax
jb 0x1c601
movq (%rbx), %rdi
movl $0x8, %esi
callq 0x159f7
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 0x1c5cc
nop