// File: /workspace/github_c_makefile_star2_O2/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, %rbx
leaq 0x17b9a(%rip), %rax     # 0x1dd20
movq (%rax,%rbx,8), %rdx
leaq 0x34be(%rip), %rsi      # 0x964f
xorl %r13d, %r13d
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x22a0
leaq 0x309b(%rip), %rsi      # 0x9248
movq %r15, %rdi
callq 0x2260
testq %rax, %rax
je 0x61f6
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
callq 0x6975
movq %rax, %r15
cmpl $0x0, 0xc(%rax)
jne 0x61e3
leaq 0x3481(%rip), %rdi      # 0x9658
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x6378
movq %r12, %rdi
callq 0x20c0
movq %r15, %rdi
callq 0x5725
movq %rax, %r13
leaq 0x17b23(%rip), %rax     # 0x1dd20
movq (%rax,%rbx,8), %rdx
leaq 0x3463(%rip), %rsi      # 0x966b
leaq 0x420(%rsp), %r15
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x22a0
movq %r15, %rdi
callq 0x20d0
testq %rax, %rax
je 0x632b
movq %rax, %r12
movq %r13, 0x8(%rsp)
movl %ebp, 0x14(%rsp)
leaq 0x3430(%rip), %r13      # 0x9671
leaq 0x20(%rsp), %rbp
movq %r12, %rdi
callq 0x2200
testq %rax, %rax
je 0x631a
movq %rax, %r15
leaq 0x17abf(%rip), %rax     # 0x1dd20
movq (%rax,%rbx,8), %rdx
movq %r15, %r8
addq $0x13, %r8
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0x22a0
cmpb $0x8, 0x12(%r15)
jne 0x6246
movq %rbp, %rdi
callq 0x20e0
cmpq $0x4, %rax
jb 0x6246
leaq 0x1c(%rsp), %rcx
addq %rcx, %rax
movq %rax, %rdi
leaq 0x33b0(%rip), %rsi      # 0x9653
pushq $0x4
popq %rdx
callq 0x2070
testl %eax, %eax
jne 0x6246
movq %rbp, %rdi
leaq 0x2f8f(%rip), %rsi      # 0x9248
callq 0x2260
testq %rax, %rax
je 0x6246
movq %rax, %rdi
xorl %esi, %esi
movq %rax, 0x18(%rsp)
callq 0x6975
movq %rax, %r15
cmpl $0x0, 0xc(%rax)
jne 0x62ec
leaq 0x3397(%rip), %rdi      # 0x9679
movq %rbp, %rsi
xorl %eax, %eax
callq 0x6378
movq 0x18(%rsp), %rdi
callq 0x20c0
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
jne 0x6308
callq 0x5fe3
movq %rax, %rsi
movq %r15, %rdi
movq %rsi, 0x8(%rsp)
callq 0x5f89
jmp 0x6246
movq %r12, %rdi
callq 0x2160
movl 0x14(%rsp), %ebp
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0x6360
movslq %ebp, %rax
imulq $0x420, %rbx, %rcx      # imm = 0x420
leaq 0xd4af(%rip), %rdx      # 0x137f0
addq %rcx, %rdx
movq %r13, (%rdx,%rax,8)
imulq $0x210, %rbx, %rcx      # imm = 0x210
leaq 0x821a(%rip), %rdx      # 0xe570
addq %rcx, %rdx
movl $0x1, (%rdx,%rax,4)
movq %r13, %rax
addq $0x828, %rsp            # imm = 0x828
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)