// File: /workspace/github_c_makefile_star2_O1/pipde[P]deos-songlib/lib/songlib.c
// Function: readSampleSetName
SAMPLE_SET *
readSampleSetName(int inst,int baseNote,const char *name)
    {
    RRA *h = 0;
    SAMPLE_SET *ss = 0;
    FILE *fp = 0;
    DIR *dp = 0;
    struct dirent *ep = 0;     
    char fileNameBuffer[NOTE_NAME_LENGTH];
    char dirNameBuffer[NOTE_NAME_LENGTH];
    
    sprintf(fileNameBuffer, "%s%s.rra", 
        InstrumentDir[inst], name
        );

    dDebug("attempting to read %s\n",fileNameBuffer);
    fp = fopen(fileNameBuffer,"r");

    if (fp)
        {
        h = readRRA(fp,0);
        if (h->samples == 0) Fatal("note %s is empty!\n",fileNameBuffer);
        fclose(fp);
        ensureFadeIn(h);
        ss = newSampleSetForRRA(h);
        dDebug("successfully read base sample %s\n",fileNameBuffer);
        }
        
    sprintf(dirNameBuffer, "%s%s/", 
        InstrumentDir[inst], name
        );
    
    dDebug("attempting to read samples in directory %s\n",dirNameBuffer);
    
    dp = opendir(dirNameBuffer);
    if (dp != NULL)
        {            
        while ((ep = readdir(dp)))
            {
            sprintf(fileNameBuffer, "%s%s/%s", 
                InstrumentDir[inst], name, ep->d_name
                );
                
            // Ensure file is of regular type, and that it ends with .rra
            if (ep->d_type != DT_REG || !endsWith(fileNameBuffer, ".rra"))
                {
                dDebug("skipping entry %s\n",fileNameBuffer);
                continue;
                }
        
            dDebug("attempting to read %s\n",fileNameBuffer);
            fp = fopen(fileNameBuffer,"r");

            if (fp)
                {
                h = readRRA(fp,0);
                if (!h->samples) Fatal("sample %s is empty!\n",fileNameBuffer);
                fclose(fp);
                ensureFadeIn(h);
                if (!ss) ss = newSampleSet();
                addSampleToSampleSet(h,ss);
                dDebug("successfully read directory sample %s\n",fileNameBuffer);
                }
            }
                        
        (void)closedir(dp);
        }
        
    if (!ss) 
        {
        dDebug("no samples found for %s\n",name);
        return 0;
        }
        
    scale[inst][baseNote] = ss;
    originals[inst][baseNote] = 1;
    dDebug("successfully read %d samples for note %s\n",ss->count,name);
        
    return ss;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x828, %rsp            # imm = 0x828
movq %rdx, %r14
movl %esi, %ebp
movslq %edi, %r15
leaq 0x183cc(%rip), %rax     # 0x1ed20
movq (%rax,%r15,8), %rdx
leaq 0x3cd0(%rip), %rsi      # 0xa62f
xorl %r13d, %r13d
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x22b0
leaq 0x38cd(%rip), %rsi      # 0xa248
movq %rbx, %rdi
callq 0x2270
testq %rax, %rax
je 0x69df
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
callq 0x718e
movq %rax, %rbx
cmpl $0x0, 0xc(%rax)
jne 0x69b1
leaq 0x3c93(%rip), %rdi      # 0xa638
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x6b88
movq %r12, %rdi
callq 0x20c0
movl $0x10, %edi
callq 0x6cb5
movq %rax, %r13
movq $0x0, (%rax)
movl $0x0, 0x8(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6751
leaq 0x1833a(%rip), %rax     # 0x1ed20
movq (%rax,%r15,8), %rdx
leaq 0x3c5a(%rip), %rsi      # 0xa64b
leaq 0x420(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x22b0
movq %rbx, %rdi
callq 0x20d0
testq %rax, %rax
je 0x6b37
movq %rax, %r12
movq %r13, 0x8(%rsp)
movl %ebp, 0x14(%rsp)
movq %rax, %rdi
callq 0x2210
testq %rax, %rax
je 0x6b26
movq %rax, %rbx
leaq 0x3c13(%rip), %r13      # 0xa651
leaq 0x20(%rsp), %rbp
leaq 0x182d6(%rip), %rax     # 0x1ed20
movq (%rax,%r15,8), %rdx
leaq 0x13(%rbx), %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0x22b0
cmpb $0x8, 0x12(%rbx)
jne 0x6a96
movq %rbp, %rdi
callq 0x20e0
cmpq $0x4, %rax
jb 0x6a96
leaq 0x1c(%rsp), %rcx
addq %rcx, %rax
movl $0x4, %edx
movq %rax, %rdi
leaq 0x3ba6(%rip), %rsi      # 0xa633
callq 0x2070
testl %eax, %eax
je 0x6aa8
movq %r12, %rdi
callq 0x2210
movq %rax, %rbx
testq %rax, %rax
jne 0x6a43
jmp 0x6b26
movq %rbp, %rdi
leaq 0x3796(%rip), %rsi      # 0xa248
callq 0x2270
testq %rax, %rax
je 0x6a96
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x718e
movq %rax, 0x18(%rsp)
cmpl $0x0, 0xc(%rax)
jne 0x6ae5
leaq 0x3b7e(%rip), %rdi      # 0xa659
movq %rbp, %rsi
xorl %eax, %eax
callq 0x6b88
movq %rbx, %rdi
callq 0x20c0
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
jne 0x6b12
movl $0x10, %edi
callq 0x6cb5
movq %rax, %rsi
movq $0x0, (%rax)
movl $0x0, 0x8(%rax)
movq 0x18(%rsp), %rdi
movq %rsi, 0x8(%rsp)
callq 0x6751
jmp 0x6a96
movq %r12, %rdi
callq 0x2160
movl 0x14(%rsp), %ebp
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0x6b6e
movslq %ebp, %rax
imulq $0x420, %r15, %rcx      # imm = 0x420
leaq 0xdca3(%rip), %rdx      # 0x147f0
addq %rcx, %rdx
movq %r13, (%rdx,%rax,8)
imulq $0x210, %r15, %rcx      # imm = 0x210
leaq 0x8a0e(%rip), %rdx      # 0xf570
addq %rcx, %rdx
movl $0x1, (%rdx,%rax,4)
jmp 0x6b71
xorl %r13d, %r13d
movq %r13, %rax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop