// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movq %rdi, -0x38(%rbp)
xorl %eax, %eax
leaq 0xff4e(%rip), %rcx      # 0x15cd0
leaq 0x10027(%rip), %rdx     # 0x15db0
cmpq $0xd8, %rax
je 0x5da2
movl $0x2710, (%rax,%rcx)    # imm = 0x2710
andl $0x0, (%rax,%rdx)
addq $0x4, %rax
jmp 0x5d89
pushq $0x8
popq %rax
leaq 0x101c4(%rip), %rcx     # 0x15f70
xorps %xmm0, %xmm0
cmpq $0x968, %rax            # imm = 0x968
je 0x5dc9
movl $0x70, -0x8(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
addq $0x18, %rax
jmp 0x5daf
leaq -0xa0(%rbp), %r12
xorl %ebx, %ebx
imulq $0x18, %rbx, %rax
leaq (%rcx,%rax), %r15
leaq (%rax,%rcx), %r14
addq $0x8, %r14
leaq 0x1(%rbx), %rax
movq %rax, -0x30(%rbp)
movb $0x1, %r13b
movq -0x38(%rbp), %rdi
leaq 0x8e60(%rip), %rsi      # 0xec58
movq %r12, %rdx
xorl %eax, %eax
callq 0x3070
cmpl $-0x1, %eax
je 0x5ea8
cmpb $0x2e, -0xa0(%rbp)
je 0x5e98
movq %r12, %rdi
callq 0x5cfa
testb $0x1, %r13b
je 0x5e75
movl %eax, (%r15)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movl %eax, %edi
callq 0x5323
cltq
leaq 0xfe90(%rip), %rdx      # 0x15cd0
movslq (%rdx,%rax,4), %rcx
cmpq %rcx, %rbx
jge 0x5e4c
movl %ebx, (%rdx,%rax,4)
leaq 0xff5d(%rip), %rcx      # 0x15db0
movslq (%rcx,%rax,4), %rcx
xorl %r13d, %r13d
cmpq %rcx, %rbx
jl 0x5ded
leaq 0xff4a(%rip), %rcx      # 0x15db0
movq -0x30(%rbp), %rdx
movl %edx, (%rcx,%rax,4)
xorl %r13d, %r13d
jmp 0x5ded
movl %eax, %edi
callq 0x5d41
cmpq $0x0, (%r14)
movq %r14, %rcx
je 0x5e89
movq 0x10(%r15), %rcx
movq %rax, (%rcx)
movq %rax, 0x10(%r15)
xorl %r13d, %r13d
jmp 0x5ded
movq -0x30(%rbp), %rbx
leaq 0x100cd(%rip), %rcx     # 0x15f70
jmp 0x5dd2
movq 0xe149(%rip), %r15      # 0x13ff8
leaq 0xe89a(%rip), %r13      # 0x14750
xorl %r12d, %r12d
xorl %r14d, %r14d
leaq 0xfe0d(%rip), %rax      # 0x15cd0
leaq 0xfee6(%rip), %rcx      # 0x15db0
cmpq $0xd8, %r14
je 0x5f47
movl (%r14,%rax), %r8d
cmpl $0x71, %r8d
jge 0x5eef
movl (%r14,%rcx), %r8d
testl %r8d, %r8d
jle 0x5f1b
addq $0x4, %r14
incl %r12d
jmp 0x5eca
movq (%r15), %rdi
movq 0x1d0(%r13,%r14,2), %rdx
leaq 0x7a98(%rip), %rsi      # 0xd999
movl %r12d, %ecx
xorl %eax, %eax
callq 0x3130
leaq 0xfe9e(%rip), %rcx      # 0x15db0
leaq 0xfdb7(%rip), %rax      # 0x15cd0
jmp 0x5edd
movq (%r15), %rdi
movq 0x1d0(%r13,%r14,2), %rdx
leaq 0x7a85(%rip), %rsi      # 0xd9b2
movl %r12d, %ecx
xorl %eax, %eax
callq 0x3130
leaq 0xfe72(%rip), %rcx      # 0x15db0
leaq 0xfd8b(%rip), %rax      # 0x15cd0
jmp 0x5ee6
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq