// File: /workspace/github_cpp_makefile_star2_O3/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 0x1be0e
movb $0x0, (%rbx)
movb $0xf, 0xf(%rbx)
jmp 0x1c038
movq %r9, %r13
movq %r8, %r12
movq %rcx, %r15
addq $0x1e, %rbp
leaq (%r14,%rbp), %rsi
movq %rbx, %rdi
callq 0x194bc
testb $0x8, 0x9(%r13)
jne 0x1c038
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
cmpq $0x4, %r13
jb 0x1bf2e
addq %r14, %r13
movb $0x1, %bpl
movq %r14, %r12
leaq 0x4(%r14), %rax
movzwl 0x2(%r14), %r14d
movq %r13, %rcx
subq %rax, %rcx
cmpq %r14, %rcx
jb 0x1bf24
addq %rax, %r14
cmpw $0x7075, (%r12)         # imm = 0x7075
jne 0x1bf14
testb $0x1, %bpl
je 0x1bf14
cmpb $0x1, (%rax)
jne 0x1bf14
movzbl 0xf(%rbx), %esi
testb %sil, %sil
jns 0x1beab
movl 0x8(%rbx), %esi
movq (%rbx), %rdi
jmp 0x1beb2
xorq $0xf, %rsi
movq %rbx, %rdi
movl 0x5(%r12), %r15d
xorl %edx, %edx
callq 0x7f18
cmpl %eax, %r15d
jne 0x1bf14
addq $0x9, %r12
movq %r14, %rdx
subq %r12, %rdx
xorl %ebp, %ebp
movq %rsp, %rdi
movq %r12, %rsi
xorl %ecx, %ecx
callq 0x5990
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
movq %rsi, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rcx
shrq $0x38, %rcx
xorq $0xf, %rcx
testq %rax, %rax
movl %eax, %edx
cmovnsq %rcx, %rdx
leaq 0x20(%rsp), %rax
cmovnsq %rax, %rsi
movq %rbx, %rdi
callq 0x195fc
movq %r13, %rax
subq %r14, %rax
cmpq $0x3, %rax
ja 0x1be64
testb $0x1, %bpl
je 0x1c038
movups (%rbx), %xmm0
leaq 0x30(%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
testq %r13, %r13
je 0x1bf7a
xorl %eax, %eax
movb (%r12,%rax), %cl
addb $-0x20, %cl
cmpb $0x5f, %cl
jae 0x1bf8c
incq %rax
cmpq %rax, %r13
jne 0x1bf66
movaps 0x30(%rsp), %xmm0
movaps %xmm0, 0x10(%rsp)
movups %xmm0, (%rbx)
jmp 0x1c038
leaq 0x10(%rsp), %rax
movb $0xf, 0xf(%rax)
movb $0x0, (%rax)
xorl %ebp, %ebp
movq %rsp, %r15
leaq 0x20(%rsp), %r14
movzbl (%r12,%rbp), %eax
leaq 0x14092(%rip), %rcx     # 0x30040
movzwl (%rcx,%rax,2), %esi
movq %r15, %rdi
callq 0x1aa86
movq (%rsp), %rsi
movq 0x8(%rsp), %rax
movq %rsi, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rcx
shrq $0x38, %rcx
xorq $0xf, %rcx
testq %rax, %rax
movl %eax, %edx
cmovnsq %rcx, %rdx
cmovnsq %r14, %rsi
leaq 0x10(%rsp), %rdi
callq 0x1967e
cmpb $0x0, 0xf(%rsp)
jns 0x1bfff
movq (%rsp), %rdi
callq 0x3430
incq %rbp
cmpq %rbp, %r13
jne 0x1bfa2
cmpb $0x0, 0xf(%rbx)
jns 0x1c015
movq (%rbx), %rdi
callq 0x3430
cmpb $0x0, 0x3f(%rsp)
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rbx)
movb $0xf, 0x1f(%rsp)
movb $0x0, 0x10(%rsp)
jns 0x1c038
movq 0x30(%rsp), %rdi
callq 0x3430
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq