// File: /workspace/github_c_makefile_star2_O0/pipde[P]deos-songlib/utils/processtab/tabchecker.c
// Function: newCompositionFromTab
Composition *
newCompositionFromTab(ASTTab *astTab)
    {
    Composition *c = newComposition();
    Part *part;
    Measure *measure;
    Section *section = 0;
    int i, j, k, partIndex, measureCount = 0;
    ASTCommand *astCommand;
    ASTStave *astStave;
    ASTCourse *astCourse;
    char *astEvents, *astTimingEvents;
    ASTAttributeList *attributeList = 0, *originalList = 0;
    bool attributeAdded;
        
    /* First pass checks all the stave courses and creates parts */
    
    for (i = 0; i < astTab->commandCount; i++)
        {
        astCommand = astTab->commands[i];
        if (astCommand->commandType == StaveCommand)
            {
            astStave = astCommand->un.stave;
            for (j = 0; j < astStave->courseCount; j++)
                {
                astCourse = astStave->courses[j];
                part = 0;
                /* Add measure to each part */
                for (partIndex = 0; partIndex < c->partCount; partIndex++)
                    {                
                    if (strcmp(astCourse->name, c->parts[partIndex]->voiceName) == 0) 
                        {
                        part = c->parts[partIndex];
                        break;
                        }
                    }
                    
                if (part == 0)
                    {
                    /* Set up part */
                    part = newPart();
                    part->voiceName = StringDup(astCourse->name);
                    addPartToComposition(part, c);
                    }
                }
            }
        }
    
    /* Second pass reads attributes and staves and populates sections, measures, and note instances */
    
    for (i = 0; i < astTab->commandCount; i++)
        {
        astCommand = astTab->commands[i];
        /* attribute command */
        if (astCommand->commandType == AttributeCommand) 
            {
            attributeList = addAttributeToList(astCommand->un.attribute, attributeList);
                        
            /* add attribute name to composition if it hasn't already been added */
            attributeAdded = false;
            for (j = 0; j < c->attributeNameCount; j++)
                {
                if (strcmp(astCommand->un.attribute->name, c->attributeNames[j]) == 0) attributeAdded = true;
                }
            if (!attributeAdded)
                {
                addAttributeNameToComposition(astCommand->un.attribute->name, c);
                }
           }
        /* stave command */
        else if (astCommand->commandType == StaveCommand)
            {
            astStave = astCommand->un.stave;
            
            /* Begin a section at each new stave */
            section = newSection();
            section->measureNumber = measureCount;
            addSectionToComposition(section, c);
            
            /* Add current attributes to section, removing them from the list */
            while (attributeList != 0)
                {
                addAttributeToSection(attributeList->attribute, section);
                originalList = attributeList;
                attributeList = attributeList->next;
                free(originalList); 
                originalList = 0;
                }
            
            /* Add measures to each part */
            for (partIndex = 0; partIndex < c->partCount; partIndex++)
                {                
                part = c->parts[partIndex];
                
                for (j = 0; j < astStave->timingCourse->measureCount; j++)
                    {
                    measure = newMeasure();
                    measure->beatsInMeasure = 4; /* TODO: replace with attribute */
                    measure->beatLength = 4;     /* TODO: replace with attribute */
                    addMeasureToPart(measure, part);
                    
                    astTimingEvents = astStave->timingCourse->measures[j]->events;
                    
                    /* find course in this stave that matches the part, then populate noteInstances */
                    for (k = 0; k < astStave->courseCount; k++)
                        {
                        astCourse = astStave->courses[k];
                        if (strcmp(astCourse->name, part->voiceName) != 0) continue;
                        
                        /* build note instances based on timing events */            
                        astEvents = astCourse->measures[j]->events;
                        buildMeasureFromASTEvents(measure, astEvents, astTimingEvents);
                        }
                    
                    /* course for this part not found; populate with rests */
                    if (measure->noteInstances == 0) buildMeasureFromASTEvents(measure, 0, astTimingEvents);
                    }
                }
            
            /* Advance measure count */
            measureCount += astStave->timingCourse->measureCount;
            }
        /* comment command */
        else if (astCommand->commandType == CommentCommand) 
            {
            /* skip */
            }
        /* unknown command */
        else
            {
            Fatal("AstCommand of type '%i' found; aborting\n", astCommand->commandType);
            return 0;
            }
        }
    
    return c;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
callq 0x4d70
movq %rax, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x44(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x505b
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x504b
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x5049
movq -0x58(%rbp), %rax
movq (%rax), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x5005
movq -0x60(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rsi
callq 0x10e0
cmpl $0x0, %eax
jne 0x4ff8
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
jmp 0x5005
jmp 0x4ffa
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4fb3
cmpq $0x0, -0x20(%rbp)
jne 0x5039
callq 0x4dc0
movq %rax, -0x20(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rdi
callq 0x65f0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5340
jmp 0x503b
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4f81
jmp 0x504b
jmp 0x504d
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x4f3e
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x531e
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x511c
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x78(%rbp), %rsi
callq 0x53f0
movq %rax, -0x78(%rbp)
movb $0x0, -0x81(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jge 0x50fa
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x10e0
cmpl $0x0, %eax
jne 0x50ed
movb $0x1, -0x81(%rbp)
jmp 0x50ef
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x50b5
testb $0x1, -0x81(%rbp)
jne 0x5117
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x5490
jmp 0x530e
movq -0x50(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x52e1
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
callq 0x4eb0
movq %rax, -0x30(%rbp)
movl -0x44(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5540
cmpq $0x0, -0x78(%rbp)
je 0x5193
movq -0x78(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x55f0
movq -0x78(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rdi
callq 0x1030
movq $0x0, -0x80(%rbp)
jmp 0x5155
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x52ce
movq -0x18(%rbp), %rax
movq (%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x58(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpl 0x10(%rcx), %eax
jge 0x52be
callq 0x4e10
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x4, 0xc(%rax)
movq -0x28(%rbp), %rax
movl $0x4, 0x10(%rax)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x5690
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x5293
movq -0x58(%rbp), %rax
movq (%rax), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x10e0
cmpl $0x0, %eax
je 0x5260
jmp 0x5288
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x5740
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5226
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x52ae
movq -0x28(%rbp), %rdi
movq -0x70(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0x5740
jmp 0x52b0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x51c4
jmp 0x52c0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x519a
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x530c
movq -0x50(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x52ec
jmp 0x530a
movq -0x50(%rbp), %rax
movl (%rax), %esi
leaq 0x30ca(%rip), %rdi      # 0x83c3
movb $0x0, %al
callq 0x63e0
movq $0x0, -0x8(%rbp)
jmp 0x5326
jmp 0x530c
jmp 0x530e
jmp 0x5310
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5062
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)