// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movl $0x30, %edi
callq 0x5257
movq %rax, %r13
xorl %eax, %eax
movq %rax, (%r13)
movl %eax, 0x8(%r13)
movq %rax, 0x10(%r13)
movq $0x0, (%rsp)
movl %eax, 0x18(%r13)
movl 0x8(%rbx), %eax
testl %eax, %eax
jle 0x44db
xorl %edx, %edx
movq %r13, 0x18(%rsp)
movq %rbx, 0x30(%rsp)
movq (%rbx), %rcx
movq (%rcx,%rdx,8), %rcx
cmpl $0x2, (%rcx)
jne 0x413f
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rsp)
movl 0x8(%rcx), %ecx
testl %ecx, %ecx
jle 0x413f
movq %rdx, 0x20(%rsp)
xorl %ebp, %ebp
movl %ecx, 0x28(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbp,8), %r12
cmpl $0x0, (%rsp)
jle 0x408e
movq (%r12), %r15
movq 0x18(%rsp), %rax
movq (%rax), %rbx
movl (%rsp), %r14d
xorl %r13d, %r13d
movq (%rbx,%r13,8), %rax
movq 0x10(%rax), %rsi
movq %r15, %rdi
callq 0x1110
testl %eax, %eax
je 0x411a
incq %r13
cmpq %r13, %r14
jne 0x406e
movl $0x20, %edi
callq 0x5257
movq %rax, %r15
movq $0x0, (%rax)
movl $0x0, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq (%r12), %rdi
callq 0x523a
movq %rax, 0x10(%r15)
movq 0x18(%rsp), %r13
movq (%r13), %rbx
movl 0x8(%r13), %eax
leal 0x8(,%rax,8), %edi
callq 0x5257
movq %rax, (%r13)
movslq 0x8(%r13), %rcx
testq %rcx, %rcx
jle 0x40fd
xorl %eax, %eax
movq (%rbx,%rax,8), %rdx
movq (%r13), %rsi
movq %rdx, (%rsi,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x40e5
movq (%r13), %rax
movq %r15, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movq %rax, (%rsp)
movl %eax, 0x8(%r13)
movq %r13, 0x18(%r15)
movq 0x8(%rsp), %rax
movl 0x8(%rax), %ecx
jmp 0x4123
movq 0x18(%rsp), %r13
movl 0x28(%rsp), %ecx
incq %rbp
movslq %ecx, %rax
cmpq %rax, %rbp
jl 0x4045
movq 0x30(%rsp), %rbx
movl 0x8(%rbx), %eax
movq 0x20(%rsp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jl 0x401a
testl %eax, %eax
jle 0x44db
xorl %ecx, %ecx
xorl %r15d, %r15d
movl $0x0, 0x14(%rsp)
movq (%rbx), %rax
movq (%rax,%rcx,8), %r14
movl (%r14), %esi
cmpl $0x3, %esi
je 0x44b3
cmpl $0x2, %esi
movq %rcx, 0x20(%rsp)
je 0x41c3
cmpl $0x1, %esi
jne 0x44ca
movq 0x8(%r14), %rbx
movl $0x10, %edi
callq 0x5257
movq $0x0, 0x8(%rax)
movq %rbx, (%rax)
testq %r15, %r15
je 0x4423
movq %r15, %rdx
movq %rdx, %rcx
movq 0x8(%rdx), %rdx
testq %rdx, %rdx
jne 0x41ae
movq %rax, 0x8(%rcx)
jmp 0x4426
movq 0x8(%r14), %rax
movq %rax, (%rsp)
movl $0x18, %edi
callq 0x5257
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movl 0x14(%rsp), %eax
movl %eax, 0xc(%r12)
movq 0x10(%r13), %rbx
movl 0x18(%r13), %eax
leal 0x8(,%rax,8), %edi
callq 0x5257
movq %rax, 0x10(%r13)
movslq 0x18(%r13), %rcx
testq %rcx, %rcx
jle 0x422a
xorl %eax, %eax
movq (%rbx,%rax,8), %rdx
movq 0x10(%r13), %rsi
movq %rdx, (%rsi,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x4212
movq 0x10(%r13), %rax
movq %r12, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movl %eax, 0x18(%r13)
movq %r13, 0x10(%r12)
testq %r15, %r15
je 0x429f
movq (%r15), %rbx
movq (%r12), %r14
movl 0x8(%r12), %eax
leal 0x8(,%rax,8), %edi
callq 0x5257
movq %rax, (%r12)
movslq 0x8(%r12), %rcx
testq %rcx, %rcx
jle 0x427f
xorl %eax, %eax
movq (%r14,%rax,8), %rdx
movq (%r12), %rsi
movq %rdx, (%rsi,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x4267
movq (%r12), %rax
movq %rbx, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movl %eax, 0x8(%r12)
movq 0x8(%r15), %rbx
movq %r15, %rdi
callq 0x1030
movq %rbx, %r15
testq %rbx, %rbx
jne 0x423f
movl 0x8(%r13), %ecx
testl %ecx, %ecx
jle 0x4408
movq (%rsp), %rax
movq 0x10(%rax), %rax
xorl %esi, %esi
cmpl $0x0, 0x10(%rax)
jle 0x43f7
movq (%r13), %rax
movq %rsi, 0x28(%rsp)
movq (%rax,%rsi,8), %r13
movq $0x0, 0x8(%rsp)
movl $0x20, %edi
callq 0x5257
movq %rax, %r15
movq $0x0, 0x18(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0x4, %eax
movl %eax, 0xc(%r15)
movl %eax, 0x10(%r15)
movq (%r13), %rbx
movl 0x8(%r13), %eax
leal 0x8(,%rax,8), %edi
callq 0x5257
movq %rax, (%r13)
movslq 0x8(%r13), %rcx
testq %rcx, %rcx
jle 0x4338
xorl %eax, %eax
movq (%rbx,%rax,8), %rdx
movq (%r13), %rsi
movq %rdx, (%rsi,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x4320
movq (%r13), %rax
movq %r15, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movl %eax, 0x8(%r13)
movq %r13, 0x18(%r15)
movq (%rsp), %rcx
movq 0x10(%rcx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movq (%rax), %r12
movl 0x8(%rcx), %r14d
testl %r14d, %r14d
jle 0x43b4
xorl %ebx, %ebx
movq (%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rbp
movq (%rbp), %rdi
movq 0x10(%r13), %rsi
callq 0x1110
testl %eax, %eax
jne 0x43a9
movq 0x8(%rbp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x44ed
movq (%rsp), %rax
movl 0x8(%rax), %r14d
incq %rbx
movslq %r14d, %rax
cmpq %rax, %rbx
jl 0x436a
cmpq $0x0, (%r15)
jne 0x43c7
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x44ed
movq 0x8(%rsp), %rsi
incq %rsi
movq (%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x10(%rax), %rcx
movq %rsi, 0x8(%rsp)
cmpq %rcx, %rsi
jl 0x42d5
movq 0x18(%rsp), %r13
movl 0x8(%r13), %ecx
movq 0x28(%rsp), %rsi
incq %rsi
movslq %ecx, %rdx
cmpq %rdx, %rsi
jl 0x42b5
jmp 0x4410
movq (%rsp), %rax
movq 0x10(%rax), %rax
movl 0x14(%rsp), %ecx
addl 0x10(%rax), %ecx
movl %ecx, 0x14(%rsp)
xorl %r15d, %r15d
jmp 0x44ae
movq %rax, %r15
movq %r13, %rcx
movslq 0x28(%r13), %r13
movq 0x8(%r14), %rax
movq (%rax), %r12
movq 0x20(%rcx), %r14
testq %r13, %r13
jle 0x446a
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%r14,%rbx,8), %rsi
movq %r12, %rdi
callq 0x1110
testl %eax, %eax
sete %al
orb %al, %bpl
incq %rbx
cmpq %rbx, %r13
jne 0x4441
testb $0x1, %bpl
je 0x446a
movq 0x18(%rsp), %r13
jmp 0x44ae
leal 0x8(,%r13,8), %edi
callq 0x5257
movq 0x18(%rsp), %r13
movq %rax, 0x20(%r13)
movslq 0x28(%r13), %rcx
testq %rcx, %rcx
jle 0x44a3
xorl %eax, %eax
movq (%r14,%rax,8), %rdx
movq 0x20(%r13), %rsi
movq %rdx, (%rsi,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x448b
movq 0x20(%r13), %rax
movq %r12, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movl %eax, 0x28(%r13)
movq 0x20(%rsp), %rcx
incq %rcx
movq 0x30(%rsp), %rbx
movslq 0x8(%rbx), %rax
cmpq %rax, %rcx
jl 0x4163
jmp 0x44db
leaq 0x2f7f(%rip), %rdi      # 0x7450
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x5138
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq