// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %rdi, %r14
movl $0x18, %edi
callq 0x5257
movq %rax, %rbx
xorl %eax, %eax
movq %rax, (%rbx)
movl $0x0, 0x8(%rbx)
movq %rax, 0x10(%rbx)
movq %r14, %rdi
callq 0x10e0
movl %eax, %ebp
movsbl %bpl, %edi
movq %r14, %rsi
callq 0x1160
testb %bpl, %bpl
je 0x3125
movzbl %bpl, %eax
cmpl $0xa, %eax
je 0x3125
cmpl $0xff, %eax
je 0x3125
movq %r14, %rdi
callq 0x3761
testq %rax, %rax
je 0x3104
movq %rax, %r15
movq (%rax), %rax
cmpb $0x0, (%rax)
je 0x310b
movq (%rbx), %r12
movl 0x8(%rbx), %eax
leal 0x8(,%rax,8), %edi
callq 0x5257
movq %rax, (%rbx)
movslq 0x8(%rbx), %rcx
testq %rcx, %rcx
jle 0x30f5
xorl %eax, %eax
movq (%r12,%rax,8), %rdx
movq (%rbx), %rsi
movq %rdx, (%rsi,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x30df
movq (%rbx), %rax
movq %r15, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movl %eax, 0x8(%rbx)
jmp 0x3074
xorl %ebx, %ebx
jmp 0x3226
movq %r15, 0x10(%rbx)
movq %r14, %rdi
callq 0x10e0
movl %eax, %ebp
movsbl %bpl, %edi
movq %r14, %rsi
callq 0x1160
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x31f6
movslq 0x8(%rbx), %rax
movq %rax, 0x20(%rsp)
testq %rax, %rax
jle 0x31d7
movq (%rbx), %rsi
movq 0x10(%rsp), %rax
movl 0x10(%rax), %r12d
xorl %eax, %eax
movq %rsi, 0x18(%rsp)
movq (%rsi,%rax,8), %rdx
movq %rdx, 0x8(%rsp)
movl 0x10(%rdx), %edx
cmpl %r12d, %edx
jne 0x324e
movq %rax, 0x28(%rsp)
testl %r12d, %r12d
jle 0x31c3
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r13
xorl %r14d, %r14d
movq 0x30(%rsp), %rax
movq (%rax,%r14,8), %rax
movq (%rax), %rdi
callq 0x1080
movq %rax, %r15
movq (%r13,%r14,8), %rax
movq (%rax), %rdi
callq 0x1080
cmpq %rax, %r15
jne 0x3208
incq %r14
cmpq %r14, %r12
jne 0x3195
movq 0x28(%rsp), %rax
incq %rax
cmpq 0x20(%rsp), %rax
movq 0x18(%rsp), %rsi
jne 0x315c
cmpb $0xa, %bpl
je 0x3226
movzbl %bpl, %eax
cmpl $0xff, %eax
je 0x3226
cmpl $0x7c, %eax
jne 0x3238
leaq 0x3e9b(%rip), %rdi      # 0x708f
jmp 0x31fd
leaq 0x3dec(%rip), %rdi      # 0x6fe9
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5138
jmp 0x3226
movq 0x8(%rsp), %rcx
movq (%rcx), %rsi
leaq 0x3e30(%rip), %rdi      # 0x7047
xorl %ebx, %ebx
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x5138
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbl %bpl, %esi
leaq 0x3e7b(%rip), %rdi      # 0x70be
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5138
jmp 0x3226
movq 0x8(%rsp), %rax
movq (%rax), %rsi
leaq 0x3dae(%rip), %rdi      # 0x700b
xorl %ebx, %ebx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x5138
jmp 0x3226