// File: /workspace/github_cpp_makefile_star2_O3/AshOlogn[P]ash-language-interpreter/src/parser.cpp
// Function: parseFunction(unsigned int, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Function* parseFunction(uint32_t startLine, uint32_t secondStartLine, string functionName) {

	//now create a Function struct
	Function* function = (Function*) malloc(sizeof(Function));
	function->returnFlag = (bool*) malloc(sizeof(bool));
	function->returnValue = (ParseData*) malloc(sizeof(ParseData));

	//assign the global returnFlag and returnValue pointers to this function
	returnFlag.push_back(function->returnFlag);
	returnValue.push_back(function->returnValue);

	//now read in arguments enclosed in parentheses
	Token* leftParenToken = consume(); //consume (

	//if the next token is not a parenthesis, throw an error
	if(leftParenToken->type != LEFT_PAREN) {

		uint32_t endLine = (leftParenToken->type == END) ? secondStartLine : leftParenToken->line+1;

		if(leftParenToken->type == END) {
			throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), "Expected '(' to begin function parameter list"); 
		} else {
			throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), leftParenToken->lexeme, "Expected '(' to begin function parameter list");
		}
	}

	//first scan to figure out how many arguments must be allocated in Function
	uint32_t currentIndex = 0;
	uint32_t argCount = 0;

	uint32_t currentErrorLine = leftParenToken->line+1;
	while(peekAhead(currentIndex)->type != RIGHT_PAREN) {

		//make sure you have a type then variable
		if(!isTypeTokenType(peekAhead(currentIndex)->type)) {

			Token* tempTypeToken = peekAhead(currentIndex);	
			uint32_t endLine = (tempTypeToken->type == END) ? currentErrorLine : tempTypeToken->line+1;

			if(tempTypeToken->type == END) {
				throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), "Expected function parameter type");
			} else {
				throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), tempTypeToken->lexeme, "Expected function parameter type");
			}
		}
		currentErrorLine = peekAhead(currentIndex)->line+1;
		currentIndex++;

		//could be an array type
		if(peekAhead(currentIndex)->type == LEFT_BRACKET) {

			currentErrorLine = peekAhead(currentIndex)->line+1;
			currentIndex++;

			//next token must be ']'
			if(peekAhead(currentIndex)->type != RIGHT_BRACKET) {

				uint32_t endLine = (peekAhead(currentIndex)->type == END) ? currentErrorLine : peekAhead(currentIndex)->line+1;

				if(peekAhead(currentIndex)->type == END) {
					throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), "Expected closing ']' in array type");		
				} else {
					throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), peekAhead(currentIndex)->lexeme, "Expected closing ']' in array type");						
				}
			}

			currentErrorLine = peekAhead(currentIndex)->line+1;
			currentIndex++;
		}

		//make sure parameter name follows type
		if(peekAhead(currentIndex)->type != VARIABLE) {

			Token* tempVariableToken = peekAhead(currentIndex);
			uint32_t endLine = (tempVariableToken->type == END) ? currentErrorLine : tempVariableToken->line+1;

			if(tempVariableToken->type == END) {
				throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), "Expected function parameter name");
			} else {
				throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), tempVariableToken->lexeme, "Expected function parameter name");
			}
		}
		currentErrorLine = peekAhead(currentIndex)->line+1;
		currentIndex++;
		argCount++;

		//if next token is not closing parenthesis, it must be a comma
		Token* nextToken = peekAhead(currentIndex);				
		if(nextToken->type != RIGHT_PAREN && nextToken->type != COMMA) {

			uint32_t endLine = (nextToken->type == END) ? currentErrorLine : nextToken->line+1;

			if(nextToken->type == END) {
				throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), "Expected ',' separating arguments or ')' terminating argument list");
			} else {
				throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), nextToken->lexeme, "Expected ',' separating arguments or ')' terminating argument list"); 
			} 

		} else if(nextToken->type == COMMA) {
			currentErrorLine = nextToken->line+1;
			currentIndex++; //"consume" COMMA token
		}
	}

	//now allocate memory for argument names and types
	function->numArgs = argCount;
	ParseDataType* argTypes = new ParseDataType[argCount];
	ParseDataType* argSubTypes = new ParseDataType[argCount];
	char** argNames = (char**) malloc(sizeof(char*) * argCount);

	//keep track of variable line numbers
	uint32_t typeLines[argCount];
	uint32_t varLines[argCount];

	//now read in arguments for real
	uint32_t argIndex = 0;
	while(peek()->type != RIGHT_PAREN) {

		//read in parameter type
		Token* currTypeToken = consume();

		//could be an array type
		if(peek()->type == LEFT_BRACKET) {

			argTypes[argIndex] = ARRAY_T;
			argSubTypes[argIndex] = typeTokenConversion(currTypeToken->type);

			consume(); //consume '['
			typeLines[argIndex] = consume()->line+1;

		} else {

			argTypes[argIndex] = typeTokenConversion(currTypeToken->type);
			argSubTypes[argIndex] = INVALID_T;
			typeLines[argIndex] = currTypeToken->line+1;
		}

		//read in parameter name
		Token* currVarToken = consume();
		const char* aName = currVarToken->lexeme;
		argNames[argIndex] = copyString(aName);
		varLines[argIndex] = currVarToken->line+1;

		argIndex++;
		if(argIndex < argCount)
			consume(); //consume ,
	}
	leftParenToken = consume(); //consume ')' token

	function->argTypes = argTypes;
	function->argSubTypes = argSubTypes;
	function->argNames = argNames;

	//now get the return type
	Token* rightArrowToken = consume(); //consume ->
	if(rightArrowToken->type != RIGHTARROW) {
		
		uint32_t endLine = (rightArrowToken->line == END) ? leftParenToken->line+1 : rightArrowToken->line+1;

		if(rightArrowToken->line == END) {
			throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), "Expected -> followed by return type");
		} else {
			throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), rightArrowToken->lexeme, "Expected -> followed by return type");
		}
	}

	//make sure following token is a return type
	Token* returnTypeToken = consume();
	if(!isTypeTokenType(returnTypeToken->type)) {

		uint32_t endLine = (returnTypeToken->type == END) ? rightArrowToken->line+1 : returnTypeToken->line+1;

		if(returnTypeToken->type == END) {
			throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), "Expected function return type"); 
		} else {
			throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), returnTypeToken->lexeme, "Expected function return type"); 
		}
	}

	returnType.push_back(typeTokenConversion(returnTypeToken->type));
	function->returnType = typeTokenConversion(returnTypeToken->type);

	//just declare function up front with dummy data and Function public interface data
	//(to allow for recursive definitions)
	ParseData dummyFunctionData;
	dummyFunctionData.type = FUN_T;
	dummyFunctionData.value.allocated = function;
	symbolTable->declare(functionName, dummyFunctionData);

	//now declare the variables just for scope-checking purposes
	//and enter a new scope (in both tables) for function body
	symbolTable->enterNewScope();
	NewAssignmentStatementNode* dummy;

	for(uint32_t i = 0; i < argCount; i++) {
		//this construction declares variable as well
		string argName(argNames[i]);
		dummy = new NewAssignmentStatementNode(argName, argTypes[i], symbolTable, typeLines[i], varLines[i]);
	}

	//now store AbstractStatementNode* vector representing function body
	//make sure the body is braced
	Token* leftBraceToken = consume(); //consume {
	if(leftBraceToken->type != LEFT_BRACE) {

		uint32_t endLine = (leftBraceToken->type == END) ? returnTypeToken->line+1 : leftBraceToken->line+1;

		if(leftBraceToken->type == END) {
			throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), "Expected '{' followed by function body");
		} else {
			throw ParseSyntaxError(startLine, endLine, getCodeLineBlock(startLine-1, endLine-1), leftBraceToken->lexeme, "Expected '{' followed by function body");
		}
	}

	//represents statements in body
	vector<AbstractStatementNode*>* body = new vector<AbstractStatementNode*>();

	while(peek()->type != RIGHT_BRACE) {
		body->push_back(addStatement());  
	}
	consume(); //consume }

	//leave scope
	symbolTable->leaveScope();
	function->body = body;

	//reset global pointers
	returnFlag.pop_back();
	returnValue.pop_back();
	returnType.pop_back();

	return function;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, -0x90(%rbp)
movl %esi, %ebx
movq %rdi, -0x30(%rbp)
movl $0x40, %edi
callq 0x4290
movq %rax, %r15
movl $0x1, %edi
callq 0x4290
movq %rax, %r14
movq %rax, 0x38(%r15)
movl $0x10, %edi
callq 0x4290
movq %rax, 0x30(%r15)
movq 0x14882(%rip), %rsi     # 0x2c238
cmpq 0x14883(%rip), %rsi     # 0x2c240
movq %r15, -0x48(%rbp)
je 0x179d0
movq %r14, (%rsi)
addq $0x8, 0x1486a(%rip)     # 0x2c238
jmp 0x179e4
leaq 0x38(%r15), %rdx
leaq 0x14855(%rip), %rdi     # 0x2c230
callq 0x1d672
movq -0x48(%rbp), %r15
leaq 0x30(%r15), %rdx
movq 0x14861(%rip), %rsi     # 0x2c250
cmpq 0x14862(%rip), %rsi     # 0x2c258
je 0x17a08
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x1484a(%rip)     # 0x2c250
jmp 0x17a14
leaq 0x14839(%rip), %rdi     # 0x2c248
callq 0x1d7ac
callq 0x177cc
movq %rax, %r12
movl (%rax), %eax
testl %eax, %eax
jne 0x18181
movl 0x10(%r12), %r14d
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x17855
cmpl $0x1, (%rax)
jne 0x17bcc
movq -0x48(%rbp), %rax
movl %r15d, (%rax)
movl %r15d, %r14d
leaq (,%r14,4), %rbx
movq %rbx, %rdi
callq 0x4030
movq %rax, -0x50(%rbp)
movq %rbx, %rdi
callq 0x4030
movq %rax, %rbx
leaq (,%r14,8), %rdi
callq 0x4290
movq %rax, -0x38(%rbp)
movq %rsp, %rcx
movq %r14, -0x58(%rbp)
leaq 0xf(,%r14,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x60(%rbp)
movq %rcx, %rsp
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
callq 0x1781b
cmpl $0x1, (%rax)
je 0x17b53
xorl %r15d, %r15d
callq 0x177cc
movq %rax, %r14
callq 0x1781b
cmpl $0x2, (%rax)
jne 0x17aeb
movl %r15d, %r13d
movq -0x50(%rbp), %rax
movl $0xc, (%rax,%r13,4)
movl (%r14), %edi
callq 0x812a
movl %eax, (%rbx,%r13,4)
callq 0x177cc
callq 0x177cc
movq %rax, %r14
jmp 0x17b06
movl (%r14), %edi
callq 0x812a
movl %r15d, %r13d
movq -0x50(%rbp), %rcx
movl %eax, (%rcx,%r13,4)
movl $0x11, (%rbx,%r13,4)
movl 0x10(%r14), %eax
incl %eax
movq -0x60(%rbp), %rcx
movl %eax, (%rcx,%r13,4)
callq 0x177cc
movq %rax, %r14
movq 0x18(%rax), %rdi
callq 0x175e8
movq -0x38(%rbp), %rcx
movq %rax, (%rcx,%r13,8)
movl 0x10(%r14), %eax
incl %eax
movl %eax, (%r12,%r13,4)
incl %r15d
cmpl -0x58(%rbp), %r15d
jae 0x17b45
callq 0x177cc
callq 0x1781b
cmpl $0x1, (%rax)
jne 0x17aaf
callq 0x177cc
movq %rax, %r14
movq -0x48(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq -0x38(%rbp), %rcx
movq %rcx, 0x18(%rax)
callq 0x177cc
movq %rax, %rbx
cmpl $0x2d, (%rax)
jne 0x18278
callq 0x177cc
movq %rax, %r14
movl (%rax), %edi
callq 0x633a
testb %al, %al
je 0x182cd
movl (%r14), %edi
callq 0x812a
movl %eax, -0x80(%rbp)
movq 0x146bb(%rip), %rsi     # 0x2c268
cmpq 0x146bc(%rip), %rsi     # 0x2c270
je 0x17d1a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x146a1(%rip)     # 0x2c268
jmp 0x17d2a
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x17855
movl (%rax), %edi
callq 0x633a
testb %al, %al
je 0x18370
xorl %ebx, %ebx
movl $0x1, %r15d
movl %ebx, %edi
callq 0x17855
movl 0x10(%rax), %r14d
leal 0x1(%rbx), %r12d
movl %r12d, %edi
callq 0x17855
cmpl $0x2, (%rax)
jne 0x17c3f
movl %r12d, %edi
callq 0x17855
movl 0x10(%rax), %r13d
leal 0x2(%rbx), %r12d
movl %r12d, %edi
callq 0x17855
movl (%rax), %r14d
movl %r12d, %edi
callq 0x17855
cmpl $0x3, %r14d
jne 0x17fbc
movl 0x10(%rax), %r14d
addl $0x3, %ebx
movl %ebx, %r12d
movl %r12d, %edi
callq 0x17855
movl (%rax), %r13d
movl %r12d, %edi
callq 0x17855
movq %rax, %rbx
cmpl $0x3b, %r13d
jne 0x17f5e
movl 0x10(%rbx), %r13d
leal 0x1(%r13), %eax
movq %rax, -0x38(%rbp)
leal 0x1(%r12), %ebx
movl %ebx, %edi
callq 0x17855
movq %rax, %r14
movl (%rax), %eax
cmpl $0x1, %eax
je 0x17c9b
cmpl $0x2b, %eax
jne 0x17eff
movl 0x10(%r14), %eax
incl %eax
movq %rax, -0x38(%rbp)
addl $0x2, %r12d
movl %r12d, %ebx
movl %ebx, %edi
callq 0x17855
cmpl $0x1, (%rax)
je 0x17a3e
movl %ebx, %edi
callq 0x17855
movl (%rax), %edi
callq 0x633a
incl %r15d
testb %al, %al
jne 0x17bec
movl %ebx, %edi
callq 0x17855
cmpl $0x4e, (%rax)
jne 0x1801f
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movq -0x38(%rbp), %rax
leal -0x1(%rax), %esi
callq 0x17891
leaq 0x138d5(%rip), %rcx     # 0x2b5d0
addq $0x10, %rcx
movq %rcx, (%r14)
movq %rax, 0x8(%r14)
movq $0x0, 0x10(%r14)
leaq 0xb34d(%rip), %rax      # 0x23062
jmp 0x17f45
leaq 0x1453f(%rip), %rdi     # 0x2c260
leaq -0x80(%rbp), %rdx
callq 0x1d8e6
movq %r14, -0x88(%rbp)
movl (%r14), %edi
callq 0x812a
movq -0x48(%rbp), %r13
movl %eax, 0x28(%r13)
movq 0x14548(%rip), %rbx     # 0x2c290
leaq -0xc0(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x90(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %r14
movq %r14, %rdi
callq 0x897a
movq %rbx, %rdi
movq %r14, %rsi
movl $0xd, %edx
movq %r13, %rcx
callq 0x164ea
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
je 0x17d97
callq 0x41e0
movq 0x144f2(%rip), %rdi     # 0x2c290
callq 0x16468
cmpq $0x0, -0x58(%rbp)
je 0x17e51
leaq -0xa0(%rbp), %rbx
xorl %r13d, %r13d
leaq -0xb0(%rbp), %r14
movq -0x38(%rbp), %rax
movq (%rax,%r13,8), %rsi
leaq -0x80(%rbp), %rdi
leaq -0x39(%rbp), %rdx
callq 0x40c0
movl $0x48, %edi
callq 0x4210
movq %rax, %r15
movq %rbx, -0xb0(%rbp)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x897a
movq -0x50(%rbp), %rax
movl (%rax,%r13,4), %edx
movq 0x14486(%rip), %rcx     # 0x2c290
movq -0x60(%rbp), %rax
movl (%rax,%r13,4), %r8d
movl (%r12,%r13,4), %r9d
movq %r15, %rdi
movq %r14, %rsi
callq 0x15ada
movq -0xb0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x17e32
callq 0x41e0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x17e44
callq 0x41e0
incq %r13
cmpq %r13, -0x58(%rbp)
jne 0x17dbf
callq 0x177cc
movq %rax, %rbx
movl (%rax), %eax
cmpl $0x4, %eax
jne 0x181d9
movl $0x18, %edi
callq 0x4210
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
callq 0x1781b
cmpl $0x5, (%rax)
je 0x17ebf
leaq -0x80(%rbp), %r14
callq 0x18475
movq %rax, -0x80(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x17eaa
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x17eb5
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1da1e
callq 0x1781b
cmpl $0x5, (%rax)
jne 0x17e8d
callq 0x177cc
movq 0x143c5(%rip), %rdi     # 0x2c290
callq 0x164d8
addq $-0x8, 0x14360(%rip)    # 0x2c238
movq -0x48(%rbp), %rax
movq %rbx, 0x20(%rax)
addq $-0x8, 0x14368(%rip)    # 0x2c250
addq $-0x4, 0x14378(%rip)    # 0x2c268
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4e, %eax
jne 0x18079
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %r13d, %esi
callq 0x17891
leaq 0x136a5(%rip), %rcx     # 0x2b5d0
addq $0x10, %rcx
movq %rcx, (%r14)
movq %rax, 0x8(%r14)
movq $0x0, 0x10(%r14)
leaq 0xb182(%rip), %rax      # 0x230c7
movq %rax, 0x18(%r14)
movq -0x30(%rbp), %rax
movl %eax, 0x20(%r14)
movq -0x38(%rbp), %rax
movl %eax, 0x24(%r14)
jmp 0x1816b
cmpl $0x4e, (%rbx)
jne 0x180e1
movl $0x28, %edi
callq 0x4110
movq %rax, %r15
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %r14d, %esi
callq 0x17891
incl %r14d
leaq 0x13643(%rip), %rcx     # 0x2b5d0
addq $0x10, %rcx
movq %rcx, (%r15)
movq %rax, 0x8(%r15)
movq $0x0, 0x10(%r15)
leaq 0xb0ff(%rip), %rax      # 0x230a6
movq %rax, 0x18(%r15)
movq -0x30(%rbp), %rax
movl %eax, 0x20(%r15)
movl %r14d, 0x24(%r15)
jmp 0x180cb
cmpl $0x4e, (%rax)
je 0x17fcd
movl %r12d, %edi
callq 0x17855
movl 0x10(%rax), %r13d
leal 0x1(%r13), %r15d
movl %r12d, %edi
callq 0x17855
movl (%rax), %ebx
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
cmpl $0x4e, %ebx
jne 0x18127
movl %r13d, %esi
callq 0x17891
leaq 0x135c9(%rip), %rcx     # 0x2b5d0
addq $0x10, %rcx
movq %rcx, (%r14)
movq %rax, 0x8(%r14)
movq $0x0, 0x10(%r14)
jmp 0x18154
movq %rax, %r12
movl 0x10(%rax), %ebx
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %ebx, %esi
callq 0x17891
incl %ebx
movq 0x18(%r12), %rcx
leaq 0x13582(%rip), %rdx     # 0x2b5d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movq %rcx, 0x10(%r14)
leaq 0xaffe(%rip), %rax      # 0x23062
movq %rax, 0x18(%r14)
movq -0x30(%rbp), %rax
movl %eax, 0x20(%r14)
movl %ebx, 0x24(%r14)
jmp 0x1816b
movl 0x10(%r14), %ebx
movl $0x28, %edi
callq 0x4110
movq %rax, %r15
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %ebx, %esi
callq 0x17891
incl %ebx
movq 0x18(%r14), %rcx
leaq 0x1352b(%rip), %rdx     # 0x2b5d0
addq $0x10, %rdx
movq %rdx, (%r15)
movq %rax, 0x8(%r15)
movq %rcx, 0x10(%r15)
leaq 0xb00c(%rip), %rax      # 0x230c7
movq %rax, 0x18(%r15)
movq -0x30(%rbp), %rax
movl %eax, 0x20(%r15)
movl %ebx, 0x24(%r15)
leaq 0x13526(%rip), %rsi     # 0x2b5f8
movq 0x13eff(%rip), %rdx     # 0x2bfd8
movq %r15, %rdi
callq 0x4350
movl 0x10(%rbx), %r15d
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %r15d, %esi
callq 0x17891
incl %r15d
movq 0x18(%rbx), %rcx
leaq 0x134c1(%rip), %rdx     # 0x2b5d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movq %rcx, 0x10(%r14)
leaq 0xaf81(%rip), %rax      # 0x230a6
jmp 0x1815b
movl %r13d, %esi
callq 0x17891
movq %rax, %rbx
movl %r12d, %edi
callq 0x17855
movq 0x18(%rax), %rax
leaq 0x1348b(%rip), %rcx     # 0x2b5d0
addq $0x10, %rcx
movq %rcx, (%r14)
movq %rbx, 0x8(%r14)
movq %rax, 0x10(%r14)
leaq 0xaf28(%rip), %rax      # 0x23083
movq %rax, 0x18(%r14)
movq -0x30(%rbp), %rax
movl %eax, 0x20(%r14)
movl %r15d, 0x24(%r14)
leaq 0x13486(%rip), %rsi     # 0x2b5f8
movq 0x13e5f(%rip), %rdx     # 0x2bfd8
movq %r14, %rdi
callq 0x4350
cmpl $0x4e, %eax
jne 0x1822f
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
leal -0x1(%rbx), %esi
callq 0x17891
leaq 0x13423(%rip), %rcx     # 0x2b5d0
addq $0x10, %rcx
movq %rcx, (%r14)
movq %rax, 0x8(%r14)
movq $0x0, 0x10(%r14)
leaq 0xae6d(%rip), %rax      # 0x23034
movq %rax, 0x18(%r14)
movq -0x30(%rbp), %rax
movl %eax, 0x20(%r14)
movl %ebx, 0x24(%r14)
jmp 0x1816b
cmpl $0x4e, %eax
jne 0x18327
movq -0x88(%rbp), %rax
movl 0x10(%rax), %ebx
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %ebx, %esi
callq 0x17891
incl %ebx
leaq 0x133c0(%rip), %rcx     # 0x2b5d0
addq $0x10, %rcx
movq %rcx, (%r14)
movq %rax, 0x8(%r14)
movq $0x0, 0x10(%r14)
leaq 0xaf22(%rip), %rax      # 0x2314c
jmp 0x18064
movl 0x10(%r12), %ebx
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %ebx, %esi
callq 0x17891
incl %ebx
movq 0x18(%r12), %rcx
leaq 0x13373(%rip), %rdx     # 0x2b5d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movq %rcx, 0x10(%r14)
leaq 0xadc1(%rip), %rax      # 0x23034
jmp 0x18064
movl 0x10(%rbx), %r15d
cmpl $0x4e, %r15d
jne 0x1837c
movl 0x10(%r14), %ebx
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %ebx, %esi
callq 0x17891
incl %ebx
leaq 0x13322(%rip), %rcx     # 0x2b5d0
addq $0x10, %rcx
movq %rcx, (%r14)
movq %rax, 0x8(%r14)
movq $0x0, 0x10(%r14)
leaq 0xae42(%rip), %rax      # 0x2310a
jmp 0x18064
movl (%r14), %r12d
cmpl $0x4e, %r12d
movq %r14, %r13
cmoveq %rbx, %r14
movl 0x10(%r14), %ebx
leal 0x1(%rbx), %r15d
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
cmpl $0x4e, %r12d
jne 0x183c1
movl %ebx, %esi
callq 0x17891
leaq 0x132c1(%rip), %rcx     # 0x2b5d0
addq $0x10, %rcx
movq %rcx, (%r14)
movq %rax, 0x8(%r14)
movq $0x0, 0x10(%r14)
jmp 0x183e2
movl 0x10(%rbx), %r15d
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %r15d, %esi
callq 0x17891
incl %r15d
movq 0x18(%rbx), %rcx
leaq 0x1327b(%rip), %rdx     # 0x2b5d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movq %rcx, 0x10(%r14)
leaq 0xade1(%rip), %rax      # 0x2314c
jmp 0x1815b
incl %r14d
movq %r14, -0x38(%rbp)
jmp 0x17cc4
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
leal -0x1(%rax), %edi
movl %r15d, %esi
callq 0x17891
incl %r15d
movq 0x18(%rbx), %rcx
leaq 0x1322a(%rip), %rdx     # 0x2b5d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movq %rcx, 0x10(%r14)
leaq 0xad4e(%rip), %rax      # 0x2310a
jmp 0x1815b
movl %ebx, %esi
callq 0x17891
movq 0x18(%r13), %rcx
leaq 0x131fd(%rip), %rdx     # 0x2b5d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movq %rcx, 0x10(%r14)
leaq 0xad45(%rip), %rax      # 0x2312e
jmp 0x1815b
jmp 0x18423
jmp 0x18423
jmp 0x18423
jmp 0x18423
jmp 0x18423
jmp 0x18423
jmp 0x18423
jmp 0x18423
movq %rax, %r12
movq -0xd0(%rbp), %rdi
cmpq %r15, %rdi
jne 0x18468
jmp 0x1846d
jmp 0x18423
jmp 0x18423
jmp 0x18423
jmp 0x18417
movq %rax, %r12
movq %r15, %rdi
jmp 0x18429
jmp 0x18423
jmp 0x18423
movq %rax, %r12
movq %r14, %rdi
callq 0x4190
jmp 0x1846d
movq %rax, %r12
jmp 0x1846d
movq %rax, %r12
jmp 0x1845b
movq %rax, %r12
jmp 0x18453
movq %rax, %r12
movq -0xb0(%rbp), %rdi
cmpq %rbx, %rdi
je 0x18453
callq 0x41e0
movq %r15, %rdi
callq 0x41e0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x1846d
callq 0x41e0
movq %r12, %rdi
callq 0x4380