// File: /workspace/github_c_makefile_star2_O2/pipde[P]deos-songlib/utils/processtab/tabparser.c
// Function: parseStave
ASTStave *
parseStave(FILE *in)
    {
    ASTStave *s = newASTStave();
    ASTCourse *c = 0;
    int i, j;
    char ch;
    
    /* parseCourse consumes newline for each line, so if another is found, the stave is finished */
    while ((ch = peekChar(in)) && ch != EOF && ch != '\n')
        {
        c = parseCourse(in);
        if (c == 0) return 0;
                
        /* timing course is the last course in each stave */
        if (strcmp(c->name, "") == 0)
            {
            s->timingCourse = c;
            ch = peekChar(in);
            break;
            }   
        
        /* this is a regular course */
        addASTCourseToASTStave(c, s);              
        }
       
    if (s->timingCourse == 0)
        {
        Fatal("timing course not found in stave\n");
        return 0;
        }  
     
    for (i = 0; i < s->courseCount; i++)
        {
        c = s->courses[i];
        
        /* check measure counts against timing course */
        if (c->measureCount != s->timingCourse->measureCount)
            {
            Fatal("course '%s' has %i measures; timing course has %i measures\n", c->name, c->measureCount, s->timingCourse->measureCount);
            return 0;
            }
            
        /* check measure lengths against timing course */
        for (j = 0; j < c->measureCount; j++)
            {
            if (strlen(c->measures[j]->events) != strlen(s->timingCourse->measures[j]->events))
                {
                Fatal("course '%s' measure has length %i; timing course measure has length %i\n", 
                        c->name, strlen(c->measures[j]->events), strlen(s->timingCourse->measures[j]->events));
                return 0;
                }
            }
        }
    
    /* expect newline or EOF */    
    if (ch != '\n' && ch != EOF)
        {
        /* another course found */  
        if (ch == '|') Fatal("timing course is not the last course in stave\n");
        else Fatal("unexpected '%c'\n", ch);
        return 0;
        }
        
    return s;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
callq 0x2b03
movq %rax, %rbx
movq %r14, %rdi
callq 0x2bfa
movl %eax, %ebp
testb %al, %al
je 0x2daf
movzbl %bpl, %eax
cmpl $0xa, %eax
je 0x2daf
cmpl $0xff, %eax
je 0x2daf
movq %r14, %rdi
callq 0x335f
testq %rax, %rax
je 0x2d9a
movq %rax, %r15
movq (%rax), %rax
cmpb $0x0, (%rax)
je 0x2da1
movq (%rbx), %r12
movl 0x8(%rbx), %eax
leal 0x8(,%rax,8), %edi
callq 0x47c5
movq %rax, (%rbx)
movslq 0x8(%rbx), %rax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x2d89
movq (%r12,%rdx,8), %rsi
movq (%rbx), %rdi
movq %rsi, (%rdi,%rdx,8)
incq %rdx
jmp 0x2d74
movq (%rbx), %rcx
movq %r15, (%rcx,%rax,8)
incl %eax
movl %eax, 0x8(%rbx)
jmp 0x2d15
xorl %ebx, %ebx
jmp 0x2e77
movq %r15, 0x10(%rbx)
movq %r14, %rdi
callq 0x2bfa
movl %eax, %ebp
movq 0x10(%rbx), %rax
movq %rax, (%rsp)
testq %rax, %rax
je 0x2e67
movl 0x8(%rbx), %edx
xorl %esi, %esi
testl %edx, %edx
cmovlel %esi, %edx
xorl %edi, %edi
movq %rdx, 0x8(%rsp)
cmpq %rdx, %rdi
je 0x2e89
movq (%rbx), %rax
movq (%rax,%rdi,8), %r13
movl 0x10(%r13), %r14d
movq (%rsp), %rax
movl 0x10(%rax), %ecx
cmpl %ecx, %r14d
jne 0x2ea8
movq %rdi, 0x10(%rsp)
testl %r14d, %r14d
cmovlel %esi, %r14d
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x2e3a
movq 0x8(%r13), %rax
movq (%rax,%r12,8), %rax
movq (%rax), %rdi
callq 0x1080
movq %rax, %r15
movq (%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax,%r12,8), %rax
movq (%rax), %rdi
callq 0x1080
incq %r12
cmpq %rax, %r15
je 0x2e04
jmp 0x2e4b
movq 0x10(%rsp), %rdi
incq %rdi
movq 0x8(%rsp), %rdx
xorl %esi, %esi
jmp 0x2dd1
movq (%r13), %rsi
leaq 0x31f1(%rip), %rdi      # 0x6047
xorl %ebx, %ebx
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4610
jmp 0x2e77
leaq 0x317b(%rip), %rdi      # 0x5fe9
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4610
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0xa, %bpl
je 0x2e77
movzbl %bpl, %eax
cmpl $0xff, %eax
je 0x2e77
cmpl $0x7c, %eax
jne 0x2ec1
leaq 0x31e9(%rip), %rdi      # 0x608f
jmp 0x2e6e
movq (%r13), %rsi
leaq 0x3158(%rip), %rdi      # 0x600b
xorl %ebx, %ebx
movl %r14d, %edx
xorl %eax, %eax
callq 0x4610
jmp 0x2e77
movsbl %bpl, %esi
leaq 0x31f2(%rip), %rdi      # 0x60be
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4610
jmp 0x2e77