// File: /workspace/github_c_makefile_star2_O1/Gaurang18[P]Compiler-Project-BITS-Pilani/./parser.c
// Function: printToFile
void printToFile(parsetree head){ //used to print to file

    //fseek(fp, 0, SEEK_END);

    if((head==NULL)||(head->value==109)){
        //printf("head = NULL\n");
       // fclose(fp);
        return;
    }

     printToFile(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));         //the different values to be output
    

    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 rule = head->rule;

    //to print in columns

    fprintf(stdout, "\r\n %-25s %-6d %-24s %-14s %-24s %-10s %-24s %-4d\n ", lexemeCurrentNode, lineno, token, valueIfNumber, parentNodeSymbol, isleafNode, NodeSymbol, rule);
    

    free(token);
    free(lexemeCurrentNode);
    free(parentNodeSymbol);
    free(valueIfNumber);
    free(isleafNode);
    free(NodeSymbol);

   
    printToFile(head->right);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x8e71(%rip), %r12      # 0xca80
testq %rbx, %rbx
je 0x3df1
cmpl $0x6d, 0x8(%rbx)
je 0x3df1
movq 0x18(%rbx), %rdi
callq 0x3bf4
movl $0x1e, %edi
callq 0x2150
movq %rax, -0x40(%rbp)
movl $0x1e, %edi
callq 0x2150
movq %rax, %r15
movl $0x1e, %edi
callq 0x2150
movq %rax, %r13
movl $0x1e, %edi
callq 0x2150
movq %rax, -0x60(%rbp)
movl $0x1e, %edi
callq 0x2150
movq %rax, -0x38(%rbp)
movl $0x1e, %edi
callq 0x2150
movq %rax, -0x30(%rbp)
movslq 0x8(%rbx), %r14
movq (%r12,%r14,8), %rsi
movq %r15, -0x78(%rbp)
movq %r15, %rdi
movq %rsi, -0x68(%rbp)
callq 0x2060
movq (%rbx), %rcx
movq 0x30(%rbx), %rax
movq %rcx, -0x50(%rbp)
movq (%rcx), %rcx
movl 0x3c(%rcx), %ecx
movl %ecx, -0x44(%rbp)
testq %rax, %rax
movq %r13, -0x58(%rbp)
je 0x3cc4
movslq 0x8(%rax), %rax
movq (%r12,%rax,8), %rsi
movq %r13, %rdi
callq 0x2060
jmp 0x3cd1
movb $0x0, 0x4(%r13)
movl $0x544f4f52, (%r13)     # imm = 0x544F4F52
cmpl $0x0, 0x38(%rbx)
movq -0x60(%rbp), %r15
je 0x3ce7
movq -0x38(%rbp), %rax
movl $0x736579, (%rax)       # imm = 0x736579
jmp 0x3cf4
movq -0x38(%rbp), %rax
movb $0x0, 0x2(%rax)
movw $0x6f6e, (%rax)         # imm = 0x6F6E
movq %rbx, %r12
cmpl $0x34, %r14d
jl 0x3d21
movq -0x50(%rbp), %rax
movq (%rax), %rsi
addq $0x1e, %rsi
movq -0x40(%rbp), %rdi
callq 0x2060
movq -0x30(%rbp), %rax
movl $0x2d2d2d2d, (%rax)     # imm = 0x2D2D2D2D
movb $0x0, 0x4(%rax)
jmp 0x3d3c
movq -0x40(%rbp), %rax
movb $0x0, 0x4(%rax)
movl $0x2d2d2d2d, (%rax)     # imm = 0x2D2D2D2D
movq -0x30(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x2060
movq -0x58(%rbp), %rbx
addl $-0x6b, %r14d
cmpl $0x1, %r14d
ja 0x3d5f
movq -0x50(%rbp), %rax
movq (%rax), %rsi
addq $0x1e, %rsi
movq %r15, %rdi
callq 0x2060
jmp 0x3d6b
movb $0x0, 0x4(%r15)
movl $0x2d2d2d2d, (%r15)     # imm = 0x2D2D2D2D
movq %r12, -0x70(%rbp)
movl 0xc(%r12), %r10d
movq 0x9265(%rip), %rax      # 0xcfe0
movq (%rax), %rdi
leaq 0x57d1(%rip), %rsi      # 0x9556
movq -0x40(%rbp), %r14
movq %r14, %rdx
movl -0x44(%rbp), %ecx
movq -0x78(%rbp), %r12
movq %r12, %r8
movq %r15, %r9
xorl %eax, %eax
pushq %r10
movq -0x30(%rbp), %r15
pushq %r15
movq -0x38(%rbp), %r13
pushq %r13
pushq %rbx
callq 0x2130
addq $0x20, %rsp
movq %r12, %rdi
callq 0x2030
movq %r14, %rdi
callq 0x2030
movq %rbx, %rdi
movq -0x70(%rbp), %rbx
callq 0x2030
movq -0x60(%rbp), %rdi
callq 0x2030
movq %r13, %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2030
movq 0x28(%rbx), %rbx
jmp 0x3c08
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq