// File: /workspace/github_c_makefile_star2_O1/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 0x1055f(%rip), %rdi     # 0x16db0
xorl %ebx, %ebx
movl $0xd8, %edx
xorl %esi, %esi
callq 0x30f0
leaq 0x1046a(%rip), %rax     # 0x16cd0
movl $0x2710, (%rbx,%rax)    # imm = 0x2710
addq $0x4, %rbx
cmpq $0xd8, %rbx
jne 0x6866
movl $0x8, %eax
leaq 0x106ea(%rip), %rbx     # 0x16f70
xorps %xmm0, %xmm0
movl $0x70, -0x8(%rax,%rbx)
movups %xmm0, (%rax,%rbx)
addq $0x18, %rax
cmpq $0x968, %rax            # imm = 0x968
jne 0x6889
leaq 0x93b0(%rip), %rsi      # 0xfc58
movq $0x0, -0x30(%rbp)
leaq -0xb0(%rbp), %rdx
movq -0x38(%rbp), %rdi
xorl %eax, %eax
callq 0x3070
cmpl $-0x1, %eax
je 0x69e2
leaq -0xb0(%rbp), %r12
xorl %ecx, %ecx
leaq (%rcx,%rcx,2), %rax
leaq (%rbx,%rax,8), %r13
leaq (%rbx,%rax,8), %r15
addq $0x8, %r15
movq %rcx, -0x30(%rbp)
leaq 0x1(%rcx), %rax
movq %rax, -0x40(%rbp)
movb $0x1, %bl
cmpb $0x2e, -0xb0(%rbp)
je 0x69b0
movq %r12, %r14
movq %r12, %rdi
callq 0x67be
movl %eax, %r12d
testb $0x1, %bl
je 0x695c
movl %r12d, (%r13)
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movl %r12d, %edi
callq 0x5cf7
cltq
leaq 0x103a2(%rip), %rdx     # 0x16cd0
movslq (%rdx,%rax,4), %rcx
movq -0x30(%rbp), %rsi
cmpq %rcx, %rsi
jge 0x693e
movl %esi, (%rdx,%rax,4)
leaq 0x1046b(%rip), %rdx     # 0x16db0
movslq (%rdx,%rax,4), %rcx
cmpq %rcx, %rsi
movq %r14, %r12
jl 0x6958
movq -0x40(%rbp), %rcx
movl %ecx, (%rdx,%rax,4)
xorl %ebx, %ebx
jmp 0x6990
movl $0x18, %edi
callq 0x3150
movl %r12d, 0x8(%rax)
movq $0x0, (%rax)
movq $-0x1, 0x10(%rax)
cmpq $0x0, (%r15)
movq %r15, %rcx
je 0x6986
movq 0x10(%r13), %rcx
movq %rax, (%rcx)
movq %rax, 0x10(%r13)
movq %r14, %r12
movq -0x38(%rbp), %rdi
leaq 0x92bd(%rip), %rsi      # 0xfc58
movq %r12, %rdx
xorl %eax, %eax
callq 0x3070
cmpl $-0x1, %eax
jne 0x68f2
jmp 0x69e2
movq -0x38(%rbp), %rdi
leaq 0x929d(%rip), %rsi      # 0xfc58
movq %r12, %rdx
xorl %eax, %eax
callq 0x3070
movq -0x40(%rbp), %rdx
movq %rdx, %rcx
cmpl $-0x1, %eax
leaq 0x1059a(%rip), %rbx     # 0x16f70
jne 0x68d4
movl %edx, %eax
movq %rax, -0x30(%rbp)
xorl %ebx, %ebx
xorl %r14d, %r14d
leaq 0x103c2(%rip), %rax     # 0x16db0
leaq 0x102db(%rip), %rcx     # 0x16cd0
movl (%rbx,%rcx), %esi
cmpl $0x71, %esi
jge 0x6a13
movl (%rbx,%rax), %esi
testl %esi, %esi
jle 0x6a2b
incq %r14
addq $0x4, %rbx
cmpq $0x36, %r14
jne 0x69f5
jmp 0x6a43
movq %r14, %rdi
callq 0x36c2
leaq 0x102ae(%rip), %rcx     # 0x16cd0
leaq 0x10387(%rip), %rax     # 0x16db0
jmp 0x69fd
movq %r14, %rdi
callq 0x36f5
leaq 0x10296(%rip), %rcx     # 0x16cd0
leaq 0x1036f(%rip), %rax     # 0x16db0
jmp 0x6a04
movq -0x30(%rbp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq