// File: /workspace/github_c_makefile_star2_O2/sharmaeklavya2[P]cerplag/parser.c
// Function: build_parse_tree
parse_tree_node* build_parse_tree(FILE * ifp, gsymb_t start_sym){

    int_stack st;
    int_stack_init(&st);
    int_stack_push(&st, GS_EOF);
    int_stack_push(&st, start_sym);

    Token cur_tkn;
    Dfa dfa;
    init_dfa(&dfa);
    init_token(&cur_tkn);

    Symbol* symb = make_symbol(start_sym);
    parse_tree_node * current_tn = parse_tree_get_node(symb);
    parse_tree_node * root = current_tn;

    get_token(ifp, &dfa, &cur_tkn, false);
    //fprintf(stderr, "%s\n", GS_STRS[cur_tkn.tid]);
    do{
    gsymb_t cur_st_top = int_stack_top(&st);
    if(is_t(cur_st_top) || cur_st_top == GS_EOF){
        if(cur_st_top == cur_tkn.tid){
            int_stack_pop(&st);
            copy_symbol(current_tn->value, &cur_tkn);
            current_tn = get_successor(current_tn);
        }else{
            current_tn = handle_parse_error_1(&cur_tkn, &st, current_tn);
            //int_stack_print(&st, stderr);
        }
        get_token(ifp, &dfa, &cur_tkn, false);
        //fprintf(stderr, "%s\n", GS_STRS[cur_tkn.tid]);
        //int_stack_print(&st, stderr);
    }else{
        int rule_num = pt[get_nt_id(int_stack_top(&st))][cur_tkn.tid];
        //fprintf(stderr, "pt[%s, %d][%s, %d] = %d\n", GS_STRS[int_stack_top(&st)], get_nt_id(int_stack_top(&st)), GS_STRS[cur_tkn.tid], cur_tkn.tid, rule_num);
        if(rule_num != -1){
            int_stack_pop(&st);
            push_ll(&st, rules[rule_num].head);
            RuleNode * tmp = rules[rule_num].head;
            current_tn->value->rule_num = rule_num;
            current_tn->value->line = cur_tkn.line;
            current_tn->value->col = cur_tkn.col;
            while(tmp != NULL){
                Symbol * ps = make_symbol(tmp->value);
                parse_tree_insert(current_tn, ps);
                tmp = tmp->next;
            }
            current_tn = get_first_child_or_successor(current_tn);
        }else{
            current_tn = handle_parse_error_2(&cur_tkn, &st, current_tn);
            //int_stack_print(&st, stderr);
        }
    }
    }while(st.size > 1);
    if(int_stack_top(&st) != GS_EOF){
        fprintf(stderr, "No valid derivation of string exists! 3\n");
        fprintf(stderr, "Current Token: %s\n", GS_STRS[cur_tkn.tid]);
        //int_stack_print(&st, stderr);
    }
    int_stack_clear(&st);
    parser_error_count += dfa.error_count;
    return root;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq -0x48(%rbp), %r15
movq %r15, %rdi
callq 0x3bb9
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x3c29
movq %r15, %rdi
movl %ebx, %esi
callq 0x3c29
leaq -0x90(%rbp), %r12
movq %r12, %rdi
callq 0x4b23
leaq -0x68(%rbp), %r13
movq %r13, %rdi
callq 0x4b5b
movl %ebx, %edi
callq 0x5496
movq %rax, %rdi
callq 0x6d08
movq %rax, %rbx
movq %r14, -0x38(%rbp)
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x4cf8
movq %rbx, -0x30(%rbp)
movq %r15, %rdi
callq 0x3cf4
cmpl $0x39, %eax
jg 0x680e
cmpl -0x50(%rbp), %eax
jne 0x68aa
movq %r15, %rdi
callq 0x3d22
movq (%rbx), %rdi
movq %r13, %rsi
callq 0x53b3
movq %rbx, %rdi
callq 0x54c8
jmp 0x68b8
movq %r15, %rdi
callq 0x3cf4
movl %eax, %edi
callq 0x5323
cltq
movslq -0x50(%rbp), %rcx
imulq $0xe8, %rax, %rax
leaq 0x1040f(%rip), %rdx     # 0x16c40
addq %rdx, %rax
movslq (%rax,%rcx,4), %r14
cmpq $-0x1, %r14
je 0x68d2
movq %r15, %rdi
callq 0x3d22
movq %r15, %rdi
imulq $0x18, %r14, %r12
leaq 0xf718(%rip), %r13      # 0x15f70
movq 0x8(%r12,%r13), %rsi
callq 0x536a
movq 0x8(%r12,%r13), %r12
movq (%rbx), %rax
movl %r14d, 0x18(%rax)
movl -0x68(%rbp), %ecx
movl %ecx, (%rax)
movl -0x64(%rbp), %ecx
movl %ecx, 0x4(%rax)
testq %r12, %r12
je 0x6899
movl 0x8(%r12), %edi
callq 0x5496
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6d61
movq (%r12), %r12
jmp 0x6879
movq %rbx, %rdi
callq 0x54e4
movq %rax, %rbx
leaq -0x68(%rbp), %r13
jmp 0x68e3
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x6658
movq %rax, %rbx
movq -0x38(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x4cf8
jmp 0x68e3
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x66e1
movq %rax, %rbx
cmpl $0x1, -0x40(%rbp)
jg 0x67d8
leaq -0x48(%rbp), %rdi
callq 0x3cf4
cmpl $0x1, %eax
jne 0x6920
leaq -0x48(%rbp), %rdi
callq 0x3bc7
movl -0x70(%rbp), %eax
addl %eax, 0xffc3(%rip)      # 0x168d0
movq -0x30(%rbp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xd6d1(%rip), %rbx      # 0x13ff8
movq (%rbx), %rcx
leaq 0x7156(%rip), %rdi      # 0xda87
pushq $0x28
popq %rsi
pushq $0x1
popq %rdx
callq 0x31c0
movq (%rbx), %rdi
movslq -0x50(%rbp), %rax
leaq 0xde06(%rip), %rcx      # 0x14750
movq (%rcx,%rax,8), %rdx
leaq 0x715b(%rip), %rsi      # 0xdab0
xorl %eax, %eax
callq 0x3130
jmp 0x68fb