// File: /workspace/github_c_makefile_star2_O0/Gaurang18[P]Compiler-Project-BITS-Pilani/./parser.c
// Function: insert
void insert(parsetree x, int rule, int G[][14], node* Lex){ //to insert a node in the parsetree

    int *r = G[rule-1];
    int i = 1;
    parsetree temp, temp2, right, left;

    x->isVisited = 1;
    x->rule = rule;

    while(r[i]!=-1){
        int j;
        temp = (parsetree) malloc(sizeof (struct Parse_Tree));
        temp->Lex = createnode();
        temp->Lex->tk->line = Lex->tk->line;
        temp->generated = 0;
        //temp->Lex = (node *) malloc sizeof(node);
        //temp->Lex->tk = (tokenInfo *) malloc sizeof (tokenInfo);
        temp->value =  r[i];
        
        if(r[i] > NON_TERMINALS)
        {
            temp->isleaf = 1;
            //temp->Lex = getNextToken();
        }
        else
            {
                //temp->Lex = NULL;
                temp->isleaf = 0;
            }
        temp->left = NULL;
        temp->right = NULL;
        temp->child = NULL;
        temp->parent = x;
        //temp->Lex = Lex;
        temp->isVisited = 0;

        if(x->child==NULL)
            x->child = temp;
        else                            //if x has children already
        {
            temp2 = x->child;
            while(temp2->right!=NULL)
            {
                right = temp2->right;
                temp2 = right;

            }

            temp2->right = temp;
            temp->left = temp2;
             
        }


        i++;
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl $0x1, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movl $0x1, 0x3c(%rax)
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
je 0x4b4b
movl $0x40, %edi
callq 0x2130
movq %rax, -0x38(%rbp)
callq 0x22c0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl 0x3c(%rax), %ecx
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movl %ecx, 0x3c(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpl $0x33, (%rax,%rcx,4)
jle 0x4a99
movq -0x38(%rbp), %rax
movl $0x1, 0x38(%rax)
jmp 0x4aa4
movq -0x38(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x38(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x8(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x3c(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x4af8
movq -0x38(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x4b3d
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x4b25
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x4b04
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4a1b
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)