// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rdx, %r15
movq %rdi, %rbx
movq %r8, %rbp
subq %rdx, %rbp
movzwl 0x1a(%r8), %edx
leaq (%rdx,%rbp), %rax
addq $0x1e, %rax
cmpq %rcx, %rax
jbe 0x1c4ec
movb $0x0, (%rbx)
movb $0xf, 0xf(%rbx)
jmp 0x1c6d4
movq %r9, %r13
movq %r8, %r12
movq %rcx, %r14
addq $0x1e, %rbp
leaq (%r15,%rbp), %rsi
movq %rbx, %rdi
callq 0x1929c
testb $0x8, 0x9(%r13)
jne 0x1c6d4
movzwl 0x1a(%r12), %eax
addq %rax, %rbp
movzwl 0x1c(%r12), %r12d
addq %rbp, %r15
addq %r12, %rbp
xorl %eax, %eax
cmpq %r14, %rbp
cmovaq %rax, %r12
cmovaq %rax, %r15
addq %r15, %r12
movb $0x1, %cl
movq %r12, %rax
subq %r15, %rax
cmpq $0x4, %rax
jb 0x1c625
leaq 0x4(%r15), %rax
movzwl 0x2(%r15), %r14d
movq %r12, %r13
subq %rax, %r13
cmpq %r14, %r13
jae 0x1c563
movq %rax, %rbp
jmp 0x1c619
leaq (%rax,%r14), %rbp
cmpw $0x7075, (%r15)         # imm = 0x7075
jne 0x1c619
testb $0x1, %cl
je 0x1c619
cmpb $0x1, (%rax)
jne 0x1c619
movzbl 0xf(%rbx), %esi
testb %sil, %sil
movq %rbx, 0x50(%rsp)
movl %ecx, 0x3c(%rsp)
jns 0x1c59f
movl 0x8(%rbx), %esi
movq (%rbx), %rdi
jmp 0x1c5a6
xorq $0xf, %rsi
movq %rbx, %rdi
movl 0x5(%r15), %ebx
xorl %edx, %edx
callq 0x7990
cmpl %eax, %ebx
jne 0x1c610
addq $0x9, %r15
movq %rbp, %rdx
subq %r15, %rdx
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x5040
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rax
movq %rsi, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movzbl 0x37(%rsp), %ecx
movq %rcx, %rdi
xorq $0xf, %rdi
testb %cl, %cl
movl %eax, %edx
leaq 0x28(%rsp), %rax
cmovnsq %rax, %rsi
cmovnsq %rdi, %rdx
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
callq 0x193dc
xorl %ecx, %ecx
jmp 0x1c619
movq 0x50(%rsp), %rbx
movl 0x3c(%rsp), %ecx
movq %rbp, %r15
cmpq %r14, %r13
jae 0x1c537
testb $0x1, %cl
je 0x1c6d4
movups (%rbx), %xmm0
movaps %xmm0, (%rsp)
movb $0xf, 0xf(%rbx)
movb $0x0, (%rbx)
movzbl 0xf(%rsp), %r13d
testb %r13b, %r13b
jns 0x1c651
movl 0x8(%rsp), %eax
movq (%rsp), %rcx
jmp 0x1c65b
movq %r13, %rax
xorq $0xf, %rax
movq %rsp, %rcx
testq %rax, %rax
sete %dl
je 0x1c692
movb (%rcx), %sil
addb $-0x20, %sil
cmpb $0x5e, %sil
ja 0x1c68e
movl $0x1, %esi
cmpq %rsi, %rax
sete %dl
je 0x1c692
movb (%rcx,%rsi), %dil
addb $-0x20, %dil
incq %rsi
cmpb $0x5f, %dil
jb 0x1c675
testb %dl, %dl
je 0x1c6e6
movaps (%rsp), %xmm0
movaps %xmm0, 0x40(%rsp)
movb $0xf, 0xf(%rsp)
movb $0x0, (%rsp)
cmpb $0x0, 0xf(%rbx)
jns 0x1c6b2
movq (%rbx), %rdi
callq 0x3430
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rbx)
movb $0xf, 0x4f(%rsp)
movb $0x0, 0x40(%rsp)
cmpb $0x0, 0xf(%rsp)
jns 0x1c6d4
movq (%rsp), %rdi
callq 0x3430
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0xf, 0x4f(%rsp)
movb $0x0, 0x40(%rsp)
testb %r13b, %r13b
jns 0x1c700
movl 0x8(%rsp), %r13d
movq (%rsp), %r12
jmp 0x1c707
xorq $0xf, %r13
movq %rsp, %r12
testq %r13, %r13
je 0x1c6a4
xorl %ebp, %ebp
leaq 0x18(%rsp), %r14
leaq 0x40(%rsp), %r15
movzbl (%r12,%rbp), %eax
leaq 0x138cc(%rip), %rcx     # 0x2fff0
movzwl (%rcx,%rax,2), %esi
movq %r14, %rdi
callq 0x1a9ca
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rax
movq %rsi, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movzbl 0x37(%rsp), %ecx
movq %rcx, %rdi
xorq $0xf, %rdi
testb %cl, %cl
movl %eax, %edx
leaq 0x28(%rsp), %rax
cmovnsq %rax, %rsi
cmovnsq %rdi, %rdx
movq %r15, %rdi
callq 0x19466
cmpb $0x0, 0x27(%rsp)
jns 0x1c77a
movq 0x18(%rsp), %rdi
callq 0x3430
incq %rbp
cmpq %rbp, %r13
jne 0x1c718
jmp 0x1c6a4
nop