// File: /workspace/github_c_makefile_star2_O1/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 0x4787
movq %rbx, %rdi
movl $0x1, %esi
callq 0x4809
movq %rbx, %rdi
movl %r12d, %esi
callq 0x4809
leaq -0x90(%rbp), %r13
movq %r13, %rdi
callq 0x5798
leaq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x57ce
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 0x78bc
movq %rax, %r12
movq %r15, -0x48(%rbp)
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x59b8
movq %r12, -0x40(%rbp)
movq %r12, %r15
leaq -0x38(%rbp), %r12
movq %r12, %rdi
callq 0x48d9
cmpl $0x39, %eax
jg 0x73a8
cmpl -0x50(%rbp), %eax
jne 0x7480
movq %r12, %rdi
callq 0x48f0
movq (%r15), %rdi
movq %r14, %rsi
callq 0x5d8c
movq 0x20(%r15), %r12
testq %r12, %r12
jne 0x7491
movq 0x8(%r15), %r15
testq %r15, %r15
jne 0x738a
xorl %r12d, %r12d
jmp 0x7491
movq %r12, %rdi
callq 0x48d9
movl %eax, %edi
callq 0x5cf7
cltq
movslq -0x50(%rbp), %rcx
imulq $0xe8, %rax, %rax
leaq 0x10875(%rip), %rdx     # 0x17c40
addq %rdx, %rax
movslq (%rax,%rcx,4), %r13
cmpq $-0x1, %r13
je 0x74a8
movq %r12, %rdi
callq 0x48f0
movq %r12, %rdi
leaq (,%r13,2), %r12
addq %r13, %r12
leaq 0xfb77(%rip), %r14      # 0x16f70
movq 0x8(%r14,%r12,8), %rsi
callq 0x5d40
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 0x745c
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 0x7903
movq (%r12), %r12
jmp 0x741a
movq 0x10(%r15), %r12
testq %r12, %r12
leaq -0x68(%rbp), %r14
jne 0x74bd
movq 0x20(%r15), %r12
testq %r12, %r12
jne 0x74bd
movq 0x8(%r15), %r15
testq %r15, %r15
jne 0x7469
xorl %r12d, %r12d
jmp 0x74bd
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x716e
movq %rax, %r12
movq -0x48(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x59b8
jmp 0x74bd
leaq -0x68(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x7221
movq %rax, %r12
cmpl $0x1, -0x30(%rbp)
movq %r12, %r15
jg 0x735d
leaq -0x38(%rbp), %rdi
callq 0x48d9
cmpl $0x1, %eax
jne 0x74fd
leaq -0x38(%rbp), %rdi
callq 0x479b
movl -0x70(%rbp), %eax
addl %eax, 0x103e6(%rip)     # 0x178d0
movq -0x40(%rbp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x68(%rbp), %rdi
callq 0x374a
jmp 0x74d8