// File: /workspace/github_cpp_makefile_star2_O2/Alcaro[P]bridges/arlib/zip.cpp
// Function: zip::fh_fname(arrayview<unsigned char>, zip::locfhead*, zip::centdirrec*)
string zip::fh_fname(arrayview<uint8_t> data, locfhead* fh, centdirrec* cdr)
{
	size_t start = (uint8_t*)fh - data.ptr();
	if (start + sizeof(locfhead) + fh->len_fname > data.size()) return "";
	
	string fname = data.slice(start+sizeof(locfhead), fh->len_fname);
#if !ZIP_STRICT
	if (!(cdr->bitflags & (1 << 11)))
	{
		bool filename_cp437 = true;
		bytestream extra = zip::fh_extra(data, fh, cdr);
		while (extra.remaining() >= 4)
		{
			uint16_t signature = extra.u16l();
			uint16_t size = extra.u16l();
			
			if (extra.remaining() < size) break;
			bytestream chunk = extra.bytes(size);
			
			if (signature == 0x7075) // 'up', 4.6.9 -Info-ZIP Unicode Path Extra Field (0x7075)
			{
				if (filename_cp437 && chunk.u8() == 1 && chunk.u32l() == crc32(fname.bytes()))
				{
					fname = cstring(chunk.bytes(chunk.remaining()));
					filename_cp437 = false;
				}
			}
		}
		if (filename_cp437)
			fname = fromcp437(std::move(fname));
	}
#endif
	return fname;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r14
movq %rdi, %rbx
movq %r8, %rbp
subq %rdx, %rbp
movzwl 0x1a(%r8), %edx
leaq (%rdx,%rbp), %rax
addq $0x1e, %rax
cmpq %rcx, %rax
jbe 0x17588
leaq 0x13e5e(%rip), %rsi     # 0x2b3d9
movq %rbx, %rdi
callq 0x4242
jmp 0x17755
movq %r9, %r13
movq %r8, %r12
movq %rcx, %r15
addq $0x1e, %rbp
leaq (%r14,%rbp), %rsi
movq %rbx, %rdi
callq 0x146ba
testb $0x8, 0x9(%r13)
jne 0x17755
movzwl 0x1a(%r12), %eax
addq %rax, %rbp
movzwl 0x1c(%r12), %r13d
addq %rbp, %r14
addq %r13, %rbp
xorl %eax, %eax
cmpq %r15, %rbp
cmovaq %rax, %r13
cmovaq %rax, %r14
addq %r14, %r13
movb $0x1, %al
movl %eax, 0xc(%rsp)
movl %eax, %r15d
notb %r15b
movq %r13, %rax
subq %r14, %rax
cmpq $0x4, %rax
jb 0x17674
movq %r14, %r12
leaq 0x4(%r14), %rax
movzwl 0x2(%r14), %r14d
movq %r13, %rcx
subq %rax, %rcx
cmpq %r14, %rcx
jb 0x17674
addq %rax, %r14
cmpw $0x7075, (%r12)         # imm = 0x7075
setne %cl
orb %r15b, %cl
testb $0x1, %cl
jne 0x175dd
cmpb $0x1, (%rax)
jne 0x175dd
movzbl 0xf(%rbx), %esi
testb %sil, %sil
jns 0x1762f
movl 0x8(%rbx), %esi
movq (%rbx), %rdi
jmp 0x17636
xorq $0xf, %rsi
movq %rbx, %rdi
movl 0x5(%r12), %ebp
callq 0x17795
cmpl %eax, %ebp
jne 0x175dd
addq $0x9, %r12
movq %r14, %rdx
subq %r12, %rdx
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x1045e
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x5682
xorl %eax, %eax
jmp 0x175d3
testb $0x1, 0xc(%rsp)
je 0x17755
movups (%rbx), %xmm0
leaq 0x20(%rsp), %r12
movaps %xmm0, (%r12)
movb $0xf, 0xf(%rbx)
movb $0x0, (%rbx)
movzbl 0xf(%r12), %eax
movq %rax, %rcx
xorq $0xf, %rcx
testb %al, %al
movl 0x8(%r12), %r13d
cmovnsq %rcx, %r13
cmovsq (%r12), %r12
xorl %eax, %eax
cmpq %rax, %r13
je 0x17718
movb (%r12,%rax), %cl
addb $-0x20, %cl
incq %rax
cmpb $0x5f, %cl
jb 0x176b2
leaq 0x30(%rsp), %rax
movb $0xf, 0xf(%rax)
movb $0x0, (%rax)
xorl %ebp, %ebp
leaq 0x118a5(%rip), %r14     # 0x28f80
leaq 0x10(%rsp), %r15
cmpq %rbp, %r13
je 0x1772c
movzbl (%r12,%rbp), %eax
movzwl (%r14,%rax,2), %esi
movq %r15, %rdi
callq 0x15aa0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
leaq 0x30(%rsp), %rdi
callq 0x4296
movq %r15, %rdi
callq 0x56b4
incq %rbp
jmp 0x176e0
movaps 0x20(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
movb $0xf, 0x2f(%rsp)
movb $0x0, 0x20(%rsp)
movq %rbx, %rdi
callq 0x56b4
leaq 0x30(%rsp), %rdi
movaps (%rdi), %xmm0
movups %xmm0, (%rbx)
movb $0xf, 0xf(%rdi)
movb $0x0, (%rdi)
callq 0x56b4
leaq 0x20(%rsp), %rdi
callq 0x56b4
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop