// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x840, %rsp            # imm = 0x840
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
leaq -0x440(%rbp), %rdi
movslq -0xc(%rbp), %rcx
leaq 0x193f1(%rip), %rax     # 0x21cf0
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rcx
leaq 0x4ddb(%rip), %rsi      # 0xd6e9
movb $0x0, %al
callq 0x2260
leaq -0x440(%rbp), %rdi
leaq 0x5285(%rip), %rsi      # 0xdba8
callq 0x2220
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x8982
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9730
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x8963
leaq -0x440(%rbp), %rsi
leaq 0x4d96(%rip), %rdi      # 0xd6f2
movb $0x0, %al
callq 0x8c70
movq -0x30(%rbp), %rdi
callq 0x2090
movq -0x20(%rbp), %rdi
callq 0x8b30
movq -0x20(%rbp), %rdi
callq 0x7250
movq %rax, -0x28(%rbp)
leaq -0x840(%rbp), %rdi
movslq -0xc(%rbp), %rcx
leaq 0x1935c(%rip), %rax     # 0x21cf0
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rcx
leaq 0x4d62(%rip), %rsi      # 0xd705
movb $0x0, %al
callq 0x2260
leaq -0x840(%rbp), %rdi
callq 0x20a0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x8ac0
jmp 0x89c7
movq -0x38(%rbp), %rdi
callq 0x21c0
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x8ab7
leaq -0x440(%rbp), %rdi
movslq -0xc(%rbp), %rcx
leaq 0x19300(%rip), %rax     # 0x21cf0
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %r8
addq $0x13, %r8
leaq 0x4d04(%rip), %rsi      # 0xd70b
movb $0x0, %al
callq 0x2260
movq -0x40(%rbp), %rax
movzbl 0x12(%rax), %eax
cmpl $0x8, %eax
jne 0x8a33
leaq -0x440(%rbp), %rdi
leaq 0x4cc4(%rip), %rsi      # 0xd6ed
callq 0x8be0
cmpl $0x0, %eax
jne 0x8a35
jmp 0x89c7
leaq -0x440(%rbp), %rdi
leaq 0x5165(%rip), %rsi      # 0xdba8
callq 0x2220
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x8ab2
movq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9730
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x8a83
leaq -0x440(%rbp), %rsi
leaq 0x4c97(%rip), %rdi      # 0xd713
movb $0x0, %al
callq 0x8c70
movq -0x30(%rbp), %rdi
callq 0x2090
movq -0x20(%rbp), %rdi
callq 0x8b30
cmpq $0x0, -0x28(%rbp)
jne 0x8aa5
callq 0x8340
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x8290
jmp 0x89c7
movq -0x38(%rbp), %rdi
callq 0x2130
cmpq $0x0, -0x28(%rbp)
jne 0x8ad1
movq $0x0, -0x8(%rbp)
jmp 0x8b1a
movq -0x28(%rbp), %rdx
movslq -0xc(%rbp), %rcx
leaq 0xece0(%rip), %rax      # 0x177c0
imulq $0x420, %rcx, %rcx      # imm = 0x420
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movslq -0xc(%rbp), %rcx
leaq 0x9a43(%rip), %rax      # 0x12540
imulq $0x210, %rcx, %rcx      # imm = 0x210
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x840, %rsp            # imm = 0x840
popq %rbp
retq
nopw (%rax,%rax)