// File: /workspace/github_c_makefile_star2_O3/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, %r12d
movq %rdi, %r15
leaq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x479f
movq %rbx, %rdi
movl $0x1, %esi
callq 0x4821
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4821
leaq -0x90(%rbp), %r13
movq %r13, %rdi
callq 0x57a7
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x57dd
movl $0x40, %edi
callq 0x3150
xorl %ebx, %ebx
movq %rbx, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movups %xmm0, 0x20(%rax)
movq %rbx, 0x30(%rax)
movl %r12d, 0x10(%rax)
movq %rax, %rdi
callq 0x78cc
movq %rax, %r12
movq %r15, -0x48(%rbp)
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x59cc
movq %r12, -0x40(%rbp)
movq %r12, %r15
leaq -0x38(%rbp), %r12
movq %r12, %rdi
callq 0x48f1
cmpl $0x39, %eax
jg 0x73b7
cmpl -0x50(%rbp), %eax
jne 0x748f
movq %r12, %rdi
callq 0x4908
movq (%r15), %rdi
movq %r14, %rsi
callq 0x5d9c
movq 0x20(%r15), %r12
testq %r12, %r12
jne 0x74a0
movq 0x8(%r15), %r15
testq %r15, %r15
jne 0x7399
xorl %r12d, %r12d
jmp 0x74a0
movq %r12, %rdi
callq 0x48f1
movl %eax, %edi
callq 0x5d07
cltq
movslq -0x50(%rbp), %rcx
imulq $0xe8, %rax, %rax
leaq 0x10866(%rip), %rdx     # 0x17c40
addq %rdx, %rax
movslq (%rax,%rcx,4), %r13
cmpq $-0x1, %r13
je 0x74b7
movq %r12, %rdi
callq 0x4908
movq %r12, %rdi
leaq (,%r13,2), %r12
addq %r13, %r12
leaq 0xfb68(%rip), %r14      # 0x16f70
movq 0x8(%r14,%r12,8), %rsi
callq 0x5d50
movq 0x8(%r14,%r12,8), %r12
movq (%r15), %rax
movl %r13d, 0x18(%rax)
movl -0x68(%rbp), %ecx
movl %ecx, (%rax)
movl -0x64(%rbp), %ecx
movl %ecx, 0x4(%rax)
testq %r12, %r12
je 0x746b
movl 0x8(%r12), %r13d
movl $0x40, %edi
callq 0x3150
movq %rbx, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movups %xmm0, 0x20(%rax)
movq %rbx, 0x30(%rax)
movl %r13d, 0x10(%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0x7913
movq (%r12), %r12
jmp 0x7429
movq 0x10(%r15), %r12
testq %r12, %r12
leaq -0x68(%rbp), %r14
jne 0x74cc
movq 0x20(%r15), %r12
testq %r12, %r12
jne 0x74cc
movq 0x8(%r15), %r15
testq %r15, %r15
jne 0x7478
xorl %r12d, %r12d
jmp 0x74cc
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x717b
movq %rax, %r12
movq -0x48(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x59cc
jmp 0x74cc
leaq -0x68(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x722e
movq %rax, %r12
cmpl $0x1, -0x30(%rbp)
movq %r12, %r15
jg 0x736c
leaq -0x38(%rbp), %rdi
callq 0x48f1
cmpl $0x1, %eax
jne 0x750c
leaq -0x38(%rbp), %rdi
callq 0x47b3
movl -0x70(%rbp), %eax
addl %eax, 0x103d7(%rip)     # 0x178d0
movq -0x40(%rbp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x374a
jmp 0x74e7