// File: /workspace/github_c_makefile_star2_O1/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 0x5680
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0x5719
movq %r14, %rdi
callq 0x5714
movq %rax, %rdi
callq 0x48c2
movq %rax, %rbx
testq %rax, %rax
je 0x5c8b
leaq 0x79a9(%rip), %rsi      # 0xd628
movq %rbx, %rdi
callq 0x4400
testl %eax, %eax
je 0x5ce7
movq %r14, %rdi
callq 0x570f
cmpb $0x21, 0x1(%rax)
jne 0x5ce7
movq %r14, %rdi
callq 0x570f
movq %rax, %rdi
callq 0x489c
movq %rax, %r15
movb (%rax), %al
addb $-0x31, %al
cmpb $0x4, %al
ja 0x5cc6
cmpb $0x21, 0x1(%r15)
jne 0x5cc6
cmpb $0x21, 0x2(%r15)
jne 0x5d95
leaq 0x79d4(%rip), %rsi      # 0xd6a1
movl $0x2, %edi
callq 0x491c
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x4080
jmp 0x5d7b
leaq 0x793a(%rip), %rsi      # 0xd628
movq %rbx, %rdi
callq 0x4400
testl %eax, %eax
je 0x5d10
leaq 0x79a0(%rip), %rsi      # 0xd6a1
movl $0x2, %edi
callq 0x491c
xorl %r14d, %r14d
jmp 0x5d7b
leaq 0x7987(%rip), %rsi      # 0xd69e
movq %r15, %rdi
callq 0x4650
testq %rax, %rax
je 0x5d59
movq %rax, %r14
movq %rax, %rdi
callq 0x42d0
movq %rax, %r12
movq %r14, %rdi
callq 0x4220
testq %r12, %r12
je 0x5d62
movq %r12, %rdi
movl $0x1, %esi
callq 0x5bd5
movq %rax, %r14
movq %r12, %rdi
callq 0x43d0
jmp 0x5d7b
leaq 0x7b01(%rip), %rsi      # 0xd861
jmp 0x5d69
leaq 0x7b23(%rip), %rsi      # 0xd88c
xorl %r14d, %r14d
movl $0x1, %edi
movq %r15, %rdx
xorl %eax, %eax
callq 0x4949
movq %rbx, %rdi
callq 0x4080
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 0x7884(%rip), %rsi      # 0xd62c
movl $0x3, %edi
callq 0x491c
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x30(%rsp)
movb $0x31, (%r15)
leaq 0x78ab(%rip), %r13      # 0xd67e
leaq 0x78c4(%rip), %rbp      # 0xd69e
movq %r14, %rdi
callq 0x5697
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0x591a
movq %r12, %rdi
callq 0x5706
movq %rax, %r12
movl $0x3, %edi
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4949
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4650
testq %rax, %rax
je 0x5e3c
movq %rax, %r12
movq %rax, %rdi
callq 0x42d0
movsbq (%r15), %rcx
movq %rax, -0x178(%rsp,%rcx,8)
movq %r12, %rdi
callq 0x4220
movb (%r15), %al
incb %al
movb %al, (%r15)
cmpb $0x36, %al
jl 0x5dda
leaq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
movl $0x1, %edx
callq 0x5e64
movq %rax, %r14
jmp 0x5cda