// File: /workspace/github_c_makefile_star2_O0/anuwu[P]ERPLAG-Compiler/parser.c
// Function: parse
treeNode* parse (FILE *fp)
{
	fillUtilityArray();
	init_parser () ;

 	int rule_index , while_count = 1 ; 	
	twinBuffer *twinBuf = lexer_init (fp) ;
	token* tk ;
 
	stacknode* stack = initStack () ;
	stack = push (stack, program) ;
	treeNode *root = create_root () ;
 	treeNode* current_node ;
	current_node = root ;

	tk = getNextToken (twinBuf) ;
	int flag=0;
	int current=-1;

	while (1)
	{		
		if(tk->id == TK_LEXERROR)
		{
			root->syntax_error=1;
			errLex () ;
			printf ("at line ") ;
			errLine (tk->lineNumber) ;
			printf (" ") ;
			errArrow () ;
			#ifdef _WIN64
				printf (" %s\n", tk->lexeme) ;
			#endif
			#if defined __linux__ || defined __MACH__
				printf (ANSI_BOLD ANSI_RED " %s\n" ANSI_RESET, tk->lexeme) ;
			#endif
		}
		
		if(stack!=NULL && stack->key<0)
		{
			flag=1;
			root->syntax_error=1;
			errParse () ;
			errArrow () ;
			#ifdef _WIN64
				printf ("Invalid symbol on stack\n") ;
			#endif
			#if defined __linux__ || defined __MACH__
				printf(ANSI_BOLD ANSI_RED "Invalid symbol on stack\n" ANSI_RESET);
			#endif
			break;
		}

		if (tk->id == TK_EOF)
		{
			if(stack!= NULL && stack->key==TK_EOF)
				break ;
			
			if(stack==NULL)
			{
				errParse () ;
				errArrow () ;
				#ifdef _WIN64
					printf ("Stack is empty\n") ;
				#endif
				#if defined __linux__ || defined __MACH__
					printf(ANSI_BOLD ANSI_RED "Stack is empty\n" ANSI_RESET);
				#endif
				break;
			}
		}
 
		if (isTerminal(stack->key)) // We are getting a terminal on top of the stack
		{
			if (stack->key == tk->id) // If top of the stack matches with the input symbol
			{
				stack = pop (stack); // Pop the element from top of the stack and move ahead
				if(flag==0) // No error has been encountered yet
				{
					//Add the terminal to the parse tree
					current_node->tnt.term->lexeme =  tk->lexeme ; 
					current_node->tnt.term->lineNumber = tk->lineNumber ;
					current_node=nextTreeNode(current_node);
				}

				// Get the new look-ahead symbol
				tk = getNextToken (twinBuf) ;
			}
			else   // The top of stack is a terminal but doesn't match with the input symbol
			{
				root->syntax_error=1;
				if(current != tk->lineNumber)
				{
					if(stack->key!= TK_SEMICOL && stack->key!= TK_ENDDEF && stack->key!= TK_DRIVERENDDEF)
					{
						errParse () ;
						printf ("at line ") ;
						errLine (tk->lineNumber) ;
						printf (" ") ;
						errArrow () ;
						#ifdef _WIN64
							printf ("%s symbol was expected\n", utility_array[stack->key]) ;
						#endif
						#if defined __linux__ || defined __MACH__
							printf (ANSI_BOLD ANSI_RED "%s" ANSI_RESET " symbol was expected\n", utility_array[stack->key]);
						#endif
						current=tk->lineNumber;
					}
					else
					{
						errParse () ;
						printf ("at line ") ;
						errLine (tk->lineNumber - 1) ;
						printf (" ") ;
						errArrow () ;
						#ifdef _WIN64
							printf ("%s symbol was expected\n", utility_array[stack->key]) ;
						#endif
						#if defined __linux__ || defined __MACH__
							printf (ANSI_BOLD ANSI_RED "%s" ANSI_RESET " symbol was expected\n", utility_array[stack->key]);
						#endif
						current=tk->lineNumber-1;
					}
					
				}
				stacknode* temp=stack;
				if(stack==NULL)
				{
					errParse () ;
					errArrow () ;
					#ifdef _WIN64
						printf ("Stack is empty\n") ;
					#endif
					#if defined __linux__ || defined __MACH__
						printf(ANSI_BOLD ANSI_RED "Stack is empty\n" ANSI_RESET);
					#endif
					break;
				}
				 stack=stack->next;

				free(temp); // Poping the stack
				flag=1; // There is an error
				
			}
		}
		else if (isNonTerminal(stack->key))
		{
			
			rule_index = parsetable[stack->key][tk->id] ;
 
			if (rule_index != -1)
			{
				stack = pushRule (stack , allRules, rule_index) ;
				if(flag==0)
				{
					current_node->gcode = rule_index ;

					addRulesParseTree (current_node , allRules, rule_index);
					current_node = current_node->child ;
 
					if(current_node->tag == TERMINAL && current_node->tnt.term->id == TK_EPS)
					{
						current_node->tnt.term->lineNumber = tk->lineNumber ;
						current_node=nextTreeNode(current_node);
					}
				}
			}
			else
			{
				root->syntax_error=1;
				if(current != tk->lineNumber)
				{
					errParse () ;
					printf ("at line ");
					errLine (tk->lineNumber) ;
					printf ("\n") ;
					current=tk->lineNumber;
				}

				if(stack==NULL)
				{
					errParse () ;
					errArrow () ;
					#ifdef _WIN64
						printf ("Stack is empty\n") ;
					#endif
					#if defined __linux__ || defined __MACH__
						printf(ANSI_BOLD ANSI_RED "Stack is empty\n" ANSI_RESET);
					#endif
					break;
				}
				flag=1;
					while(1)
					{
						node* temp=NULL;
						temp=follows[stack->key];
						while(temp != NULL && temp->key != tk->id)
							temp=temp->next;

						if(stack!=NULL && temp!=NULL)
						{
							stack=pop(stack);
							break;
						}

						else
						{
							if(tk->id != TK_EOF)
							{
								tk=getNextToken(twinBuf);
								
								if(tk->id == TK_LEXERROR)
								{
									root->syntax_error=1;
									errLex () ;
									printf ("at line ") ;
									errLine (tk->lineNumber) ;
									printf (" ") ;
									errArrow () ;
									#ifdef _WIN64
										printf (" %s\n", tk->lexeme) ;
									#endif
									#if defined __linux__ || defined __MACH__
										printf (ANSI_BOLD ANSI_RED " %s\n" ANSI_RESET, tk->lexeme) ;
									#endif
								}
								break;
							}

							if(tk->id == TK_EOF)
								goto labelabc;
							
						}
					}
			}
		}
 
		while_count++ ;
	}

 	labelabc:
 	lexer_destroy (twinBuf) ;

	return root ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
callq 0xe020
callq 0xf2c0
movl $0x1, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x9fd0
movq %rax, -0x18(%rbp)
callq 0xf940
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0xf980
movq %rax, -0x28(%rbp)
callq 0xf6c0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0xa680
movq %rax, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
cmpl $0x6e, (%rax)
jne 0xfd9e
movq -0x30(%rbp), %rax
movl $0x1, 0x24(%rax)
movb $0x0, %al
callq 0x14cd0
leaq 0x79bd(%rip), %rdi      # 0x1771d
movb $0x0, %al
callq 0x1090
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x14ca0
leaq 0x7bca(%rip), %rdi      # 0x17944
movb $0x0, %al
callq 0x1090
movb $0x0, %al
callq 0x14d70
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x798f(%rip), %rdi      # 0x17726
movb $0x0, %al
callq 0x1090
cmpq $0x0, -0x28(%rbp)
je 0xfde1
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jge 0xfde1
movl $0x1, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movl $0x1, 0x24(%rax)
movb $0x0, %al
callq 0x14cf0
movb $0x0, %al
callq 0x14d70
leaq 0x7963(%rip), %rdi      # 0x17738
movb $0x0, %al
callq 0x1090
jmp 0x1025a
movq -0x20(%rbp), %rax
cmpl $0x70, (%rax)
jne 0xfe29
cmpq $0x0, -0x28(%rbp)
je 0xfdff
movq -0x28(%rbp), %rax
cmpl $0x70, (%rax)
jne 0xfdff
jmp 0x1025a
cmpq $0x0, -0x28(%rbp)
jne 0xfe27
movb $0x0, %al
callq 0x14cf0
movb $0x0, %al
callq 0x14d70
leaq 0x7943(%rip), %rdi      # 0x1775e
movb $0x0, %al
callq 0x1090
jmp 0x1025a
jmp 0xfe29
movq -0x28(%rbp), %rax
cmpl $0x36, (%rax)
jl 0x10000
movq -0x28(%rbp), %rax
cmpl $0x72, (%rax)
jg 0x10000
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jne 0xfea9
movq -0x28(%rbp), %rdi
callq 0xf9e0
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0xfe97
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x38(%rbp), %rdi
callq 0xfc40
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0xa680
movq %rax, -0x20(%rbp)
jmp 0xfffb
movq -0x30(%rbp), %rax
movl $0x1, 0x24(%rax)
movl -0x40(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
je 0xffaf
movq -0x28(%rbp), %rax
cmpl $0x67, (%rax)
je 0xff44
movq -0x28(%rbp), %rax
cmpl $0x62, (%rax)
je 0xff44
movq -0x28(%rbp), %rax
cmpl $0x64, (%rax)
je 0xff44
movb $0x0, %al
callq 0x14cf0
leaq 0x7830(%rip), %rdi      # 0x1771d
movb $0x0, %al
callq 0x1090
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x14ca0
leaq 0x7a3d(%rip), %rdi      # 0x17944
movb $0x0, %al
callq 0x1090
movb $0x0, %al
callq 0x14d70
movq -0x28(%rbp), %rax
movslq (%rax), %rax
leaq 0xe0bd(%rip), %rsi      # 0x1dfe0
imulq $0x28, %rax, %rax
addq %rax, %rsi
leaq 0x784a(%rip), %rdi      # 0x1777b
movb $0x0, %al
callq 0x1090
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x40(%rbp)
jmp 0xffad
movb $0x0, %al
callq 0x14cf0
leaq 0x77cb(%rip), %rdi      # 0x1771d
movb $0x0, %al
callq 0x1090
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edi
subl $0x1, %edi
callq 0x14ca0
leaq 0x79d5(%rip), %rdi      # 0x17944
movb $0x0, %al
callq 0x1090
movb $0x0, %al
callq 0x14d70
movq -0x28(%rbp), %rax
movslq (%rax), %rax
leaq 0xe055(%rip), %rsi      # 0x1dfe0
imulq $0x28, %rax, %rax
addq %rax, %rsi
leaq 0x77e2(%rip), %rdi      # 0x1777b
movb $0x0, %al
callq 0x1090
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0xffaf
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xffdf
movb $0x0, %al
callq 0x14cf0
movb $0x0, %al
callq 0x14d70
leaq 0x778b(%rip), %rdi      # 0x1775e
movb $0x0, %al
callq 0x1090
jmp 0x1025a
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1030
movl $0x1, -0x3c(%rbp)
jmp 0x1024c
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jl 0x1024a
movq -0x28(%rbp), %rax
cmpl $0x35, (%rax)
jg 0x1024a
movq -0x28(%rbp), %rax
movslq (%rax), %rcx
leaq 0xf728(%rip), %rax      # 0x1f750
imulq $0x258, %rcx, %rcx      # imm = 0x258
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0xc(%rbp)
cmpl $-0x1, -0xc(%rbp)
je 0x100ca
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %edx
leaq 0x2569a(%rip), %rsi     # 0x356f0
callq 0xfa40
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x100c5
movl -0xc(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x38(%rbp), %rdi
movl -0xc(%rbp), %edx
leaq 0x25673(%rip), %rsi     # 0x356f0
callq 0xfb60
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x100c3
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
cmpl $0x36, (%rax)
jne 0x100c3
movq -0x20(%rbp), %rax
movl 0x10(%rax), %ecx
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x10(%rax)
movq -0x38(%rbp), %rdi
callq 0xfc40
movq %rax, -0x38(%rbp)
jmp 0x100c5
jmp 0x10248
movq -0x30(%rbp), %rax
movl $0x1, 0x24(%rax)
movl -0x40(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
je 0x1011a
movb $0x0, %al
callq 0x14cf0
leaq 0x762e(%rip), %rdi      # 0x1771d
movb $0x0, %al
callq 0x1090
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x14ca0
leaq 0x5cf8(%rip), %rdi      # 0x15e01
movb $0x0, %al
callq 0x1090
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x40(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x10142
movb $0x0, %al
callq 0x14cf0
movb $0x0, %al
callq 0x14d70
leaq 0x7628(%rip), %rdi      # 0x1775e
movb $0x0, %al
callq 0x1090
jmp 0x1025a
movl $0x1, -0x3c(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x28(%rbp), %rax
movslq (%rax), %rcx
leaq 0x26211(%rip), %rax     # 0x36370
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x50(%rbp)
movb %al, -0x51(%rbp)
je 0x10185
movq -0x50(%rbp), %rax
movl (%rax), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
setne %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x1018e
jmp 0x1019c
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x10167
cmpq $0x0, -0x28(%rbp)
je 0x101bc
cmpq $0x0, -0x50(%rbp)
je 0x101bc
movq -0x28(%rbp), %rdi
callq 0xf9e0
movq %rax, -0x28(%rbp)
jmp 0x10246
movq -0x20(%rbp), %rax
cmpl $0x70, (%rax)
je 0x10234
movq -0x18(%rbp), %rdi
callq 0xa680
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x6e, (%rax)
jne 0x10232
movq -0x30(%rbp), %rax
movl $0x1, 0x24(%rax)
movb $0x0, %al
callq 0x14cd0
leaq 0x7529(%rip), %rdi      # 0x1771d
movb $0x0, %al
callq 0x1090
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x14ca0
leaq 0x7736(%rip), %rdi      # 0x17944
movb $0x0, %al
callq 0x1090
movb $0x0, %al
callq 0x14d70
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x74fb(%rip), %rdi      # 0x17726
movb $0x0, %al
callq 0x1090
jmp 0x10246
movq -0x20(%rbp), %rax
cmpl $0x70, (%rax)
jne 0x1023f
jmp 0x1025c
jmp 0x10241
jmp 0x10149
jmp 0x10248
jmp 0x1024a
jmp 0x1024c
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xfd3e
jmp 0x1025c
movq -0x18(%rbp), %rdi
callq 0xa0f0
movq -0x30(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nop