// File: /workspace/github_c_makefile_star2_O0/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 %rbx
subq $0x68, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x555e
movq -0x10(%rbp), %rax
cmpl $0x6d, 0x8(%rax)
jne 0x5563
jmp 0x578a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x5540
movl $0x1e, %edi
callq 0x2130
movq %rax, -0x18(%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)
movl $0x1e, %edi
callq 0x2130
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x8(%rax), %rcx
leaq 0xd679(%rip), %rax      # 0x12c50
movq (%rax,%rcx,8), %rsi
callq 0x2050
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movl 0x3c(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x560d
movq -0x30(%rbp), %rdi
leaq 0x7023(%rip), %rsi      # 0xc629
callq 0x2050
jmp 0x562d
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq 0x8(%rax), %rcx
leaq 0xd62c(%rip), %rax      # 0x12c50
movq (%rax,%rcx,8), %rsi
callq 0x2050
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x5649
movq -0x40(%rbp), %rdi
leaq 0x7151(%rip), %rsi      # 0xc793
callq 0x2050
jmp 0x5659
movq -0x40(%rbp), %rdi
leaq 0x6fda(%rip), %rsi      # 0xc62e
callq 0x2050
movq -0x10(%rbp), %rax
cmpl $0x33, 0x8(%rax)
jle 0x568c
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rsi
addq $0x1e, %rsi
callq 0x2050
movq -0x48(%rbp), %rdi
leaq 0x6fad(%rip), %rsi      # 0xc632
callq 0x2050
jmp 0x56b8
movq -0x18(%rbp), %rdi
leaq 0x6f9b(%rip), %rsi      # 0xc632
callq 0x2050
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x8(%rax), %rcx
leaq 0xd5a1(%rip), %rax      # 0x12c50
movq (%rax,%rcx,8), %rsi
callq 0x2050
movq -0x10(%rbp), %rax
cmpl $0x6b, 0x8(%rax)
je 0x56cc
movq -0x10(%rbp), %rax
cmpl $0x6c, 0x8(%rax)
jne 0x56e5
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rsi
addq $0x1e, %rsi
callq 0x2050
jmp 0x56f5
movq -0x38(%rbp), %rdi
leaq 0x6f42(%rip), %rsi      # 0xc632
callq 0x2050
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x4c(%rbp)
movq 0xa8da(%rip), %rax      # 0xffe0
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x30(%rbp), %rbx
movq -0x40(%rbp), %r11
movq -0x48(%rbp), %r10
movl -0x4c(%rbp), %eax
leaq 0x6f3e(%rip), %rsi      # 0xc66c
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movb $0x0, %al
callq 0x2100
movq -0x28(%rbp), %rdi
callq 0x2030
movq -0x18(%rbp), %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x40(%rbp), %rdi
callq 0x2030
movq -0x48(%rbp), %rdi
callq 0x2030
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x5540
addq $0x68, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)