// File: /workspace/github_c_makefile_star2_O3/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 0x2e388(%rip), %r15     # 0x31028
testq %r14, %r14
je 0x35ee
movl (%r14), %eax
cmpl $0xd, %eax
jne 0x2ccb
movq 0x30(%r14), %rdi
movq %rbx, %rsi
callq 0x2c82
movq 0x38(%r14), %r14
testq %r14, %r14
jne 0x2ca0
jmp 0x340b
cmpl $0x4f, %eax
jg 0x2d00
leal -0x3e(%rax), %ecx
cmpl $0x6, %ecx
jbe 0x2d7e
cmpl $0xc, %eax
jne 0x2fda
movq 0x20(%r14), %rbx
movq 0x30(%r14), %r14
testq %r14, %r14
jne 0x2ca0
movq 0x10(%rbx), %rax
cmpq (%r15), %rax
jne 0x2ca0
jmp 0x364e
cmpl $0x55, %eax
jg 0x2e86
cmpl $0x50, %eax
je 0x3197
cmpl $0x52, %eax
jne 0x35ee
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %r15
movq %r15, %rdi
callq 0x2c01
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rcx
testq %rcx, %rcx
je 0x3465
movl $0x1, %edx
movl %edx, %eax
movq 0x38(%rcx), %rcx
testq %rcx, %rcx
je 0x3467
cmpl $0x55, (%rcx)
je 0x3467
movq 0x38(%rcx), %rcx
movq 0x38(%rcx), %rcx
leal 0x1(%rax), %edx
testq %rcx, %rcx
jne 0x2d51
jmp 0x3467
leaq 0xc45b(%rip), %rax      # 0xf1e0
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl 0x8(%rbx), %r13d
movb $0x1, %r12b
cmpl $0x4, %r13d
jne 0x2db0
cmpq %r14, 0x28(%r14)
jne 0x2db0
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, -0x30(%rbp)
xorl %r14d, %r14d
movq %rax, %rcx
movq 0x38(%rax), %rax
incl %r14d
testq %rax, %rax
jne 0x2dc3
movq 0x8(%rcx), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xb8e8
movq %rax, %r15
movl 0x18(%rax), %edx
testl %edx, %edx
setle %al
xorb $0x1, %r12b
orb %r12b, %al
jne 0x2e46
leaq 0x1454b(%rip), %rax     # 0x17348
movq (%rax), %rdi
imull %r14d, %edx
leaq 0xcc97(%rip), %rsi      # 0xfaa2
xorl %eax, %eax
callq 0x1100
cmpl $0x4, %r13d
leaq 0xccb0(%rip), %rax      # 0xfacd
leaq 0xcc8c(%rip), %rsi      # 0xfab0
cmoveq %rax, %rsi
movl $0xb, %edi
callq 0x152e
leaq 0x1450f(%rip), %rax     # 0x17348
movq (%rax), %rsi
movl $0xa, %edi
callq 0x10e0
movq -0x30(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jne 0x35ee
movq %r15, %rdi
callq 0xe01a
testl %eax, %eax
setne %al
orb %al, %r12b
jne 0x35ee
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x27ca
cmpl $0x56, %eax
je 0x332a
cmpl $0x69, %eax
jne 0x35ee
movq 0x30(%r14), %rax
movq 0x38(%rax), %rdi
movl (%rdi), %eax
leal -0x40(%rax), %ecx
cmpl $0x31, %ecx
ja 0x35fd
movabsq $0x2000000000301, %rdx  # imm = 0x2000000000301
btq %rcx, %rdx
jae 0x35fd
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1910
movq 0x30(%r14), %rcx
testl %eax, %eax
je 0x3518
movq 0x8(%rcx), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xb8e8
movq %rax, %r15
movq 0x30(%r14), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xb8e8
movq %rax, %rbx
movq %r15, %rdi
callq 0xe01a
testl %eax, %eax
je 0x3508
movq %rbx, %rdi
callq 0xe01a
testl %eax, %eax
je 0x3508
orb $-0x80, 0x1443b(%rip)   # 0x17369
leaq 0xcbe1(%rip), %rsi      # 0xfb16
movq %r15, %rdi
callq 0x1603
leaq 0xc33e(%rip), %rsi      # 0xf282
movq %r15, %rdi
callq 0x166c
leaq 0xc3bc(%rip), %rsi      # 0xf30f
movq %r15, %rdi
callq 0x16d5
leaq 0xcb83(%rip), %rsi      # 0xfae5
movq %rbx, %rdi
callq 0x16d5
leaq 0x143d7(%rip), %rbx     # 0x17348
movq (%rbx), %rcx
leaq 0xc575(%rip), %rdi      # 0xf4f0
movl $0xd, %esi
movl $0x1, %edx
callq 0x1170
movq (%rbx), %rcx
leaq 0xc56a(%rip), %rdi      # 0xf4fe
movl $0xc, %esi
movl $0x1, %edx
callq 0x1170
movq (%rbx), %rcx
leaq 0xc55e(%rip), %rdi      # 0xf50b
movl $0xd, %esi
movl $0x1, %edx
callq 0x1170
movq (%rbx), %rcx
leaq 0xcb23(%rip), %rdi      # 0xfae9
movl $0x10, %esi
movl $0x1, %edx
callq 0x1170
jmp 0x362c
cmpl $0x34, %eax
jne 0x35ee
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0xb792
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 0x3012
leaq 0x14323(%rip), %rax     # 0x17348
movq (%rax), %rdi
movl 0x108(%r15), %edx
leaq 0xc783(%rip), %rsi      # 0xf7b9
xorl %eax, %eax
callq 0x1100
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x39da
leaq 0x142f6(%rip), %r12     # 0x17348
movq (%r12), %rdi
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0xcb99(%rip), %rsi      # 0xfc06
xorl %eax, %eax
callq 0x1100
leaq 0xcb9b(%rip), %rsi      # 0xfc16
movl $0xb, %edi
callq 0x152e
movq (%r12), %rdi
movl 0x104(%r15), %edx
leaq 0xc740(%rip), %rsi      # 0xf7d7
xorl %eax, %eax
callq 0x1100
movq 0x30(%r14), %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3afe
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdi
callq 0xb792
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 0x30d7
movq %rbx, %rdx
callq 0x39da
leaq 0x14256(%rip), %r12     # 0x17348
movq (%r12), %rbx
movq 0x8(%r14), %rax
movq 0x8(%rax), %r14
leaq 0xcb0c(%rip), %rsi      # 0xfc11
movq %r14, %rdi
callq 0x10f0
testl %eax, %eax
leaq 0xcafa(%rip), %rdx      # 0xfc10
cmovneq %r14, %rdx
leaq 0xcae5(%rip), %rsi      # 0xfc06
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1100
leaq 0xcae4(%rip), %rsi      # 0xfc16
movl $0xb, %edi
callq 0x152e
movq (%r12), %rdi
movl 0x104(%r15), %edx
leaq 0xc689(%rip), %rsi      # 0xf7d7
jmp 0x33f6
movq 0x38(%r14), %rdi
movq %rbx, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20b8
movq 0x38(%r14), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xb8e8
movq %rax, %rsi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x24b6
movq 0x38(%r14), %r12
movl 0x141b3(%rip), %ecx     # 0x17354
leal 0x1(%rcx), %eax
movl %eax, -0x30(%rbp)
addl $0x2, %ecx
movq %rcx, -0x38(%rbp)
movl %ecx, 0x141a0(%rip)     # 0x17354
movq 0x8(%r12), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0xb8e8
movq %rax, %r15
movq %rax, -0x40(%rbp)
leaq 0x14175(%rip), %r14     # 0x17348
movq (%r14), %rdi
movq 0x38(%r12), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0xc910(%rip), %rsi      # 0xfafa
xorl %eax, %eax
callq 0x1100
movq (%r14), %r13
movl 0x1c(%r15), %edi
callq 0x1580
leaq 0xc903(%rip), %rsi      # 0xfb07
leaq 0x14165(%rip), %rdx     # 0x17370
movq %r13, %rdi
movq %rdx, %r13
xorl %eax, %eax
callq 0x1100
movq (%r14), %rdi
leaq 0xc8f7(%rip), %rsi      # 0xfb19
movl -0x30(%rbp), %edx
xorl %eax, %eax
callq 0x1100
movq (%r14), %rdi
movq 0x38(%r12), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0xc487(%rip), %rsi      # 0xf6ce
xorl %eax, %eax
callq 0x1100
movq (%r14), %rcx
leaq 0xc8cc(%rip), %rdi      # 0xfb24
movl $0xd, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rdi
leaq 0xc8c1(%rip), %rsi      # 0xfb32
movq -0x38(%rbp), %r15
movl %r15d, %edx
xorl %eax, %eax
callq 0x1100
movq 0x38(%r12), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rdi
movq %rbx, %rsi
callq 0x2c82
movq (%r14), %rbx
movq -0x40(%rbp), %r12
movl 0x1c(%r12), %edi
callq 0x1580
leaq 0xc894(%rip), %rsi      # 0xfb40
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1100
leaq 0xc893(%rip), %rsi      # 0xfb53
movl $0x8, %edi
callq 0x152e
movq (%r14), %rcx
leaq 0xc892(%rip), %rdi      # 0xfb66
movl $0x9, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rbx
movl 0x1c(%r12), %edi
callq 0x1580
leaq 0xc879(%rip), %rsi      # 0xfb70
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1100
movq (%r14), %rdi
leaq 0xc874(%rip), %rsi      # 0xfb82
movl -0x30(%rbp), %edx
xorl %eax, %eax
callq 0x1100
movq (%r14), %rdi
leaq 0xc7f7(%rip), %rsi      # 0xfb19
movl %r15d, %edx
jmp 0x33f6
movq 0x38(%r14), %r13
movl 0x14023(%rip), %r14d    # 0x17358
leal 0x1(%r14), %r15d
addl $0x2, %r14d
movl %r14d, 0x14014(%rip)    # 0x17358
leaq 0x13ffd(%rip), %r12     # 0x17348
movq (%r12), %rdi
leaq 0xc83a(%rip), %rsi      # 0xfb90
movl %r15d, %edx
xorl %eax, %eax
callq 0x1100
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1e4f
movq (%r12), %rcx
leaq 0xbf9b(%rip), %rdi      # 0xf313
movl $0x9, %esi
movl $0x1, %edx
callq 0x1170
movq (%r12), %rcx
leaq 0xc80b(%rip), %rdi      # 0xfb9d
movl $0xb, %esi
movl $0x1, %edx
callq 0x1170
leaq 0xc801(%rip), %rsi      # 0xfba9
movl $0xb, %edi
callq 0x152e
movq (%r12), %rdi
leaq 0xc80a(%rip), %rsi      # 0xfbc7
movl %r14d, %edx
xorl %eax, %eax
callq 0x1100
movq 0x38(%r13), %rdi
movq %rbx, %rsi
callq 0x2c82
movq (%r12), %rdi
leaq 0xc7f9(%rip), %rsi      # 0xfbd7
movl %r15d, %edx
xorl %eax, %eax
callq 0x1100
movq (%r12), %rdi
leaq 0xc79d(%rip), %rsi      # 0xfb90
movl %r14d, %edx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1100
cmpl $0x4, 0x8(%rbx)
je 0x35ee
movq 0x80(%rbx), %rdi
callq 0x3c67
movq 0x10(%rbx), %rax
cmpq (%r15), %rax
je 0x364e
movl 0x110(%rbx), %edx
testl %edx, %edx
jle 0x35ee
leaq 0x13f05(%rip), %rax     # 0x17348
movq (%rax), %rdi
leaq 0xc62c(%rip), %rsi      # 0xfa79
xorl %eax, %eax
callq 0x1100
leaq 0xc62d(%rip), %rsi      # 0xfa88
movl $0xa, %edi
jmp 0x35db
xorl %eax, %eax
movslq %eax, %r12
leaq (,%r12,4), %rdi
callq 0x1120
movq %rax, %r13
movq %r14, %rdi
movq %rbx, -0x30(%rbp)
movq %rbx, %rsi
movl %r12d, %edx
movq %rax, %rcx
callq 0x3694
movl %eax, -0x38(%rbp)
movl 0x13eb7(%rip), %r12d    # 0x17350
incl %r12d
movl %r12d, 0x13ead(%rip)    # 0x17350
testq %r15, %r15
je 0x3575
leaq 0x13e95(%rip), %rbx     # 0x17348
movq (%rbx), %rdi
movl (%r13), %edx
leaq 0xc726(%rip), %rsi      # 0xfbe7
xorl %eax, %eax
callq 0x1100
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0x2c82
movq (%rbx), %rdi
leaq 0xc716(%rip), %rsi      # 0xfbf4
movl %r12d, %edx
xorl %eax, %eax
callq 0x1100
movq 0x38(%r15), %rax
testq %rax, %rax
je 0x3575
cmpl $0x55, (%rax)
movq 0x38(%rax), %r15
je 0x353a
movq 0x38(%r15), %r15
addq $0x4, %r13
jmp 0x34a3
movq %r15, %rdi
movq %rbx, %rsi
callq 0x198f
jmp 0x362c
movq 0x38(%rcx), %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x1e4f
movq 0x30(%r14), %rdi
movq %rbx, %rsi
movl $0x1, %edx
jmp 0x3627
leaq 0x13e07(%rip), %rbx     # 0x17348
movq (%rbx), %rdi
leaq 0xc69c(%rip), %rsi      # 0xfbe7
movl -0x38(%rbp), %edx
xorl %eax, %eax
callq 0x1100
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0x2c82
movq (%rbx), %rdi
leaq 0xc689(%rip), %rsi      # 0xfbf4
movl %r12d, %edx
xorl %eax, %eax
callq 0x1100
movq 0x38(%r14), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %rax
movq 0x38(%rax), %r14
leaq 0x13dbc(%rip), %rbx     # 0x17348
movq (%rbx), %rdi
leaq 0xc651(%rip), %rsi      # 0xfbe7
movl %r12d, %edx
xorl %eax, %eax
callq 0x1100
movq 0x20(%r14), %rax
movq 0x80(%rax), %rdi
callq 0x3c67
movq 0x20(%r14), %rax
movl 0x110(%rax), %edx
testl %edx, %edx
jle 0x35ee
movq (%rbx), %rdi
leaq 0xc4b2(%rip), %rsi      # 0xfa7a
xorl %eax, %eax
callq 0x1100
leaq 0xc4b2(%rip), %rsi      # 0xfa88
movl $0xb, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x152e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl $-0x59, %eax
cmpl $-0x2, %eax
jb 0x3610
movq 0x30(%rdi), %rax
cmpq $0x0, 0x38(%rax)
je 0x3664
xorl %r15d, %r15d
movq %rbx, %rsi
xorl %edx, %edx
callq 0x1e4f
movq 0x30(%r14), %rdi
movq %rbx, %rsi
movl %r15d, %edx
callq 0x1afd
leaq 0x13d15(%rip), %rax     # 0x17348
movq (%rax), %rsi
movl $0xa, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10e0
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3b9b
movl (%rax), %ecx
addl $-0x40, %ecx
cmpl $0x31, %ecx
ja 0x368f
movl $0x1, %r15d
movabsq $0x2000000000301, %rdx  # imm = 0x2000000000301
btq %rcx, %rdx
jae 0x368f
movq %rax, %rdi
movq %rbx, %rsi
movl %r15d, %edx
jmp 0x3618
xorl %r15d, %r15d
jmp 0x3684