// File: /workspace/github_c_makefile_star2_O1/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 0x4c71
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 0x30db
movzbl %bpl, %eax
cmpl $0xa, %eax
je 0x30db
cmpl $0xff, %eax
je 0x30db
movq %r14, %rdi
callq 0x371a
testq %rax, %rax
je 0x30ba
movq %rax, %r15
movq (%rax), %rax
cmpb $0x0, (%rax)
je 0x30c1
movq (%rbx), %r12
movl 0x8(%rbx), %eax
leal 0x8(,%rax,8), %edi
callq 0x4c71
movq %rax, (%rbx)
movslq 0x8(%rbx), %rax
testq %rax, %rax
jle 0x30a9
xorl %ecx, %ecx
movq (%r12,%rcx,8), %rdx
movq (%rbx), %rsi
movq %rdx, (%rsi,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x3096
movq (%rbx), %rcx
movq %r15, (%rcx,%rax,8)
incl %eax
movl %eax, 0x8(%rbx)
jmp 0x302b
xorl %ebx, %ebx
jmp 0x31e0
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 0x31b1
movslq 0x8(%rbx), %rax
movq %rax, 0x20(%rsp)
testq %rax, %rax
jle 0x3192
movq (%rbx), %rdx
movq 0x10(%rsp), %rax
movl 0x10(%rax), %ecx
xorl %eax, %eax
movl %ecx, 0xc(%rsp)
movq %rdx, 0x18(%rsp)
movq (%rdx,%rax,8), %rsi
movq %rsi, (%rsp)
movl 0x10(%rsi), %r15d
cmpl %ecx, %r15d
jne 0x3208
movq %rax, 0x28(%rsp)
testl %r15d, %r15d
jle 0x317a
movq (%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x10(%rsp), %rax
movq 0x8(%rax), %r14
xorl %r13d, %r13d
movq 0x30(%rsp), %rax
movq (%rax,%r13,8), %rax
movq (%rax), %rdi
callq 0x1080
movq %rax, %r12
movq (%r14,%r13,8), %rax
movq (%rax), %rdi
callq 0x1080
cmpq %rax, %r12
jne 0x31c3
incq %r13
cmpq %r13, %r15
jne 0x314d
movq 0x28(%rsp), %rax
incq %rax
cmpq 0x20(%rsp), %rax
movl 0xc(%rsp), %ecx
movq 0x18(%rsp), %rdx
jne 0x3115
cmpb $0xa, %bpl
je 0x31e0
movzbl %bpl, %eax
cmpl $0xff, %eax
je 0x31e0
cmpl $0x7c, %eax
jne 0x31f2
leaq 0x2ee0(%rip), %rdi      # 0x608f
jmp 0x31b8
leaq 0x2e31(%rip), %rdi      # 0x5fe9
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4b44
jmp 0x31e0
movq (%rsp), %rcx
movq (%rcx), %rsi
leaq 0x2e76(%rip), %rdi      # 0x6047
xorl %ebx, %ebx
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4b44
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbl %bpl, %esi
leaq 0x2ec1(%rip), %rdi      # 0x60be
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4b44
jmp 0x31e0
movq (%rsp), %rax
movq (%rax), %rsi
leaq 0x2df5(%rip), %rdi      # 0x600b
xorl %ebx, %ebx
movl %r15d, %edx
xorl %eax, %eax
callq 0x4b44
jmp 0x31e0