// File: /workspace/github_c_makefile_star2_O3/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 0x1828f(%rip), %rax     # 0x1ed20
movq (%rax,%r15,8), %rdx
leaq 0x3bd3(%rip), %rsi      # 0xa66f
xorl %r13d, %r13d
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x22b0
leaq 0x3790(%rip), %rsi      # 0xa248
movq %rbx, %rdi
callq 0x2270
testq %rax, %rax
je 0x6b1c
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
callq 0x72c2
movq %rax, %rbx
cmpl $0x0, 0xc(%rax)
jne 0x6aee
leaq 0x3b96(%rip), %rdi      # 0xa678
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x6cc0
movq %r12, %rdi
callq 0x20c0
movl $0x10, %edi
callq 0x6ddf
movq %rax, %r13
movq $0x0, (%rax)
movl $0x0, 0x8(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x688d
leaq 0x181fd(%rip), %rax     # 0x1ed20
movq (%rax,%r15,8), %rdx
leaq 0x3b5d(%rip), %rsi      # 0xa68b
leaq 0x420(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x22b0
movq %rbx, %rdi
callq 0x20d0
testq %rax, %rax
je 0x6c74
movq %rax, %r12
movq %r13, 0x8(%rsp)
movl %ebp, 0x14(%rsp)
movq %rax, %rdi
callq 0x2210
testq %rax, %rax
je 0x6c63
movq %rax, %rbx
leaq 0x3b16(%rip), %r13      # 0xa691
leaq 0x20(%rsp), %rbp
leaq 0x18199(%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 0x6bd3
movq %rbp, %rdi
callq 0x20e0
cmpq $0x4, %rax
jb 0x6bd3
leaq 0x1c(%rsp), %rcx
addq %rcx, %rax
movl $0x4, %edx
movq %rax, %rdi
leaq 0x3aa9(%rip), %rsi      # 0xa673
callq 0x2070
testl %eax, %eax
je 0x6be5
movq %r12, %rdi
callq 0x2210
movq %rax, %rbx
testq %rax, %rax
jne 0x6b80
jmp 0x6c63
movq %rbp, %rdi
leaq 0x3659(%rip), %rsi      # 0xa248
callq 0x2270
testq %rax, %rax
je 0x6bd3
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x72c2
movq %rax, 0x18(%rsp)
cmpl $0x0, 0xc(%rax)
jne 0x6c22
leaq 0x3a81(%rip), %rdi      # 0xa699
movq %rbp, %rsi
xorl %eax, %eax
callq 0x6cc0
movq %rbx, %rdi
callq 0x20c0
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
jne 0x6c4f
movl $0x10, %edi
callq 0x6ddf
movq %rax, %rsi
movq $0x0, (%rax)
movl $0x0, 0x8(%rax)
movq 0x18(%rsp), %rdi
movq %rsi, 0x8(%rsp)
callq 0x688d
jmp 0x6bd3
movq %r12, %rdi
callq 0x2160
movl 0x14(%rsp), %ebp
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0x6ca9
movslq %ebp, %rax
imulq $0x420, %r15, %rcx      # imm = 0x420
leaq 0xdb66(%rip), %rdx      # 0x147f0
addq %rcx, %rdx
movq %r13, (%rdx,%rax,8)
imulq $0x210, %r15, %rcx      # imm = 0x210
leaq 0x88d1(%rip), %rdx      # 0xf570
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
nop