// File: /workspace/github_c_makefile_star2_O2/excess-c64[P]lib1541img/src/lib/1541img/zcfileset.c
// Function: ZcFileSet_fromFile
SOEXPORT ZcFileSet *ZcFileSet_fromFile(const char *filename)
{
    ZcFileSet *self = 0;
    Filename *fn = Filename_create();
    Filename_setFull(fn, filename);
    char *ext = upperstr(Filename_ext(fn));
    if ((!ext || strcmp(ext, "D64"))
	    && Filename_base(fn)[1] == '!')
    {
	char *base = copystr(Filename_base(fn));
	if (base[0] >= '1' && base[0] <= '5'
		&& base[1] == '!' && base[2] != '!')
	{
            logmsg(L_INFO, "ZcFileSet: 4/5-file disk-packed zipcode "
                    "detected, looking for all member files...");
	    FileData *files[5] = { 0 };
	    for (base[0] = '1'; base[0] <= '5'; ++base[0])
	    {
		Filename *pn = Filename_clone(fn);
		Filename_setBase(pn, base);
                const char *ffn = Filename_full(pn);
                logfmt(L_INFO, "ZcFileSet: trying to read `%s'.", ffn);
		FILE *p = fopen_internal(ffn, "rb");
		if (p)
		{
		    files[base[0]-'1'] = readHostFile(p);
		    fclose(p);
		}
	    }
	    self = fromFileData(base+2, files, 1);
	}
        else
        {
            logmsg(L_WARNING, "ZcFileSet: no known ZipCode structure found.");
        }
	free(base);
    }
    else if (!strcmp(ext, "D64"))
    {
        self = fromD64(filename);
    }
    else
    {
        logmsg(L_WARNING, "ZcFileSet: no known ZipCode structure found.");
    }
    free(ext);
    return self;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r15
callq 0x64d4
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0x655c
movq %r14, %rdi
callq 0x6557
movq %rax, %rdi
callq 0x5902
movq %rax, %rbx
testq %rax, %rax
je 0x6a99
leaq 0x6b9b(%rip), %rsi      # 0xd628
movq %rbx, %rdi
callq 0x5430
testl %eax, %eax
je 0x6af3
movq %r14, %rdi
callq 0x6552
cmpb $0x21, 0x1(%rax)
jne 0x6af3
movq %r14, %rdi
callq 0x6552
movq %rax, %rdi
callq 0x58dc
movq %rax, %r15
movb (%rax), %al
addb $-0x31, %al
cmpb $0x4, %al
ja 0x6ad4
cmpb $0x21, 0x1(%r15)
jne 0x6ad4
cmpb $0x21, 0x2(%r15)
jne 0x6b98
leaq 0x6bc6(%rip), %rsi      # 0xd6a1
pushq $0x2
popq %rdi
callq 0x5960
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x5080
jmp 0x6b7e
leaq 0x6b2e(%rip), %rsi      # 0xd628
movq %rbx, %rdi
callq 0x5430
testl %eax, %eax
je 0x6b1a
leaq 0x6b94(%rip), %rsi      # 0xd6a1
pushq $0x2
popq %rdi
callq 0x5960
xorl %r14d, %r14d
jmp 0x6b7e
leaq 0x6b7d(%rip), %rsi      # 0xd69e
movq %r15, %rdi
callq 0x5690
testq %rax, %rax
je 0x6b5e
movq %rax, %r14
movq %rax, %rdi
callq 0x52e0
movq %rax, %r12
movq %r14, %rdi
callq 0x5230
testq %r12, %r12
je 0x6b67
movq %r12, %rdi
callq 0x5650
movq %rax, %r14
movq %r12, %rdi
callq 0x53f0
jmp 0x6b7e
leaq 0x6cfc(%rip), %rsi      # 0xd861
jmp 0x6b6e
leaq 0x6d1e(%rip), %rsi      # 0xd88c
xorl %r14d, %r14d
pushq $0x1
popq %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x598d
movq %rbx, %rdi
callq 0x5080
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rax
addq $0x2, %rax
movq %rax, 0x8(%rsp)
leaq 0x6a81(%rip), %rsi      # 0xd62c
pushq $0x3
popq %rdi
callq 0x5960
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movaps %xmm0, 0x10(%rsp)
movb $0x31, %al
leaq 0x6aaf(%rip), %r13      # 0xd67e
leaq 0x6ac8(%rip), %r12      # 0xd69e
movb %al, (%r15)
cmpb $0x35, %al
jg 0x6c44
movq %r14, %rdi
callq 0x64e9
movq %rax, %rbp
movq %rax, %rdi
movq %r15, %rsi
callq 0x674d
movq %rbp, %rdi
callq 0x6549
movq %rax, %rbp
pushq $0x3
popq %rdi
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x598d
movq %rbp, %rdi
movq %r12, %rsi
callq 0x5690
testq %rax, %rax
je 0x6c3d
movq %rax, %rbp
movq %rax, %rdi
callq 0x52e0
movsbq (%r15), %rcx
movq %rax, -0x178(%rsp,%rcx,8)
movq %rbp, %rdi
callq 0x5230
movb (%r15), %al
incb %al
jmp 0x6bd6
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
movq 0x8(%rsp), %rdi
callq 0x6c5e
movq %rax, %r14
jmp 0x6ae6