// File: /workspace/github_c_makefile_star2_O0/Gaurang18[P]Compiler-Project-BITS-Pilani/./parser.c
// Function: printTree
void printTree(parsetree head){             //print tree on console
    if((head==NULL)||(head->value==109)){
        //printf("head = NULL\n");
        return;
    }

    printTree(head->child);
    

    char* lexemeCurrentNode = (char*) malloc(30*sizeof(char));
    int lineno;
    char* token = (char*) malloc(30*sizeof(char));
    char* parentNodeSymbol = (char*) malloc(30*sizeof(char));
    char* valueIfNumber = (char*) malloc(30*sizeof(char));
    char* isleafNode = (char*) malloc(30*sizeof(char));
    char* NodeSymbol = (char*) malloc(30*sizeof(char));
    

    strcpy(token, terms[head->value]);
    lineno = head->Lex->tk->line;

    if(head->parent == NULL)
            strcpy(parentNodeSymbol, "ROOT");
        else{
             strcpy(parentNodeSymbol, terms[head->parent->value]);
        }


    if(head->isleaf == 0)
        strcpy(isleafNode, "no");
    else
        strcpy(isleafNode, "yes");




    if(head->value > NON_TERMINALS){
        strcpy(lexemeCurrentNode, head->Lex->tk->value);
        strcpy(NodeSymbol, "----");
        
    }
    else{
        strcpy(lexemeCurrentNode, "----");
        strcpy(NodeSymbol, terms[head->value]);
    }

    if(head->value == 107 || head->value == 108)
        strcpy(valueIfNumber, head->Lex->tk->value);
    else
        strcpy(valueIfNumber, "----");

    

    //int line = head->lexeme->line;
    //printf("copied everything... line= %d\n", line);

    printf("%-25s %-3d %-24s %-14s %-24s %-10s %-24s\n", lexemeCurrentNode, lineno, token, valueIfNumber, parentNodeSymbol, isleafNode, NodeSymbol);
    free(token);
    free(lexemeCurrentNode);
    free(parentNodeSymbol);
    free(valueIfNumber);
    free(isleafNode);
    free(NodeSymbol);

    
    printTree(head->right);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x4b7d
movq -0x8(%rbp), %rax
cmpl $0x6d, 0x8(%rax)
jne 0x4b82
jmp 0x4d89
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x4b60
movl $0x1e, %edi
callq 0x2130
movq %rax, -0x10(%rbp)
movl $0x1e, %edi
callq 0x2130
movq %rax, -0x20(%rbp)
movl $0x1e, %edi
callq 0x2130
movq %rax, -0x28(%rbp)
movl $0x1e, %edi
callq 0x2130
movq %rax, -0x30(%rbp)
movl $0x1e, %edi
callq 0x2130
movq %rax, -0x38(%rbp)
movl $0x1e, %edi
callq 0x2130
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq 0x8(%rax), %rcx
leaq 0xe05a(%rip), %rax      # 0x12c50
movq (%rax,%rcx,8), %rsi
callq 0x2050
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movl 0x3c(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x4c2c
movq -0x28(%rbp), %rdi
leaq 0x7a04(%rip), %rsi      # 0xc629
callq 0x2050
jmp 0x4c4c
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movslq 0x8(%rax), %rcx
leaq 0xe00d(%rip), %rax      # 0x12c50
movq (%rax,%rcx,8), %rsi
callq 0x2050
movq -0x8(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x4c68
movq -0x38(%rbp), %rdi
leaq 0x7b32(%rip), %rsi      # 0xc793
callq 0x2050
jmp 0x4c78
movq -0x38(%rbp), %rdi
leaq 0x79bb(%rip), %rsi      # 0xc62e
callq 0x2050
movq -0x8(%rbp), %rax
cmpl $0x33, 0x8(%rax)
jle 0x4cab
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rsi
addq $0x1e, %rsi
callq 0x2050
movq -0x40(%rbp), %rdi
leaq 0x798e(%rip), %rsi      # 0xc632
callq 0x2050
jmp 0x4cd7
movq -0x10(%rbp), %rdi
leaq 0x797c(%rip), %rsi      # 0xc632
callq 0x2050
movq -0x40(%rbp), %rdi
movq -0x8(%rbp), %rax
movslq 0x8(%rax), %rcx
leaq 0xdf82(%rip), %rax      # 0x12c50
movq (%rax,%rcx,8), %rsi
callq 0x2050
movq -0x8(%rbp), %rax
cmpl $0x6b, 0x8(%rax)
je 0x4ceb
movq -0x8(%rbp), %rax
cmpl $0x6c, 0x8(%rax)
jne 0x4d04
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rsi
addq $0x1e, %rsi
callq 0x2050
jmp 0x4d14
movq -0x30(%rbp), %rdi
leaq 0x7923(%rip), %rsi      # 0xc632
callq 0x2050
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x38(%rbp), %r10
movq -0x40(%rbp), %rax
leaq 0x7901(%rip), %rdi      # 0xc637
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2090
movq -0x20(%rbp), %rdi
callq 0x2030
movq -0x10(%rbp), %rdi
callq 0x2030
movq -0x28(%rbp), %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x40(%rbp), %rdi
callq 0x2030
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x4b60
addq $0x50, %rsp
popq %rbp
retq
nop