// File: /workspace/github_c_makefile_star2_O3/sharmaeklavya2[P]cerplag/parser.c
// Function: read_grammar
int read_grammar(FILE* fp)
// returns the number of rules read
{
    int i, j;
    for(i=0; i<NUM_NONTERMS; ++i)
    {
        rule_begin[i] = 10000;
        rule_end[i] = 0;
    }
    for(i=0; i<NUM_RULES; ++i)
    {
        rules[i].lhs = NUM_GS;
        rules[i].head = NULL;
        rules[i].tail = NULL;
    }
    i=0;
    bool lhs = true;
    char str[100];
    while(fscanf(fp, "%s", str) != EOF)
    {
        if(str[0] == '.')
        {
            i++;
            lhs = true;
            continue;
        }
        gsymb_t sid = get_gsymb_id(str);
        if(lhs)
        {
            rules[i].lhs = sid;
            rules[i].head = NULL;
            rules[i].tail = NULL;
            lhs = false;

            int ntsid = get_nt_id(sid);
            if(i < rule_begin[ntsid])
                rule_begin[ntsid] = i;
            if(i+1 > rule_end[ntsid])
                rule_end[ntsid] = i+1;
        }
        else
        {
            RuleNode* n = getRuleNode(sid);
            if(rules[i].head == NULL)
                rules[i].head = n;
            else
                rules[i].tail->next = n;
            rules[i].tail = n;
        }
    }
    for(j=0; j<NUM_NONTERMS; ++j)
    {
        if(rule_begin[j] > NUM_GS)
            fprintf(stderr, "rule_begin[%s, %d] = %d\n", GS_STRS[j + NUM_TOKENS], j, rule_begin[j]);
        if(rule_end[j] <= 0)
            fprintf(stderr, "rule_end[%s, %d] = %d\n", GS_STRS[j + NUM_TOKENS], j, rule_end[j]);
    }
    return i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, -0x38(%rbp)
leaq 0x10557(%rip), %r15     # 0x16db0
xorl %ebx, %ebx
movl $0xd8, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x30f0
leaq 0x1045f(%rip), %rax     # 0x16cd0
movl $0x2710, (%rbx,%rax)    # imm = 0x2710
addq $0x4, %rbx
cmpq $0xd8, %rbx
jne 0x6871
movl $0x8, %eax
leaq 0x106df(%rip), %rbx     # 0x16f70
xorps %xmm0, %xmm0
movl $0x70, -0x8(%rax,%rbx)
movups %xmm0, (%rax,%rbx)
addq $0x18, %rax
cmpq $0x968, %rax            # imm = 0x968
jne 0x6894
leaq 0x93a5(%rip), %rsi      # 0xfc58
movq $0x0, -0x30(%rbp)
leaq -0xb0(%rbp), %rdx
movq -0x38(%rbp), %rdi
xorl %eax, %eax
callq 0x3070
cmpl $-0x1, %eax
je 0x69fd
leaq -0xb0(%rbp), %r12
xorl %ecx, %ecx
leaq (%rcx,%rcx,2), %rax
leaq (%rbx,%rax,8), %r13
leaq (%rbx,%rax,8), %rbx
addq $0x8, %rbx
movq %rcx, -0x30(%rbp)
leaq 0x1(%rcx), %rax
movq %rax, -0x40(%rbp)
movb $0x1, %r15b
cmpb $0x2e, -0xb0(%rbp)
je 0x69c4
movq %r12, %r14
movq %r12, %rdi
callq 0x67c6
movl %eax, %r12d
testb $0x1, %r15b
je 0x696d
movl %r12d, (%r13)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movl %r12d, %edi
callq 0x5d07
cltq
leaq 0x10396(%rip), %rdx     # 0x16cd0
movslq (%rdx,%rax,4), %rcx
movq -0x30(%rbp), %rsi
cmpq %rcx, %rsi
jge 0x694a
movl %esi, (%rdx,%rax,4)
leaq 0x1045f(%rip), %rcx     # 0x16db0
movslq (%rcx,%rax,4), %rcx
cmpq %rcx, %rsi
movq %r14, %r12
jl 0x69a1
leaq 0x1044c(%rip), %rcx     # 0x16db0
movq -0x40(%rbp), %rdx
movl %edx, (%rcx,%rax,4)
jmp 0x69a1
movl $0x18, %edi
callq 0x3150
movl %r12d, 0x8(%rax)
movq $0x0, (%rax)
movq $-0x1, 0x10(%rax)
cmpq $0x0, (%rbx)
movq %rbx, %rcx
je 0x6997
movq 0x10(%r13), %rcx
movq %rax, (%rcx)
movq %rax, 0x10(%r13)
movq %r14, %r12
xorl %r15d, %r15d
movq -0x38(%rbp), %rdi
leaq 0x92a9(%rip), %rsi      # 0xfc58
movq %r12, %rdx
xorl %eax, %eax
callq 0x3070
cmpl $-0x1, %eax
jne 0x68fe
jmp 0x69f6
movq -0x38(%rbp), %rdi
leaq 0x9289(%rip), %rsi      # 0xfc58
movq %r12, %rdx
xorl %eax, %eax
callq 0x3070
movq -0x40(%rbp), %rdx
movq %rdx, %rcx
cmpl $-0x1, %eax
leaq 0x10586(%rip), %rbx     # 0x16f70
jne 0x68df
movl %edx, %eax
movq %rax, -0x30(%rbp)
leaq 0x103b3(%rip), %r15     # 0x16db0
xorl %ebx, %ebx
xorl %r14d, %r14d
leaq 0x102c7(%rip), %rax     # 0x16cd0
movl (%rbx,%rax), %esi
cmpl $0x71, %esi
jge 0x6a28
movl (%rbx,%r15), %esi
testl %esi, %esi
jle 0x6a39
incq %r14
addq $0x4, %rbx
cmpq $0x36, %r14
jne 0x6a09
jmp 0x6a4a
movq %r14, %rdi
callq 0x36c2
leaq 0x10299(%rip), %rax     # 0x16cd0
jmp 0x6a11
movq %r14, %rdi
callq 0x36f5
leaq 0x10288(%rip), %rax     # 0x16cd0
jmp 0x6a19
movq -0x30(%rbp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq