// File: /workspace/github_c_makefile_star2_O2/anuwu[P]ERPLAG-Compiler/codegen.c
// Function: moduleGeneration
void moduleGeneration (astNode *node, moduleST *lst)
{
	if (node == NULL)
		return ;

	varST *searchedVar ;
	astNode *idListHead ;
	moduleST *calledModule ;
	varSTentry *varEntry ;

	switch (node->id)
	{
		int start_label, end_label ;
		int reserveLabel[10] ;

		case statements :
			if (node->child == NULL && node->localST->parent == realBase)
				retModule (node->localST) ;
			else
				moduleGeneration (node->child, node->localST);		// Access local scope and move below

			break ;

		case statement :
		{
			moduleGeneration(node->child, lst);
			if (node->next == NULL)
			{
				if (lst->tableType == SWITCH_ST)
					break ;

				varEntry = lst->dynamicVars[0] ;
				freeDynamic (varEntry) ;

				if (lst->parent == realBase)
					retModule (lst) ;
				else if (lst->scopeSize > 0)
				{
					codePrint ("\n\t\tADD RSP, %d", lst->scopeSize) ;
					codeComment (10, "restoring to parent scope") ;
				}

			}
			else
				moduleGeneration(node->next, lst);

			break ;
		}

		case TK_DECLARE :
		{
			;
			switchDeclareStatus stat ;
			if (lst->tableType != SWITCH_ST)
				stat = NOT_SWITCH ; // Subtract RSP, and allocate memory if dynamic
			else if (node->parent != node)
				stat = SWITCH_INIT ; // Subtract RSP only, and do not allocate memory for dynamic
			else
			{
				stat = SWITCH_GEN ; // Do not subtract RSP, allocate memory if dynamic AND restore parent
				node->parent = node->next->parent ;
			}

			int declCount = 1 ;
			idListHead = node->next->child ;
			astNode *dtNode = node->next->next ;

			while (idListHead->next != NULL)
			{
				declCount++ ;
				idListHead = idListHead->next ;
			}

			searchedVar = searchVar (lst, idListHead->tok->lexeme) ;
			if (searchedVar->size > 0 && stat != SWITCH_GEN)
			{	
				codePrint ("\t\tSUB RSP, %d", searchedVar->size * declCount) ;
				if (stat == NOT_SWITCH)
					codeComment (11, "making space for declaration") ;
				else if (stat == SWITCH_INIT)
					codeComment (11, "declaring before switch") ;

				codePrint ("\n") ;
			}

			if (dtNode->dtTag == ARRAY && !isVarStaticArr(searchedVar) && stat != SWITCH_GEN)
				dynamicDeclaration (lst, searchedVar, declCount) ;

			break ;	
		}									

		case TK_ASSIGNOP :
		{
			if (isSingleRHS(node))
			{
				if (isArrayRHS (node, lst))
				{
					//printf ("CANNOT HANDLE ARRAY ASSIGNMENT YET\n") ;
					varST *lhs, *rhs ;
					lhs = searchVar (lst, node->child->tok->lexeme) ;
					rhs = searchVar (lst, node->child->next->tok->lexeme) ;
				
					if (isVarStaticArr (lhs) && isVarStaticArr (rhs))
					{
						tf |= 1 << asgnArr ;

						loadRegLeftLim (lhs, "CX") ;
						loadRegRightLim (lhs, "DX") ;
						loadArrBase (lhs, "RDI") ;
						loadArrBase (rhs, "RSI") ;
						codePrint ("\t\tSUB DX, CX\n") ;
						codePrint ("\t\tADD DX, 1\n") ;
						codePrint ("\t\tADD DX, DX\n") ;
						codePrint ("\t\tCALL @asgnArr\n") ;
					}
					else
						dynAsgnArr (lhs, rhs) ;
				}
				else
				{
					expr(node->child->next, lst, 1);
					exprAssign (node->child, lst, 1) ;
				}
			}
			else
			{
				int singleAssign = 0 ;

				if (isAssignUnary (node))
				{
					if (isExprLeaf (node->child->next->child->id))
						singleAssign = 1 ;

					expr(node->child->next->child, lst, singleAssign) ;
				}
				else
					expr(node->child->next, lst, 0);	

				exprAssign (node->child, lst, singleAssign) ;
			}

			codePrint ("\n") ;
			break ;
		}

		case TK_FOR :
		{
			node=node->next;
			start_label = get_label (LABEL_FOR) ;
			end_label = get_label (LABEL_FOR) ;

			searchedVar = searchVar (lst, node->tok->lexeme) ;

			codePrint ("\t\tMOV CX,%s\n", node->next->tok->lexeme);
			codePrint ("\t\tMOV [RBP%s], CX" , getOffsetStr(searchedVar->offset)) ;

			codePrint ("\n\t@FOR%d:\n", start_label) ;
			codePrint ("\t\tMOV AX, %s\n", node->next->next->tok->lexeme) ;
			codePrint ("\t\tCMP CX, AX\n");
			codePrint ("\t\tJG @FOR%d\n\n", end_label);

			moduleGeneration(node->next->next->next, lst);		// Statements

			codePrint ("\n\t\tMOV CX, [RBP%s]", getOffsetStr(searchedVar->offset)) ;
			codeComment (8, "For loop increment") ;
			codePrint ("\t\tINC CX\n");
			codePrint ("\t\tMOV [RBP%s],CX\n", getOffsetStr(searchedVar->offset)) ;
			codePrint ("\t\tJMP @FOR%d\n", start_label) ;
			codePrint ("\n\t@FOR%d:\n", end_label) ;
			break ;
		}

		
		case TK_WHILE :
		{
			node=node->next;
			start_label = get_label(LABEL_WHILE);
			end_label =  get_label(LABEL_WHILE);

			codePrint ("\n\t@WHILE%d:\n", start_label) ;

			expr (node, lst, 0);	// expr

			codePrint ("\t\tPOP AX\n");
			codePrint ("\t\tCMP AX, 0");
			codeComment (11, "checking while loop condition") ;
			codePrint ("\t\tJE @WHILE%d\n\n", end_label) ;

			moduleGeneration(node->next, lst);		// statements

			codePrint ("\t\tJMP @WHILE%d\n", start_label) ;
			codePrint ("\n\t@WHILE%d:\n", end_label) ;

			break ;
		}
		
		case TK_PRINT :
			node = node->next ;
			print (node, lst) ;
			break ;

		case TK_GET_VALUE :
			searchedVar = searchVar (lst, node->next->tok->lexeme) ;
			getValue (lst, searchedVar) ;
			break ;

		case TK_SWITCH :
		{
			int i, caseCount, def_label ;
			int *caseLabels ;
			astNode *statementsNode = node->next->next->next->next ;

			switchDeclareVars (node->next->next->next->next) ;
			caseCount = getCaseCount (node->next->next->next->next) ;
			caseLabels = (int *) malloc (sizeof(int) * caseCount) ;
			def_label = switchCaseLabels (node , lst, caseCount, caseLabels) ;

			end_label = get_label (LABEL_SWITCH) ;
			i = 0 ;
			while (statementsNode != NULL)
			{
				codePrint ("\n@SWITCH%d:\n", caseLabels[i]) ;
				moduleGeneration (statementsNode, lst) ;
				codePrint ("\n\t\tJMP @SWITCH%d\n", end_label) ;

				i++ ;
				if (statementsNode->next != NULL)
				{
					if (statementsNode->next->id == TK_DEFAULT)
					{
						statementsNode = statementsNode->next->next ;
						codePrint ("\n@SWITCH%d:\n", def_label) ;
						moduleGeneration (statementsNode, lst) ;
						codePrint ("\n\t\tJMP @SWITCH%d\n", end_label) ;

						break ;
					}
					statementsNode = statementsNode->next->next->next ;
				}
				else
					statementsNode = NULL ;
			}

			statementsNode = node->next->next->next->next ;
			codePrint ("\n@SWITCH%d:\n", end_label) ;

			varEntry = statementsNode->localST->dynamicVars[0] ;
			freeDynamic (varEntry) ;

			if (statementsNode->localST->scopeSize > 0)
			{
				codePrint ("\t\tADD RSP, %d", statementsNode->localST->scopeSize) ;
				codeComment (11, "restoring to parent scope") ;
			}

			break ;
		}

		case TK_ID :
		{
			calledModule = searchModuleInbaseST (node->tok->lexeme) ;
			varEntry = calledModule->inputVars[0] ;

			idListHead = node->next->child ; 
			while (idListHead->next != NULL)
				idListHead = idListHead->next ;

			pushInput (idListHead, varEntry, lst) ;

			codePrint ("\t\tCALL %s", strcmp(node->tok->lexeme, "main") ? node->tok->lexeme : "@main") ;
			codeComment (11, "calling user function") ;
			codePrint ("\t\tADD RSP, %d\n", calledModule->inputSize) ;
			break ;
		}

		case idList :
		{
			calledModule = searchModuleInbaseST (node->next->next->tok->lexeme) ;
			varEntry = calledModule->inputVars[0] ;

			idListHead = node->next->next->next->child ;
			while (idListHead->next != NULL)
				idListHead = idListHead->next ;

			codePrint ("\t\tSUB RSP, %d\n", calledModule->outputSize) ;
			pushInput (idListHead, varEntry, lst) ;

			codePrint ("\t\tCALL %s", node->next->next->tok->lexeme) ;
			codeComment (11, "calling user function") ;
			codePrint ("\t\tADD RSP, %d\n", calledModule->inputSize) ;

			popOutput (node->child, lst) ;
			break ;
		}
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x2d41b(%rip), %r15     # 0x30018
testq %r14, %r14
je 0x34c9
movl (%r14), %eax
cmpl $0xd, %eax
jne 0x2c28
movq 0x30(%r14), %rdi
movq %rbx, %rsi
callq 0x2bdf
movq 0x38(%r14), %r14
testq %r14, %r14
jne 0x2bfd
jmp 0x2e62
leal -0x3e(%rax), %ecx
cmpl $0x6, %ecx
jbe 0x2c81
cmpl $0x69, %eax
je 0x304a
cmpl $0x34, %eax
je 0x3185
cmpl $0x50, %eax
je 0x2eb9
cmpl $0x52, %eax
je 0x332d
cmpl $0x56, %eax
je 0x3258
cmpl $0xc, %eax
jne 0x34c9
movq 0x20(%r14), %rbx
movq 0x30(%r14), %r14
testq %r14, %r14
jne 0x2bfd
movq 0x10(%rbx), %rax
cmpq (%r15), %rax
jne 0x2bfd
jmp 0x34d8
leaq 0xb558(%rip), %rax      # 0xe1e0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rbx, %r13
movl 0x8(%rbx), %ebx
movb $0x1, %r12b
cmpl $0x4, %ebx
jne 0x2cb4
cmpq %r14, 0x28(%r14)
jne 0x2cb4
movq 0x38(%r14), %rax
movq 0x28(%rax), %rax
movq %rax, 0x28(%r14)
xorl %r12d, %r12d
movq 0x38(%r14), %rcx
movq 0x30(%rcx), %rax
movq 0x38(%rcx), %rcx
movq %rcx, -0x38(%rbp)
xorl %r14d, %r14d
movq %rax, %rcx
movq 0x38(%rax), %rax
incl %r14d
testq %rax, %rax
jne 0x2cc7
movq 0x8(%rcx), %rax
movq 0x8(%rax), %rsi
movq %r13, %rdi
callq 0xac19
movq %rax, %r15
movl 0x18(%rax), %edx
testl %edx, %edx
setle %al
xorb $0x1, %r12b
orb %r12b, %al
jne 0x2d45
leaq 0x13637(%rip), %rax     # 0x16338
movq (%rax), %rdi
imull %r14d, %edx
leaq 0xbd93(%rip), %rsi      # 0xeaa2
xorl %eax, %eax
callq 0x10f0
cmpl $0x4, %ebx
leaq 0xbdad(%rip), %rax      # 0xeacd
leaq 0xbd89(%rip), %rsi      # 0xeab0
cmoveq %rax, %rsi
pushq $0xb
popq %rdi
callq 0x151a
leaq 0x135fe(%rip), %rax     # 0x16338
movq (%rax), %rsi
pushq $0xa
popq %rdi
callq 0x10d0
movq -0x38(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jne 0x34c9
movq %r15, %rdi
callq 0xcd66
testl %eax, %eax
setne %al
orb %al, %r12b
jne 0x34c9
movq %r13, %rdi
movq %r15, %rsi
movl %r14d, %edx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2764
movq 0x38(%r14), %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x206b
movq 0x38(%r14), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xac19
movq %rax, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x245a
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
callq 0xab11
movq %rax, %r15
movq 0x88(%rax), %rsi
movq 0x38(%r14), %rax
movq 0x30(%rax), %rax
movq %rax, %rdi
movq 0x38(%rax), %rax
testq %rax, %rax
jne 0x2de8
movq %rbx, %rdx
callq 0x3891
leaq 0x13535(%rip), %r12     # 0x16338
movq (%r12), %rbx
movq 0x8(%r14), %rax
movq 0x8(%rax), %r14
leaq 0xbdfb(%rip), %rsi      # 0xec11
movq %r14, %rdi
callq 0x10e0
testl %eax, %eax
leaq 0xbde9(%rip), %rdx      # 0xec10
cmovneq %r14, %rdx
leaq 0xbdd4(%rip), %rsi      # 0xec06
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10f0
leaq 0xbdd3(%rip), %rsi      # 0xec16
pushq $0xb
popq %rdi
callq 0x151a
movq (%r12), %rdi
movl 0x104(%r15), %edx
leaq 0xb97a(%rip), %rsi      # 0xe7d7
jmp 0x3318
cmpl $0x4, 0x8(%rbx)
je 0x34c9
movq 0x80(%rbx), %rdi
callq 0x3ae7
movq 0x10(%rbx), %rax
cmpq (%r15), %rax
je 0x34d8
movl 0x110(%rbx), %edx
testl %edx, %edx
jle 0x34c9
leaq 0x1349e(%rip), %rax     # 0x16338
movq (%rax), %rdi
leaq 0xbbd5(%rip), %rsi      # 0xea79
xorl %eax, %eax
callq 0x10f0
leaq 0xbbd6(%rip), %rsi      # 0xea88
pushq $0xa
jmp 0x34b5
movq 0x38(%r14), %r12
movl 0x13480(%rip), %r14d    # 0x16344
leal 0x1(%r14), %eax
movl %eax, -0x2c(%rbp)
addl $0x2, %r14d
movl %r14d, 0x1346e(%rip)    # 0x16344
movq 0x8(%r12), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xac19
movq %rax, %r15
movq %rax, -0x40(%rbp)
leaq 0x13443(%rip), %rax     # 0x16338
movq (%rax), %rdi
movq %rax, %r13
movq 0x38(%r12), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0xbbeb(%rip), %rsi      # 0xeafa
xorl %eax, %eax
callq 0x10f0
movq %rbx, -0x38(%rbp)
movq %r13, %rbx
movq (%r13), %r13
movl 0x1c(%r15), %edi
callq 0x156f
leaq 0xbbd6(%rip), %rsi      # 0xeb07
leaq 0x13428(%rip), %rdx     # 0x16360
movq %r13, %rdi
movq %rdx, %r13
xorl %eax, %eax
callq 0x10f0
movq (%rbx), %rdi
leaq 0xbbca(%rip), %rsi      # 0xeb19
movl -0x2c(%rbp), %edx
xorl %eax, %eax
callq 0x10f0
movq (%rbx), %rdi
movq %rbx, %r15
movq 0x38(%r12), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0xb757(%rip), %rsi      # 0xe6ce
xorl %eax, %eax
callq 0x10f0
movq (%rbx), %rcx
leaq 0xbb9c(%rip), %rdi      # 0xeb24
pushq $0xd
popq %rsi
pushq $0x1
popq %rdx
callq 0x1160
movq (%rbx), %rdi
leaq 0xbb95(%rip), %rsi      # 0xeb32
movl %r14d, %edx
xorl %eax, %eax
callq 0x10f0
movq 0x38(%r12), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x2bdf
movq (%rbx), %rbx
movq -0x40(%rbp), %r12
movl 0x1c(%r12), %edi
callq 0x156f
leaq 0xbb6b(%rip), %rsi      # 0xeb40
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x10f0
leaq 0xbb6a(%rip), %rsi      # 0xeb53
pushq $0x8
popq %rdi
callq 0x151a
movq (%r15), %rcx
leaq 0xbb6b(%rip), %rdi      # 0xeb66
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x1160
movq (%r15), %rbx
movl 0x1c(%r12), %edi
callq 0x156f
leaq 0xbb56(%rip), %rsi      # 0xeb70
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x10f0
movq (%r15), %rdi
leaq 0xbb51(%rip), %rsi      # 0xeb82
movl -0x2c(%rbp), %edx
xorl %eax, %eax
callq 0x10f0
movq (%r15), %rdi
leaq 0xbad4(%rip), %rsi      # 0xeb19
jmp 0x3315
movq 0x30(%r14), %rax
movq 0x38(%rax), %r12
movl (%r12), %eax
addl $-0x40, %eax
movabsq $0x2000000000301, %r15  # imm = 0x2000000000301
cmpl $0x31, %eax
ja 0x34ee
btq %rax, %r15
jae 0x34ee
movq %r14, %rdi
movq %rbx, %rsi
callq 0x18eb
movq 0x30(%r14), %rcx
testl %eax, %eax
je 0x340e
movq 0x8(%rcx), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xac19
movq %rax, %r15
movq 0x30(%r14), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xac19
movq %rax, %rbx
movq %r15, %rdi
callq 0xcd66
testl %eax, %eax
je 0x33fe
movq %rbx, %rdi
callq 0xcd66
testl %eax, %eax
je 0x33fe
orb $-0x80, 0x13277(%rip)   # 0x16359
leaq 0xba2d(%rip), %rsi      # 0xeb16
movq %r15, %rdi
callq 0x15ee
leaq 0xb18a(%rip), %rsi      # 0xe282
movq %r15, %rdi
callq 0x1657
leaq 0xb208(%rip), %rsi      # 0xe30f
movq %r15, %rdi
callq 0x16c0
leaq 0xb9cf(%rip), %rsi      # 0xeae5
movq %rbx, %rdi
callq 0x16c0
leaq 0x13213(%rip), %r15     # 0x16338
movq (%r15), %rcx
leaq 0xb3c1(%rip), %rdi      # 0xe4f0
pushq $0xd
popq %r14
pushq $0x1
popq %rbx
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1160
movq (%r15), %rcx
leaq 0xb3b3(%rip), %rdi      # 0xe4fe
pushq $0xc
popq %rsi
movq %rbx, %rdx
callq 0x1160
movq (%r15), %rcx
leaq 0xb3ab(%rip), %rdi      # 0xe50b
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1160
movq (%r15), %rcx
leaq 0xb974(%rip), %rdi      # 0xeae9
pushq $0x10
popq %rsi
movq %rbx, %rdx
callq 0x1160
jmp 0x352d
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0xab11
movq %rax, %r15
movq 0x88(%rax), %r12
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x30(%rax), %rax
movq %rax, %r13
movq 0x38(%rax), %rax
testq %rax, %rax
jne 0x31b4
leaq 0x13171(%rip), %rax     # 0x16338
movq (%rax), %rdi
movl 0x108(%r15), %edx
leaq 0xb5e1(%rip), %rsi      # 0xe7b9
xorl %eax, %eax
callq 0x10f0
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3891
leaq 0x13144(%rip), %r12     # 0x16338
movq (%r12), %rdi
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0xb9f7(%rip), %rsi      # 0xec06
xorl %eax, %eax
callq 0x10f0
leaq 0xb9f9(%rip), %rsi      # 0xec16
pushq $0xb
popq %rdi
callq 0x151a
movq (%r12), %rdi
movl 0x104(%r15), %edx
leaq 0xb5a0(%rip), %rsi      # 0xe7d7
xorl %eax, %eax
callq 0x10f0
movq 0x30(%r14), %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x39a4
movq 0x38(%r14), %r13
movl 0x130e5(%rip), %r14d    # 0x16348
leal 0x1(%r14), %edx
movl %edx, -0x38(%rbp)
addl $0x2, %r14d
movl %r14d, 0x130d3(%rip)    # 0x16348
leaq 0x130bc(%rip), %r15     # 0x16338
movq (%r15), %rdi
leaq 0xb90a(%rip), %rsi      # 0xeb90
xorl %eax, %eax
callq 0x10f0
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1e06
movq (%r15), %rcx
leaq 0xb06f(%rip), %rdi      # 0xe313
pushq $0x9
popq %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
callq 0x1160
movq (%r15), %rcx
leaq 0xb8e0(%rip), %rdi      # 0xeb9d
pushq $0xb
popq %rsi
movq %r12, %rdx
callq 0x1160
leaq 0xb8da(%rip), %rsi      # 0xeba9
pushq $0xb
popq %rdi
callq 0x151a
movq (%r15), %rdi
leaq 0xb8e6(%rip), %rsi      # 0xebc7
movl %r14d, %edx
xorl %eax, %eax
callq 0x10f0
movq 0x38(%r13), %rdi
movq %rbx, %rsi
callq 0x2bdf
movq (%r15), %rdi
leaq 0xb8d6(%rip), %rsi      # 0xebd7
movl -0x38(%rbp), %edx
xorl %eax, %eax
callq 0x10f0
movq (%r15), %rdi
leaq 0xb87b(%rip), %rsi      # 0xeb90
movl %r14d, %edx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10f0
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %r12
movq %r12, %rdi
callq 0x2b56
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rdi
callq 0x2b29
movslq %eax, %r15
leaq (,%r15,4), %rdi
callq 0x1110
movq %rax, %r13
movq %r14, %rdi
movq %rbx, -0x38(%rbp)
movq %rbx, %rsi
movl %r15d, %edx
movq %rax, %rcx
callq 0x355f
movl %eax, -0x2c(%rbp)
movl 0x12fb4(%rip), %r15d    # 0x16340
incl %r15d
movl %r15d, 0x12faa(%rip)    # 0x16340
testq %r12, %r12
je 0x3452
leaq 0x12f92(%rip), %rbx     # 0x16338
movq (%rbx), %rdi
movl (%r13), %edx
leaq 0xb833(%rip), %rsi      # 0xebe7
xorl %eax, %eax
callq 0x10f0
movq %r12, %rdi
movq -0x38(%rbp), %rsi
callq 0x2bdf
movq (%rbx), %rdi
leaq 0xb823(%rip), %rsi      # 0xebf4
movl %r15d, %edx
xorl %eax, %eax
callq 0x10f0
movq 0x38(%r12), %rax
testq %rax, %rax
je 0x33f5
cmpl $0x55, (%rax)
movq 0x38(%rax), %r12
je 0x3417
movq 0x38(%r12), %r12
jmp 0x33f8
xorl %r12d, %r12d
addq $0x4, %r13
jmp 0x3396
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1968
jmp 0x352d
movq 0x38(%rcx), %rdi
jmp 0x350f
leaq 0x12f1a(%rip), %rbx     # 0x16338
movq (%rbx), %rdi
leaq 0xb7bf(%rip), %rsi      # 0xebe7
movl -0x2c(%rbp), %edx
xorl %eax, %eax
callq 0x10f0
movq %r12, %rdi
movq -0x38(%rbp), %rsi
callq 0x2bdf
movq (%rbx), %rdi
leaq 0xb7ac(%rip), %rsi      # 0xebf4
movl %r15d, %edx
xorl %eax, %eax
callq 0x10f0
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rbx
leaq 0x12ecf(%rip), %r14     # 0x16338
movq (%r14), %rdi
leaq 0xb774(%rip), %rsi      # 0xebe7
movl %r15d, %edx
xorl %eax, %eax
callq 0x10f0
movq 0x20(%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x3ae7
movq 0x20(%rbx), %rax
movl 0x110(%rax), %edx
testl %edx, %edx
jle 0x34c9
movq (%r14), %rdi
leaq 0xb5d5(%rip), %rsi      # 0xea7a
xorl %eax, %eax
callq 0x10f0
leaq 0xb5d5(%rip), %rsi      # 0xea88
pushq $0xb
popq %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x151a
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3a32
movq %r14, %rdi
callq 0x18c3
testl %eax, %eax
je 0x354d
movq 0x30(%r12), %rdi
movl (%rdi), %eax
addl $-0x40, %eax
cmpl $0x31, %eax
ja 0x355a
btq %rax, %r15
jae 0x355a
pushq $0x1
popq %r15
movq %rbx, %rsi
movl %r15d, %edx
callq 0x1e06
movq 0x30(%r14), %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x1ace
leaq 0x12e04(%rip), %rax     # 0x16338
movq (%rax), %rsi
pushq $0xa
popq %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10d0
xorl %r15d, %r15d
movq %r12, %rdi
movq %rbx, %rsi
xorl %edx, %edx
jmp 0x3519
xorl %r15d, %r15d
jmp 0x3513