// File: /workspace/github_c_makefile_star2_O0/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
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x4170
leaq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x4240
movl -0xc(%rbp), %esi
leaq -0x20(%rbp), %rdi
callq 0x4240
leaq -0x68(%rbp), %rdi
callq 0x5930
leaq -0x40(%rbp), %rdi
callq 0x5990
movl -0xc(%rbp), %edi
callq 0x6770
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0x8b50
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x40(%rbp), %rdx
xorl %ecx, %ecx
callq 0x5c50
leaq -0x20(%rbp), %rdi
callq 0x4350
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %edi
callq 0x6430
testb $0x1, %al
jne 0x8402
cmpl $0x1, -0x84(%rbp)
jne 0x8462
movl -0x84(%rbp), %eax
cmpl -0x28(%rbp), %eax
jne 0x8435
leaq -0x20(%rbp), %rdi
callq 0x43a0
movq -0x78(%rbp), %rax
movq (%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x65e0
movq -0x78(%rbp), %rdi
callq 0x67b0
movq %rax, -0x78(%rbp)
jmp 0x844a
movq -0x78(%rbp), %rdx
leaq -0x40(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x81f0
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x40(%rbp), %rdx
xorl %ecx, %ecx
callq 0x5c50
jmp 0x857d
leaq -0x20(%rbp), %rdi
callq 0x4350
movl %eax, %edi
callq 0x6480
movslq %eax, %rcx
leaq 0x147e4(%rip), %rax     # 0x1cc60
imulq $0xe8, %rcx, %rcx
addq %rcx, %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x88(%rbp)
cmpl $-0x1, -0x88(%rbp)
je 0x8566
leaq -0x20(%rbp), %rdi
callq 0x43a0
movslq -0x88(%rbp), %rcx
leaq 0x13ad9(%rip), %rax     # 0x1bf90
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rsi
leaq -0x20(%rbp), %rdi
callq 0x6520
movslq -0x88(%rbp), %rcx
leaq 0x13ab7(%rip), %rax     # 0x1bf90
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x90(%rbp)
movl -0x88(%rbp), %ecx
movq -0x78(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x18(%rax)
movl -0x40(%rbp), %ecx
movq -0x78(%rbp), %rax
movq (%rax), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %ecx
movq -0x78(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x4(%rax)
cmpq $0x0, -0x90(%rbp)
je 0x8557
movq -0x90(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x6770
movq %rax, -0x98(%rbp)
movq -0x78(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x8bf0
movq -0x90(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x90(%rbp)
jmp 0x8514
movq -0x78(%rbp), %rdi
callq 0x6810
movq %rax, -0x78(%rbp)
jmp 0x857b
movq -0x78(%rbp), %rdx
leaq -0x40(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x82b0
movq %rax, -0x78(%rbp)
jmp 0x857d
jmp 0x857f
cmpl $0x1, -0x18(%rbp)
jg 0x83db
leaq -0x20(%rbp), %rdi
callq 0x4350
cmpl $0x1, %eax
je 0x85d6
movq 0x11a5a(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xc51f(%rip), %rsi      # 0x14ac7
movb $0x0, %al
callq 0x3120
movq 0x11a42(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
movslq -0x28(%rbp), %rcx
leaq 0x121ac(%rip), %rax     # 0x1a770
movq (%rax,%rcx,8), %rdx
leaq 0xc521(%rip), %rsi      # 0x14af0
movb $0x0, %al
callq 0x3120
leaq -0x20(%rbp), %rdi
callq 0x4190
movl -0x48(%rbp), %eax
addl 0x14308(%rip), %eax     # 0x1c8f0
movl %eax, 0x14302(%rip)     # 0x1c8f0
movq -0x80(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)