// File: /workspace/github_c_makefile_star2_O2/goodpaul6[P]generic/script.c
// Function: resolve_type_tags
static void resolve_type_tags(script_t* script, void* vexp)
{
	expr_t* exp = vexp;
	
	// NOTE: Pathetic attempt at providing proper
	// line information for type warnings
	g_file = exp->ctx.file;
	g_line = exp->ctx.line;
	
	switch(exp->type)
	{
		case EXP_ATOMIC:
		{
			exp->tag = create_type_tag(script, TAG_VOID);
			resolve_type_tags(script, exp->atomx);
		} break;

		case EXP_DOT: case EXP_COLON:
		{
			resolve_type_tags(script, exp->dotx.value);
			if (exp->dotx.value->tag->type != TAG_STRUCT)
				error_defer_e(exp->dotx.value, "Attempted to access members in non-struct type\n");
			else
			{
				char found = 0;

				type_tag_t* tag = exp->dotx.value->tag;
				for (int i = 0; i < tag->ds.members.length; ++i)
				{
					type_tag_member_t* mem = vec_get(&tag->ds.members, i);
					if (strcmp(mem->name, exp->dotx.name) == 0)
					{
						exp->tag = mem->type;
						found = 1;

						if (exp->type == EXP_COLON) error_defer_e(exp, "Attempted to use ':' operator to access member value; use '.' instead\n");
						break;
					}
				}

				if (!found)
				{
					func_decl_t* decl = get_struct_member_function(script, exp->dotx.value->tag->ds.name, exp->dotx.name);
					if (decl) found = 1;
					if (exp->type == EXP_DOT) error_defer_e(exp, "Attempted to use '.' operator to access member function; use ':' instead\n");

					if (!found)
						error_exit_e(exp, "Attempted to access non-existent member '%s' in struct %s\n", exp->dotx.name, tag->ds.name);
					else
						exp->tag = decl->tag;
				}
			}
		} break;
		
		case EXP_NULL:
		{
			exp->tag = create_type_tag(script, TAG_DYNAMIC);
		} break;
		
		case EXP_STRUCT_DECL:
		{
			exp->tag = create_type_tag(script, TAG_VOID);
			
			for(int i = 0; i < exp->struct_tag->ds.members.length; ++i)
			{
				type_tag_member_t* mem = vec_get(&exp->struct_tag->ds.members, i);
				if(mem->default_value)
				{	
					resolve_type_tags(script, mem->default_value);
					if(!compare_type_tags(mem->type, mem->default_value->tag))
						error_defer_e(mem->default_value, "Type of default value does not match type of member variable '%s'\n", mem->name);
				}
			}
		} break;
		
		case EXP_STRUCT_NEW:
		{
			exp->tag = exp->newx.type;
			
			for(int i = 0; i < exp->newx.init.length; ++i)
			{
				expr_t* init = vec_get_value(&exp->newx.init, i, expr_t*);
				
				int member_index = get_struct_type_member_index(exp->newx.type, init->binx.lhs->varx.name);
				resolve_type_tags(script, init->binx.rhs);
					
				type_tag_member_t* mem = vec_get(&exp->newx.type->ds.members, member_index);
				if(!compare_type_tags(init->binx.rhs->tag, mem->type))
					error_defer_e(init->binx.rhs, "Type of initializer does not match type of member '%s' being initialized\n", mem->name);
			}
		} break;
			
		case EXP_NUMBER:
		{
			exp->tag = create_type_tag(script, TAG_NUMBER);
		} break;
		
		case EXP_STRING:
		{
			exp->tag = create_type_tag(script, TAG_STRING);
		} break;
		
		case EXP_BOOL:
		{
			exp->tag = create_type_tag(script, TAG_BOOL);
		} break;
		
		case EXP_CHAR:
		{
			exp->tag = create_type_tag(script, TAG_CHAR);
		} break;
		
		case EXP_VAR:
		{
			if(!exp->varx.decl)
			{
				func_decl_t* decl = reference_function(script, exp->varx.name);
				if(decl) exp->tag = decl->tag;
				else error_exit_e(exp, "Referencing undeclared function/variable '%s'\n", exp->varx.name); 
			}
			else
				exp->tag = exp->varx.decl->tag;
		} break;
		
		case EXP_WRITE:
		{
			exp->tag = create_type_tag(script, TAG_VOID);
			resolve_type_tags(script, exp->write);
		} break;
		
		case EXP_UNARY:
		{
			resolve_type_tags(script, exp->unaryx.rhs);
			switch(exp->unaryx.op)
			{
				case TOK_NOT:
				{
					if(exp->unaryx.rhs->tag->type != TAG_BOOL)
						error_defer_e(exp->unaryx.rhs, "Attempted to use unary ! operator on non-boolean value\n");
					exp->tag = create_type_tag(script, TAG_BOOL);
				} break;
				
				case TOK_MINUS:
				{
					if(exp->unaryx.rhs->tag->type != TAG_NUMBER)
						error_defer_e(exp->unaryx.rhs, "Attempted to use unary - operator on non-numerical value\n");
					exp->tag = create_type_tag(script, TAG_NUMBER);
				} break;
				
				default:
					error_exit_e(exp, "No type resolution for %s operator\n", g_token_names[exp->unaryx.op]);
					break;
			}
		} break;
		
		case EXP_BINARY:
		{
			resolve_type_tags(script, exp->binx.lhs);
			resolve_type_tags(script, exp->binx.rhs);
		
			// NOTE: assignment operation lhs does not need to be
			// number
			if(exp->binx.op != TOK_ASSIGN)
			{ 
				if(!compare_type_tags(exp->binx.lhs->tag, exp->binx.rhs->tag) || !is_type_tag(exp->binx.lhs->tag, TAG_NUMBER))
				{	
					if(exp->binx.op != TOK_EQUALS && exp->binx.op != TOK_NOTEQUAL && 
						exp->binx.op != TOK_LAND && exp->binx.op != TOK_LOR)
						error_defer_e(exp->binx.lhs, "Invalid types in binary %s operation\n", g_token_names[exp->binx.op]);
				}
			}
			else
			{
				// NOTE: If the type of the lhs is unknown, set it to the type of the rhs
				// (since this is an assignment, after all)
				if (exp->binx.lhs->tag->type == TAG_UNKNOWN)
				{
					exp->binx.lhs->tag = exp->binx.rhs->tag;

					var_decl_t* decl = get_root_var_decl(exp->binx.lhs);
					if(decl)
						decl->tag = exp->binx.lhs->tag;
				}
				else if (!are_assignment_types_valid(exp->binx.lhs, exp->binx.rhs))
					error_defer_e(exp->binx.lhs, "Type of lhs in assignment operation does not match the type of rhs\n");
			}

			switch(exp->binx.op)
			{
				case TOK_PLUS:
				case TOK_MINUS:
				case TOK_MUL:
				case TOK_DIV: 
				case TOK_MOD: exp->tag = create_type_tag(script, TAG_NUMBER); break;
				
				case TOK_LTE:
				case TOK_GTE:
				case TOK_LT:
				case TOK_GT:
				case TOK_EQUALS:
				case TOK_NOTEQUAL:
				case TOK_LAND:
				case TOK_LOR: exp->tag = create_type_tag(script, TAG_BOOL); break;
				
				default: exp->tag = create_type_tag(script, TAG_VOID); break;
			}
		} break;
		
		case EXP_CALL:
		{
			resolve_type_tags(script, exp->callx.func);
			if(exp->callx.func->tag->type == TAG_DYNAMIC)
				warn_e(exp, WARN_CALL_DYNAMIC);
			
			if(exp->callx.func->tag->type != TAG_FUNC && exp->callx.func->tag->type != TAG_DYNAMIC)
				error_defer_e(exp, "Attempting to call something that is not a function\n");
			
			if(exp->callx.func->tag->type != TAG_DYNAMIC && exp->callx.args.length != exp->callx.func->tag->func.arg_types.length)
				error_defer_e(exp, "Passed %d argument(s) into function expecting %d argument(s)\n", 
				exp->callx.args.length, exp->callx.func->tag->func.arg_types.length);
			else
			{
				for(int i = 0; i < exp->callx.args.length; ++i)
				{
					expr_t* arg = vec_get_value(&exp->callx.args, i, expr_t*);
					resolve_type_tags(script, arg);
					
					if(exp->callx.func->tag->type != TAG_DYNAMIC)
					{
						type_tag_t* expected_tag = vec_get_value(&exp->callx.func->tag->func.arg_types, i, type_tag_t*);
						if(!compare_type_tags(arg->tag, expected_tag)) 
							error_defer_e(arg, "Type of argument %i does not match expected type\n", i + 1);
					}
				}
			}
			
			exp->tag = exp->callx.func->tag->func.return_type;
		} break;
		
		case EXP_PAREN:
		{
			resolve_type_tags(script, exp->paren);
			exp->tag = exp->paren->tag;
		} break;
		
		case EXP_BLOCK:
		{
			exp->tag = create_type_tag(script, TAG_VOID);
			for(int i = 0; i < exp->block.length; ++i)
			{
				expr_t* e = vec_get_value(&exp->block, i, expr_t*);
				resolve_type_tags(script, e);
			}
		} break;
		
		case EXP_ARRAY_INDEX:
		{
			resolve_type_tags(script, exp->array_index.array);
			resolve_type_tags(script, exp->array_index.index);

			if(!is_type_tag(exp->array_index.index->tag, TAG_NUMBER))
				error_defer_e(exp->array_index.index, "Attempting to index array with non-number value\n");
			
			switch(exp->array_index.array->tag->type)
			{
				case TAG_STRING: exp->tag = create_type_tag(script, TAG_CHAR); break;
				case TAG_ARRAY: exp->tag = exp->array_index.array->tag->contained; break;
				default:
					error_defer_e(exp->array_index.array, "Attempting to index non-indexable type\n");
					break;
			}
		} break;
		
		case EXP_EXTERN:
		case EXP_EXTERN_LIST: break;
		
		case EXP_ARRAY_LITERAL:
		{
			for(int i = 0; i < exp->array_literal.values.length; ++i)
				resolve_type_tags(script, vec_get_value(&exp->array_literal.values, i, expr_t*));
			
			type_tag_t* tag = create_type_tag(script, TAG_ARRAY);
			if(exp->array_literal.contained) tag->contained = exp->array_literal.contained;
			else
			{
				expr_t* first = vec_get_value(&exp->array_literal.values, 0, expr_t*);
				tag->contained = first->tag;
				
				for(int i = 1; i < exp->array_literal.values.length; ++i)
				{
					expr_t* e = vec_get_value(&exp->array_literal.values, i, expr_t*);
					if(!compare_type_tags(e->tag, tag->contained))
					{
						warn_e(e, WARN_DYNAMIC_ARRAY_LITERAL);
						tag = create_type_tag(script, TAG_DYNAMIC);			// NOTE: okay, so it must be a dynamic literal
						break;										// NOTE: also, we don't care about the types anymore
					}
					// error_defer_e(e, "Array literal value type does not match the array's contained type\n");
				}
			}
			
			exp->tag = tag;
		} break;
		
		case EXP_LEN:
		{
			exp->tag = create_type_tag(script, TAG_NUMBER);
			resolve_type_tags(script, exp->len);
			
			if(exp->len->tag->type != TAG_STRING && exp->len->tag->type != TAG_ARRAY)
				error_defer_e(exp->len, "Attempted to find the length of non-measurable type\n");
		} break;
		
		case EXP_IF:
		{
			exp->tag = create_type_tag(script, TAG_VOID);
			resolve_type_tags(script, exp->ifx.cond);
			
			if(!is_type_tag(exp->ifx.cond->tag, TAG_BOOL))
				error_defer_e(exp->ifx.cond, "Condition does not evaluate to a boolean value\n");
			
			resolve_type_tags(script, exp->ifx.body);
			if(exp->ifx.alt)
				resolve_type_tags(script, exp->ifx.alt);
		} break;
		
		case EXP_WHILE:
		{
			exp->tag = create_type_tag(script, TAG_VOID);
			resolve_type_tags(script, exp->whilex.cond);
			
			if(!is_type_tag(exp->whilex.cond->tag, TAG_BOOL)) 
				error_defer_e(exp->whilex.cond, "Condition does not evaluate to a boolean value\n");
			
			resolve_type_tags(script, exp->whilex.body);
		} break;

		case EXP_FOR:
		{
			exp->tag = create_type_tag(script, TAG_VOID);

			resolve_type_tags(script, exp->forx.init);
			resolve_type_tags(script, exp->forx.cond);
			resolve_type_tags(script, exp->forx.step);

			if (!is_type_tag(exp->forx.cond->tag, TAG_BOOL))
				error_defer_e(exp->forx.cond, "Condition does not evaluate to a boolean value\n");

			resolve_type_tags(script, exp->forx.body);
		} break;
		
		case EXP_RETURN:
		{
			exp->tag = create_type_tag(script, TAG_VOID);
			resolve_type_tags(script, exp->retx.value);
	
			if(!compare_type_tags(exp->retx.value->tag, exp->retx.parent->tag->func.return_type))
				error_defer_e(exp, "Returned value's type does not match the return type of the enclosing function.\n");
		} break;
		
		case EXP_FUNC:
		{
			exp->tag = create_type_tag(script, TAG_VOID);
			resolve_type_tags(script, exp->funcx.body);
		} break;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x53bf(%rip), %r15      # 0xd2c4
pushq $0x40
popq %r13
movq 0x10(%rbx), %rax
movq %rax, 0xc244(%rip)      # 0x14158
movl 0x8(%rbx), %eax
movl %eax, 0xc233(%rip)      # 0x14150
movl 0x28(%rbx), %eax
cmpq $0x1a, %rax
ja 0x86d8
movslq (%r15,%rax,4), %rax
addq %r15, %rax
pushq $0x38
popq %r12
jmpq *%rax
movq %r14, %rdi
xorl %esi, %esi
callq 0x731e
movq %rax, 0x30(%rbx)
jmp 0x7ff2
movq %r14, %rdi
xorl %esi, %esi
callq 0x731e
movq %rax, 0x30(%rbx)
jmp 0x7fef
movq %r14, %rdi
xorl %esi, %esi
callq 0x731e
movq %rax, 0x30(%rbx)
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x40(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x40(%rbx), %rdi
movq 0x30(%rdi), %rax
movl 0x20(%rax), %eax
decl %eax
pushq $0x50
popq %r12
cmpl $0x2, %eax
jb 0x7ff2
leaq 0x6be2(%rip), %rsi      # 0xeb8e
xorl %eax, %eax
callq 0x7dd4
jmp 0x7ff2
movq %r14, %rdi
xorl %esi, %esi
callq 0x731e
movq %rax, 0x30(%rbx)
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x38(%rbx), %rdi
movq 0x30(%rdi), %rax
movl 0x20(%rax), %eax
decl %eax
cmpl $0x2, %eax
jb 0x7fef
leaq 0x6ba6(%rip), %rsi      # 0xeb8e
xorl %eax, %eax
callq 0x7dd4
movq %r13, %r12
movq (%rbx,%r12), %rbx
jmp 0x7f09
movq %r14, %rdi
xorl %esi, %esi
callq 0x731e
movq %rax, 0x30(%rbx)
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x38(%rbx), %rdi
movq 0x30(%rdi), %rax
movl 0x20(%rax), %eax
decl %eax
cmpl $0x2, %eax
jb 0x8035
leaq 0x6b60(%rip), %rsi      # 0xeb8e
xorl %eax, %eax
callq 0x7dd4
movq 0x40(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x48(%rbx), %rbx
testq %rbx, %rbx
jne 0x7f09
jmp 0x86d8
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x38(%rbx), %rdi
movq 0x30(%rdi), %rax
cmpl $0xa, 0x20(%rax)
jne 0x82e8
leaq 0x60(%rax), %rcx
movq %rcx, -0x30(%rbp)
xorl %r12d, %r12d
movq %rax, %r15
cmpq %r12, 0x70(%rax)
jbe 0x850a
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0xc15c
movq %rax, %r13
movq (%rax), %rdi
movq 0x40(%rbx), %rsi
callq 0x2150
incq %r12
testl %eax, %eax
movq %r15, %rax
jne 0x807c
movq 0x10(%r13), %rax
movq %rax, 0x30(%rbx)
cmpl $0x3, 0x28(%rbx)
jne 0x86d8
leaq 0x670c(%rip), %rsi      # 0xe7d3
jmp 0x8502
leaq 0x40(%rbx), %r15
xorl %r12d, %r12d
cmpq %r12, 0x50(%rbx)
jbe 0x80f4
movq %r15, %rdi
movq %r12, %rsi
callq 0xc15c
movq (%rax), %rsi
movq %r14, %rdi
callq 0x7eea
incq %r12
jmp 0x80d3
pushq $0x7
popq %rsi
movq %r14, %rdi
callq 0x731e
movq %rax, %r12
movq 0x38(%rbx), %rax
testq %rax, %rax
je 0x85d4
movq %rax, 0x28(%r12)
jmp 0x870a
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x40(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
cmpl $0x24, 0x48(%rbx)
movq 0x38(%rbx), %rax
movq 0x30(%rax), %rdi
jne 0x854e
cmpl $0xb, 0x20(%rdi)
movq 0x40(%rbx), %rcx
movq 0x30(%rcx), %rsi
jne 0x867f
movq %rsi, 0x30(%rax)
movq 0x38(%rbx), %rax
movq %rax, %rcx
movl 0x28(%rcx), %edx
cmpl $0x6, %edx
je 0x8171
cmpl $0xf, %edx
jne 0x869c
movq 0x38(%rcx), %rcx
jmp 0x8160
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x38(%rbx), %rax
movq 0x30(%rax), %rax
jmp 0x86d4
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movslq 0x40(%rbx), %rax
cmpq $0x26, %rax
je 0x85af
cmpl $0x23, %eax
jne 0x8730
movq 0x38(%rbx), %rdi
movq 0x30(%rdi), %rax
cmpl $0x2, 0x20(%rax)
je 0x86bd
leaq 0x678f(%rip), %rsi      # 0xe95b
xorl %eax, %eax
callq 0x7dd4
jmp 0x86bd
movq 0x38(%rbx), %rax
movq %rax, 0x30(%rbx)
leaq 0x40(%rbx), %rax
movq %rax, -0x30(%rbp)
xorl %r13d, %r13d
cmpq %r13, 0x50(%rbx)
jbe 0x86d8
movq -0x30(%rbp), %rdi
movq %r13, %rsi
callq 0xc15c
movq (%rax), %r15
movq 0x38(%rbx), %rdi
movq 0x38(%r15), %rax
movq 0x38(%rax), %rsi
callq 0x88d3
movl %eax, %r12d
movq 0x40(%r15), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x38(%rbx), %rdi
addq $0x60, %rdi
movslq %r12d, %rsi
callq 0xc15c
movq %rax, %r12
movq 0x40(%r15), %rax
movq 0x30(%rax), %rdi
movq 0x10(%r12), %rsi
callq 0x73f5
testb %al, %al
jne 0x8263
movq 0x40(%r15), %rdi
movq (%r12), %rdx
leaq 0x6686(%rip), %rsi      # 0xe8e2
xorl %eax, %eax
callq 0x7dd4
incq %r13
jmp 0x81eb
pushq $0x1
jmp 0x86cb
pushq $0x5
jmp 0x86cb
movq %r14, %rdi
xorl %esi, %esi
callq 0x731e
movq %rax, 0x30(%rbx)
leaq 0x6614(%rip), %r15      # 0xe89f
xorl %r12d, %r12d
movq 0x38(%rbx), %rdi
cmpq %r12, 0x70(%rdi)
jbe 0x86d8
addq $0x60, %rdi
movq %r12, %rsi
callq 0xc15c
movq 0x18(%rax), %rsi
testq %rsi, %rsi
je 0x82e3
movq %rax, %r13
movq %r14, %rdi
callq 0x7eea
movq 0x10(%r13), %rdi
movq 0x18(%r13), %rax
movq 0x30(%rax), %rsi
callq 0x73f5
testb %al, %al
jne 0x82e3
movq (%r13), %rdx
movq 0x18(%r13), %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x7dd4
incq %r12
jmp 0x828e
leaq 0x64b4(%rip), %rsi      # 0xe7a3
jmp 0x866a
xorl %r15d, %r15d
movq %r14, %rdi
xorl %esi, %esi
callq 0x731e
movq %rax, 0x30(%rbx)
leaq 0x38(%rbx), %r12
cmpq %r15, 0x48(%rbx)
jbe 0x86d8
movq %r12, %rdi
movq %r15, %rsi
callq 0xc15c
movq (%rax), %rsi
movq %r14, %rdi
callq 0x7eea
incq %r15
jmp 0x8309
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x40(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x40(%rbx), %rdi
movq 0x30(%rdi), %rax
movl 0x20(%rax), %eax
cmpl $0x1, %eax
je 0x8369
cmpl $0x4, %eax
je 0x8369
leaq 0x679e(%rip), %rsi      # 0xeb00
xorl %eax, %eax
callq 0x7dd4
movq 0x38(%rbx), %rdi
movq 0x30(%rdi), %rax
movl 0x20(%rax), %ecx
cmpl $0x7, %ecx
je 0x865d
cmpl $0x5, %ecx
jne 0x8663
pushq $0x3
jmp 0x86cb
movq 0x40(%rbx), %rax
testq %rax, %rax
je 0x8642
movq 0x8(%rax), %rax
jmp 0x86d4
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x38(%rbx), %rax
movq 0x30(%rax), %rax
movl 0x20(%rax), %ecx
cmpl $0x1, %ecx
jne 0x83d7
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8934
movq 0x38(%rbx), %rax
movq 0x30(%rax), %rax
movl 0x20(%rax), %ecx
cmpl $0x1, %ecx
je 0x83fd
cmpl $0x6, %ecx
je 0x83fd
leaq 0x6673(%rip), %rsi      # 0xea5b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7dd4
movq 0x38(%rbx), %rax
movq 0x30(%rax), %rax
movl 0x20(%rax), %ecx
cmpl $0x1, %ecx
je 0x8413
movq 0x50(%rbx), %rdx
movq 0x38(%rax), %rcx
cmpq %rcx, %rdx
jne 0x86e7
leaq 0x40(%rbx), %r15
xorl %r13d, %r13d
cmpq %r13, 0x50(%rbx)
jbe 0x86f8
movq %r15, %rdi
movq %r13, %rsi
callq 0xc15c
movq (%rax), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x7eea
movq 0x38(%rbx), %rax
movq 0x30(%rax), %rdi
cmpl $0x1, 0x20(%rdi)
je 0x847d
addq $0x28, %rdi
movq %r13, %rsi
callq 0xc15c
movq (%rax), %rsi
movq 0x30(%r12), %rdi
callq 0x73f5
testb %al, %al
jne 0x847d
leal 0x1(%r13), %edx
movq %r12, %rdi
leaq 0x6658(%rip), %rsi      # 0xeace
xorl %eax, %eax
callq 0x7dd4
incq %r13
jmp 0x841a
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x731e
movq %rax, 0x30(%rbx)
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x38(%rbx), %rdi
movq 0x30(%rdi), %rax
movl 0x20(%rax), %eax
orl $0x2, %eax
cmpl $0x7, %eax
je 0x86d8
leaq 0x669e(%rip), %rsi      # 0xeb59
jmp 0x866a
movq %r14, %rdi
xorl %esi, %esi
callq 0x731e
movq %rax, 0x30(%rbx)
movq 0x40(%rbx), %rsi
movq %r14, %rdi
callq 0x7eea
movq 0x38(%rbx), %rax
movq 0x40(%rbx), %rcx
movq 0x30(%rcx), %rdi
movq 0x10(%rax), %rax
movq 0x48(%rax), %rsi
callq 0x73f5
testb %al, %al
jne 0x86d8
leaq 0x66bc(%rip), %rsi      # 0xebbe
movq %rbx, %rdi
jmp 0x866a
movq 0x38(%rbx), %rax
movq 0x40(%rbx), %rdx
movq 0x30(%rax), %rax
movq 0x30(%rax), %rsi
movq %r14, %rdi
callq 0x8759
movq %rax, %r14
cmpl $0x4, 0x28(%rbx)
jne 0x853c
leaq 0x62e8(%rip), %rsi      # 0xe81a
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7dd4
testq %r14, %r14
je 0x8717
movq 0x10(%r14), %rax
jmp 0x86d4
movq 0x40(%rbx), %rax
movq 0x30(%rax), %rsi
callq 0x73f5
testb %al, %al
je 0x857c
movq 0x38(%rbx), %rax
movq 0x30(%rax), %rax
movl 0x20(%rax), %eax
cmpl $0x1, %eax
je 0x86b2
cmpl $0x4, %eax
je 0x86b2
movl 0x48(%rbx), %eax
leal -0x2e(%rax), %ecx
cmpl $0x4, %ecx
jb 0x86b5
cltq
movq 0x38(%rbx), %rdi
leaq 0xb6a8(%rip), %rcx      # 0x13c40
movq (%rcx,%rax,8), %rdx
leaq 0x644e(%rip), %rsi      # 0xe9f1
xorl %eax, %eax
callq 0x7dd4
jmp 0x86b2
movq 0x38(%rbx), %rdi
movq 0x30(%rdi), %rax
cmpl $0x4, 0x20(%rax)
je 0x86c9
leaq 0x63cb(%rip), %rsi      # 0xe993
xorl %eax, %eax
callq 0x7dd4
jmp 0x86c9
movq %r15, %rdi
xorl %esi, %esi
callq 0xc15c
movq (%rax), %rax
movq 0x30(%rax), %rax
movq %r12, -0x30(%rbp)
movq %rax, 0x28(%r12)
pushq $0x1
popq %r13
cmpq %r13, 0x50(%rbx)
jbe 0x8706
movq %r15, %rdi
movq %r13, %rsi
callq 0xc15c
movq (%rax), %r12
movq 0x30(%r12), %rdi
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x73f5
incq %r13
testb %al, %al
jne 0x85f2
movq %r12, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x8934
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x731e
movq %rax, %r12
jmp 0x870a
movq 0x38(%rbx), %rsi
movq %r14, %rdi
callq 0x760e
testq %rax, %rax
je 0x8744
movq 0x10(%rax), %rax
jmp 0x86d4
movq 0x28(%rax), %rax
jmp 0x86d4
leaq 0x64c7(%rip), %rsi      # 0xeb31
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7dd4
callq 0x73f5
testb %al, %al
jne 0x86b2
movq 0x38(%rbx), %rdi
leaq 0x6384(%rip), %rsi      # 0xea17
xorl %eax, %eax
callq 0x7dd4
jmp 0x86b2
cmpl $0x5, %edx
jne 0x86b2
movq 0x40(%rcx), %rcx
testq %rcx, %rcx
je 0x86b2
movq 0x30(%rax), %rax
movq %rax, 0x8(%rcx)
movl 0x48(%rbx), %eax
leal -0x2a(%rax), %ecx
cmpl $0x8, %ecx
jae 0x86c1
pushq $0x2
jmp 0x86cb
addl $-0x25, %eax
cmpl $0x4, %eax
ja 0x8710
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x731e
movq %rax, 0x30(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x63a2(%rip), %rsi      # 0xea90
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7dd4
movq 0x38(%rbx), %rax
movq 0x30(%rax), %rax
movq 0x48(%rax), %rax
jmp 0x86d4
movq -0x30(%rbp), %r12
movq %r12, 0x30(%rbx)
jmp 0x86d8
movq %r14, %rdi
xorl %esi, %esi
jmp 0x86cf
movq 0x40(%rbx), %rdx
movq 0x30(%r15), %rcx
leaq 0x613e(%rip), %rsi      # 0xe864
movq %rbx, %rdi
xorl %eax, %eax
callq 0x882a
leaq 0xb509(%rip), %rcx      # 0x13c40
movq (%rcx,%rax,8), %rdx
leaq 0x628b(%rip), %rsi      # 0xe9cd
jmp 0x874f
movq 0x38(%rbx), %rdx
leaq 0x61dd(%rip), %rsi      # 0xe92c
movq %rbx, %rdi
xorl %eax, %eax
callq 0x882a