// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/g_ctffunc.c
// Function: ctf_flagtouch
qboolean ctf_flagtouch (edict_t *ent, edict_t *other)
{
	char flagcolor[MAX_INFO_STRING];
	edict_t *otherflag;       //stmt, fixed anyway.
	edict_t	*teammate;
	edict_t *assister = NULL; //surt
	char	sound[MAX_INFO_STRING];
//	int		i;
	static float last_flagtktime = 0;
	long redcount, bluecount, scorebonus;

	char message[1000], elsemessage[1000];
	sound[0] = 0;
	message[0] = 0;
	elsemessage[0] = 0;

	
	ctf_validateflags(); //make sure nothing is wierd

	// Make sure it will respawn
	ent->flags |= FL_RESPAWN;

	if(matchstate >= MATCH_RAILGUN_COUNTDOWN)
		return false;


	if (!ctf_validateplayer(other, CTF_TEAM_ANYTEAM))
		return false; //only active players may touch flag

	strcpy(flagcolor,"");
	ctf_teamstring(flagcolor, ent->flagteam, CTF_TEAM_MATCHING);

	// If it is your flag...
	if (other->client->ctf.teamnum == ent->flagteam)
	{
		// Check to see if the flag is home
//		if (FlagCompare (ent->homeposition, ent->s.origin))
		if (ctf_flagathome(ent))
		{
			// Do we have the enemy flag?
			if (other->client->pers.inventory[ITEM_INDEX(ent->item)])
			{
				//MULTIFLAG: while loop here
				// return OTHER flag to origin
				otherflag = ctf_getteamflag(other->client->ctf.teamnum,CTF_TEAM_OPPOSING);
		
				strcpy(flagcolor, "");
				ctf_teamstring(flagcolor, ent->flagteam, CTF_TEAM_OPPOSING);
				
				// Tell everyone about it
				sprintf(message, "%s captured your flag!\n",
					other->client->pers.netname);
				sprintf(elsemessage, "%s captured the %s flag.\n",
					other->client->pers.netname,
					flagcolor);

				Team_cprint(otherflag->flagteam, message, elsemessage);

				// Award Assists for captures
				assister = ctf_findplayer(NULL, NULL, other->client->ctf.teamnum);  // LM_Hati NULL second argument allows assisting yourself
				while (assister)
				{
					if (level.time < assister->client->kill_carrier_time + 6) //surt was 60 ... (this is seconds, not tenths)
					{
						sprintf(message, "%s assisted the capture by killing the flag carrier.\n",
							assister->client->pers.netname);
						ctf_BSafePrint(PRINT_HIGH, message);

						stats_add(assister, STATS_SCORE, 1);
						assister->client->resp.score += 1;
						assister->client->kill_carrier_time = 0;

						stats_add(assister, STATS_ASSISTS, 1); // STATS - LM_Hati

						// STDLog Flag Capture Frag Carrier - Surt
						sl_LogScore( &gi,
							assister->client->pers.netname,
							NULL,
							"FC Frag Assist",
							NULL,
							1, //FIXME symbolic surt
							level.time );
						
					}
					if (level.time < assister->client->return_flag_time + 3) //surt
					{
						sprintf(message, "%s assisted the capture by returning the flag.\n",
							assister->client->pers.netname);
						ctf_BSafePrint(PRINT_HIGH, message);
						stats_add(assister, STATS_SCORE, 1);
						assister->client->resp.score += 1;
						assister->client->return_flag_time = 0;

						stats_add(assister, STATS_ASSISTS, 1); // STATS - LM_Hati

						// STDLog Flag Capture Return Bonus - Surt
						sl_LogScore( &gi,
							assister->client->pers.netname,
							NULL,
							"F Return Assist",
							NULL,
							1, //bonus frags, should be symbolic, fixme surt
							level.time );

					}
					if	(level.time < assister->client->defend_flag_time + 2) //surt
					{
						sprintf(message, "%s assisted the capture by defending the flag.\n",
							assister->client->pers.netname);
						ctf_BSafePrint(PRINT_HIGH, message);
						stats_add(assister, STATS_SCORE, 1);
						assister->client->resp.score += 1;
						assister->client->defend_flag_time = 0;

						stats_add(assister, STATS_ASSISTS, 1); // STATS - LM_Hati

						// STDLog Flag Capture Defend Bonus - Surt
						sl_LogScore( &gi,
							assister->client->pers.netname,
							NULL,
							"F Defend Assist",
							NULL,
							1, //bonus frags, should be symbolic, fixme surt
							level.time );

					}

					assister = ctf_findplayer(assister, NULL, other->client->ctf.teamnum);
				}


				//gi.sound(ent, CHAN_AUTO, gi.soundindex("misc/tele_up.wav"), 1, ATTN_NORM, 0);	//FIXME capture sound
				
				if (other->client->ctf.teamnum == CTF_TEAM_RED) // Red team
					sprintf(sound, "ctf/redscore%d.wav", (int)(skinset->value)+1);
				else if (other->client->ctf.teamnum == CTF_TEAM_BLUE) // Blue team
					sprintf(sound, "ctf/bluescore%d.wav", (int)(skinset->value)+1);
				else
					strcpy(sound, "misc/tele_up");
					
				gi.sound(ent, CHAN_CTF, gi.soundindex(sound), 1, ATTN_NONE, 0);

				gi.WriteByte (svc_temp_entity);
				gi.WriteByte (TE_BFG_EXPLOSION);
				gi.WritePosition (ent->s.origin);
				gi.multicast (ent->s.origin, MULTICAST_PVS);


				//  Add score to team
				stats_add(other, STATS_SCORE, CTF_CAPTURE_BONUS_CARRIER);
				other->client->resp.score += CTF_CAPTURE_BONUS_CARRIER; //5 for being the actual capturer
				stats_add(other, STATS_CAPTURES, 1);
				// STDLog Flag Capture - Surt
				sl_LogScore( &gi,
					other->client->pers.netname,
					NULL,
					"F Capture",
					NULL,
					CTF_CAPTURE_BONUS_CARRIER,
					level.time );
			
				scorebonus = CTF_CAPTURE_BONUS_TEAM;
				//surt code to give a scoring bonus for a small team capturing vs a large team

				if ( ((int)ctfflags->value) & CTF_SCORE_BALANCE)
				{
					teammate = ctf_findplayer(NULL, NULL, CTF_TEAM_ANYTEAM);
					redcount = bluecount = 1;
					while (teammate != NULL)
					{
						if (teammate->client->ctf.teamnum == CTF_TEAM_RED)
							redcount++;
						else if (teammate->client->ctf.teamnum == CTF_TEAM_BLUE)
							bluecount++;
						teammate = ctf_findplayer(teammate, NULL, CTF_TEAM_ANYTEAM);
					}
					if (other->client->ctf.teamnum == CTF_TEAM_RED)
					{
						scorebonus *= bluecount;
						scorebonus /= redcount;
					}
					else if (other->client->ctf.teamnum == CTF_TEAM_BLUE)
					{
						scorebonus *= redcount;
						scorebonus /= bluecount;
					}
				}



				//surt
				teammate = NULL;
				// MJD Parens are suggested here, but is this
				// correct?
				//surt cleaned up structure
				teammate = ctf_findplayer(NULL, NULL, other->client->ctf.teamnum);
				while (teammate)
				{
					stats_add(teammate, STATS_SCORE, scorebonus);
					teammate->client->resp.score += scorebonus;
					// STDLog Flag Capture Team Score - Surt
					sl_LogScore( &gi,
						teammate->client->pers.netname,
						NULL,
						"Team Score",
						NULL,
						scorebonus,
						level.time );

					teammate = ctf_findplayer(teammate, NULL, other->client->ctf.teamnum);
					
				}

				if (!otherflag)
				{
					ctf_validateflags();
				}
				else
				{
					ctf_resetflagandplayer(otherflag,otherflag->owner);
				}
			}
			return false; // Can't pickup your own flag
		}
		else
		{
			// Return flag to origin
			switch (ent->flagteam)
			{
			case CTF_TEAM_RED:
				gi.sound(ent, CHAN_CTF, gi.soundindex("ctf/r_returned.wav"), 0.8f, ATTN_NONE, 0);	
				break;
			case CTF_TEAM_BLUE: 
				gi.sound(ent, CHAN_CTF, gi.soundindex("ctf/b_returned.wav"), 0.8f, ATTN_NONE, 0);	
				break;
			}

			sprintf(message, "%s returned your flag!\n",
				other->client->pers.netname);
			sprintf(elsemessage, "%s returned the %s flag.\n",
				other->client->pers.netname,
				flagcolor);

			stats_add(other, STATS_RETURNS, 1); // STATS - LM_Hati

			stats_add(other, STATS_SCORE, 1);

        // STDLog Flag Recover - Surt
        sl_LogScore( &gi,
                     other->client->pers.netname,
                     NULL,
                     "F Return",
                     NULL,
                     1, //fixme surt symbolic
                     level.time );

			other->client->resp.score += 1;
			other->client->return_flag_time = level.time;
			
			Team_cprint(other->client->ctf.teamnum, message, elsemessage);

			// Award Assists for returns
			assister = ctf_findplayer(NULL, other, other->client->ctf.teamnum);
			while (assister)
			{
				if (level.time < assister->client->kill_carrier_time + 6) //surt was 60 ... (this is seconds, not tenths)
				{
					sprintf(message, "%s helped %s return the %s flag.\n",
						assister->client->pers.netname, other->client->pers.netname, flagcolor);
					ctf_BSafePrint(PRINT_HIGH, message);
					stats_add(assister, STATS_SCORE, 1);

					// Log Flag Recover - MarkDavies
					sl_LogScore( &gi,
						assister->client->pers.netname,
						NULL,
						"F Return Assist",
						NULL,
						1,
						level.time );

					assister->client->resp.score += 1;
					assister->client->kill_carrier_time = 0;
					
					stats_add(assister, STATS_ASSISTS, 1); // STATS - LM_Hati
				}
				assister = ctf_findplayer(assister, other, other->client->ctf.teamnum);
			}

			ctf_resetflagandplayer(ent,NULL);
			return false;
		}
	}
	else // Enemy flag
	{
		// Can't pick up the flag if it is frozen
//		if (ent->entprops & CTF_PROPS_FROZEN)
//			return false;
		if (ent->flagteam == CTF_TEAM_RED && ((int)refset->value & CTF_RED_FLAG_FROZEN) )
			return false;
		else if (ent->flagteam == CTF_TEAM_BLUE && ((int)refset->value & CTF_BLUE_FLAG_FROZEN) )
			return false;
	
		// Give us a glowing shell
		other->s.effects |= EF_COLOR_SHELL;
		if (ent->flagteam == CTF_TEAM_BLUE)
			other->s.renderfx |= RF_SHELL_RED;
		else if (ent->flagteam == CTF_TEAM_RED)
			other->s.renderfx |= RF_SHELL_BLUE;


		sprintf(message, "%s stole your flag!\n",
			other->client->pers.netname);
		sprintf(elsemessage, "%s stole the %s flag.\n",
			other->client->pers.netname,
			flagcolor);

		stats_add(other, STATS_OFFENSE_FLAG, 1); // STATS - LM_Hati
		// Log Flag Pickup - MarkDavies
		sl_LogScore( &gi,
			other->client->pers.netname,
			NULL,
			"F Pickup",
			NULL,
			0, //surt fixme symbolic
			level.time );
		
		Team_cprint(ent->flagteam, message, elsemessage);
		
		//gi.sound(ent, CHAN_AUTO, gi.soundindex("world/klaxon2.wav"), 1, ATTN_NONE, 0);	//FIXME powering up sound
//		if (FlagCompare (ent->homeposition, ent->s.origin))
		if (ctf_flagathome(ent))
		{
			gi.sound(ent, CHAN_AUTO, gi.soundindex("ctf/flagtk.wav"), 0.7f, ATTN_NORM, 0);	
			switch (ent->flagteam)
			{
			case CTF_TEAM_RED:
				gi.sound(ent, CHAN_CTF, gi.soundindex("ctf/r_stolen.wav"), 0.8f, ATTN_NONE, 0);	
				break;
			case CTF_TEAM_BLUE: 
				gi.sound(ent, CHAN_CTF, gi.soundindex("ctf/b_stolen.wav"), 0.8f, ATTN_NONE, 0);	
				break;
			default:
				break;
			}
		}

		//surt volume was slightly too loud at 1.0
		//so always plays when stolen from home base
		//surt also irritating if dropped/stolen repeatedly
		else
		{
			//only plays every 5 seconds if not at home base
			if (level.time > (last_flagtktime + 8) )
			{
				last_flagtktime = level.time;
				switch (ent->flagteam)
				{
				case CTF_TEAM_RED:
					gi.sound(ent, CHAN_CTF, gi.soundindex("ctf/r_stolen.wav"), 0.8f, ATTN_NORM, 0);	
					break;
				case CTF_TEAM_BLUE: 
					gi.sound(ent, CHAN_CTF, gi.soundindex("ctf/b_stolen.wav"), 0.8f, ATTN_NORM, 0);	
					break;
				default:
					break;
				}
			}
		}

		
		ent->owner = other;
		ent->flags |= FL_RESPAWN;
		//ent->svflags |= SVF_NOCLIENT;
		ent->solid = SOLID_NOT;
		gi.linkentity(ent); //make it touchable

		ent->nextthink = level.time + FRAMETIME;	
		ent->think = ctf_flagwave;

		ent->owner->s.modelindex3 = ent->s.modelindex; // Move mode to player
		ent->s.modelindex = 0; // Turn off model
		
		
		other->client->pers.inventory[ITEM_INDEX(ent->item)]++;
	}

	return true;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xce0, %rsp            # imm = 0xCE0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x238(%rbp)
movb $0x0, -0x440(%rbp)
movb $0x0, -0x840(%rbp)
movb $0x0, -0xc30(%rbp)
callq 0x185f0
movq -0x10(%rbp), %rax
movl 0x11c(%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x11c(%rax)
movq 0x5f203(%rip), %rax     # 0x827d8
cmpl $0x5, (%rax)
jl 0x235e6
movl $0x0, -0x4(%rbp)
jmp 0x24773
movq -0x18(%rbp), %rdi
movl $0xfffffffb, %esi       # imm = 0xFFFFFFFB
callq 0x18e40
cmpl $0x0, %eax
jne 0x23605
movl $0x0, -0x4(%rbp)
jmp 0x24773
leaq -0x220(%rbp), %rdi
leaq 0x4d96d(%rip), %rsi     # 0x70f80
callq 0x182c0
leaq -0x220(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x47c(%rax), %esi
movl $0xfffffff9, %edx       # imm = 0xFFFFFFF9
callq 0x18210
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x47c(%rcx), %eax
jne 0x242b8
movq -0x10(%rbp), %rdi
callq 0x19650
cmpl $0x0, %eax
je 0x23f2e
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0xc38(%rbp)
movq -0x10(%rbp), %rax
movq 0x330(%rax), %rax
movq 0x5f7bc(%rip), %rcx     # 0x82e40
subq %rcx, %rax
movl $0x88, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0xc38(%rbp), %rax
cmpl $0x0, 0x318(%rax,%rcx,4)
je 0x23f22
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %edi
movl $0xfffffffa, %esi       # imm = 0xFFFFFFFA
callq 0x18ef0
movq %rax, -0x228(%rbp)
leaq -0x220(%rbp), %rdi
leaq 0x4d8aa(%rip), %rsi     # 0x70f80
callq 0x182c0
leaq -0x220(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x47c(%rax), %esi
movl $0xfffffffa, %edx       # imm = 0xFFFFFFFA
callq 0x18210
leaq -0x840(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq 0x4ceba(%rip), %rsi     # 0x705d4
movb $0x0, %al
callq 0x19940
leaq -0xc30(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq -0x220(%rbp), %rcx
leaq 0x4cea0(%rip), %rsi     # 0x705ec
movb $0x0, %al
callq 0x19940
movq -0x228(%rbp), %rax
movl 0x47c(%rax), %edi
leaq -0x840(%rbp), %rsi
leaq -0xc30(%rbp), %rdx
callq 0x19b40
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %edx
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x19340
movq %rax, -0x238(%rbp)
cmpq $0x0, -0x238(%rbp)
je 0x23aff
movq 0x5f5f7(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm1
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
movss 0x4c743(%rip), %xmm0    # 0x6ff04
addss 0x10f4(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x238b3
leaq -0x840(%rbp), %rdi
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq 0x4ce0d(%rip), %rsi     # 0x70606
movb $0x0, %al
callq 0x19940
leaq -0x840(%rbp), %rsi
movl $0x2, %edi
callq 0x19470
movq -0x238(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x19550
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
movl 0xdf4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xdf4(%rax)
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x10f4(%rax)
movq -0x238(%rbp), %rdi
movl $0xa, %esi
movl $0x1, %edx
callq 0x19550
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rsi
addq $0xc0, %rsi
addq $0x200, %rsi            # imm = 0x200
movq 0x5f513(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq 0x5ed67(%rip), %rdi     # 0x82600
xorl %eax, %eax
movl %eax, %r8d
leaq 0x4cd97(%rip), %rcx     # 0x7063c
movl $0x1, %r9d
movq %r8, %rdx
callq 0x19010
movq 0x5f4e6(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm1
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
movss 0x4c63e(%rip), %xmm0    # 0x6ff10
addss 0x10f0(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x239c4
leaq -0x840(%rbp), %rdi
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq 0x4cd41(%rip), %rsi     # 0x7064b
movb $0x0, %al
callq 0x19940
leaq -0x840(%rbp), %rsi
movl $0x2, %edi
callq 0x19470
movq -0x238(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x19550
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
movl 0xdf4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xdf4(%rax)
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x10f0(%rax)
movq -0x238(%rbp), %rdi
movl $0xa, %esi
movl $0x1, %edx
callq 0x19550
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rsi
addq $0xc0, %rsi
addq $0x200, %rsi            # imm = 0x200
movq 0x5f402(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq 0x5ec56(%rip), %rdi     # 0x82600
xorl %eax, %eax
movl %eax, %r8d
leaq 0x4ccc5(%rip), %rcx     # 0x7067b
movl $0x1, %r9d
movq %r8, %rdx
callq 0x19010
movq 0x5f3d5(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm1
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
movss 0x4c505(%rip), %xmm0    # 0x6fee8
addss 0x10ec(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x23ad5
leaq -0x840(%rbp), %rdi
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq 0x4cc70(%rip), %rsi     # 0x7068b
movb $0x0, %al
callq 0x19940
leaq -0x840(%rbp), %rsi
movl $0x2, %edi
callq 0x19470
movq -0x238(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x19550
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
movl 0xdf4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xdf4(%rax)
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x10ec(%rax)
movq -0x238(%rbp), %rdi
movl $0xa, %esi
movl $0x1, %edx
callq 0x19550
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rsi
addq $0xc0, %rsi
addq $0x200, %rsi            # imm = 0x200
movq 0x5f2f1(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq 0x5eb45(%rip), %rdi     # 0x82600
xorl %eax, %eax
movl %eax, %r8d
leaq 0x4cbf4(%rip), %rcx     # 0x706bb
movl $0x1, %r9d
movq %r8, %rdx
callq 0x19010
movq -0x238(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %edx
xorl %eax, %eax
movl %eax, %esi
callq 0x19340
movq %rax, -0x238(%rbp)
jmp 0x23794
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x1, 0x1100(%rax)
jne 0x23b39
leaq -0x440(%rbp), %rdi
movq 0x5edda(%rip), %rax     # 0x828f8
movq (%rax), %rax
cvttss2si 0x20(%rax), %edx
addl $0x1, %edx
leaq 0x4cb9b(%rip), %rsi     # 0x706cb
movb $0x0, %al
callq 0x19940
jmp 0x23b88
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x2, 0x1100(%rax)
jne 0x23b73
leaq -0x440(%rbp), %rdi
movq 0x5eda0(%rip), %rax     # 0x828f8
movq (%rax), %rax
cvttss2si 0x20(%rax), %edx
addl $0x1, %edx
leaq 0x4cb74(%rip), %rsi     # 0x706de
movb $0x0, %al
callq 0x19940
jmp 0x23b86
leaq -0x440(%rbp), %rdi
leaq 0x4cb71(%rip), %rsi     # 0x706f2
callq 0x182c0
jmp 0x23b88
movq 0x5ea71(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0xc40(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc48(%rbp)
movq 0x5ea54(%rip), %rax     # 0x82600
movq 0x48(%rax), %rax
leaq -0x440(%rbp), %rdi
callq *%rax
movq -0xc48(%rbp), %rdi
movl %eax, %edx
movq -0xc40(%rbp), %rax
movl $0x5, %esi
movss 0x4c316(%rip), %xmm0    # 0x6feec
xorps %xmm2, %xmm2
movaps %xmm2, %xmm1
callq *%rax
movl $0x3, %edi
movq 0x5ea16(%rip), %rax     # 0x82600
callq *0xc8(%rax)
movl $0x14, %edi
movq 0x5ea04(%rip), %rax     # 0x82600
callq *0xc8(%rax)
movq 0x5e9f7(%rip), %rax     # 0x82600
movq 0xf0(%rax), %rax
movq -0x10(%rbp), %rdi
addq $0x4, %rdi
callq *%rax
movq 0x5e9df(%rip), %rax     # 0x82600
movq 0xb0(%rax), %rax
movq -0x10(%rbp), %rdi
addq $0x4, %rdi
movl $0x2, %esi
callq *%rax
movq -0x18(%rbp), %rdi
movl $0x3, %esi
movl $0x5, %edx
callq 0x19550
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0xdf4(%rax), %ecx
addl $0x5, %ecx
movl %ecx, 0xdf4(%rax)
movq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x19550
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rsi
addq $0xc0, %rsi
addq $0x200, %rsi            # imm = 0x200
movq 0x5f10f(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq 0x5e963(%rip), %rdi     # 0x82600
xorl %eax, %eax
movl %eax, %r8d
leaq 0x4ca56(%rip), %rcx     # 0x706ff
movl $0x5, %r9d
movq %r8, %rdx
callq 0x19010
movq $0xa, -0x458(%rbp)
movq 0x5ee8f(%rip), %rax     # 0x82b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x23e0d
xorl %eax, %eax
movl %eax, %esi
movl $0xfffffffb, %edx       # imm = 0xFFFFFFFB
movq %rsi, %rdi
callq 0x19340
movq %rax, -0x230(%rbp)
movq $0x1, -0x450(%rbp)
movq $0x1, -0x448(%rbp)
cmpq $0x0, -0x230(%rbp)
je 0x23d85
movq -0x230(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x1, 0x1100(%rax)
jne 0x23d3f
movq -0x448(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x448(%rbp)
jmp 0x23d67
movq -0x230(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x2, 0x1100(%rax)
jne 0x23d65
movq -0x450(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x450(%rbp)
jmp 0x23d67
movq -0x230(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xfffffffb, %edx       # imm = 0xFFFFFFFB
callq 0x19340
movq %rax, -0x230(%rbp)
jmp 0x23d0d
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x1, 0x1100(%rax)
jne 0x23dc8
movq -0x450(%rbp), %rax
imulq -0x458(%rbp), %rax
movq %rax, -0x458(%rbp)
movq -0x448(%rbp), %rcx
movq -0x458(%rbp), %rax
cqto
idivq %rcx
movq %rax, -0x458(%rbp)
jmp 0x23e0b
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x2, 0x1100(%rax)
jne 0x23e09
movq -0x448(%rbp), %rax
imulq -0x458(%rbp), %rax
movq %rax, -0x458(%rbp)
movq -0x450(%rbp), %rcx
movq -0x458(%rbp), %rax
cqto
idivq %rcx
movq %rax, -0x458(%rbp)
jmp 0x23e0b
jmp 0x23e0d
movq $0x0, -0x230(%rbp)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %edx
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x19340
movq %rax, -0x230(%rbp)
cmpq $0x0, -0x230(%rbp)
je 0x23ef5
movq -0x230(%rbp), %rdi
movq -0x458(%rbp), %rdx
movl $0x3, %esi
callq 0x19550
movq -0x458(%rbp), %rdx
movq -0x230(%rbp), %rax
movq 0x58(%rax), %rax
movslq 0xdf4(%rax), %rcx
addq %rdx, %rcx
movl %ecx, 0xdf4(%rax)
movq -0x230(%rbp), %rax
movq 0x58(%rax), %rsi
addq $0xc0, %rsi
addq $0x200, %rsi            # imm = 0x200
movq -0x458(%rbp), %rax
movl %eax, %r9d
movq 0x5eef5(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq 0x5e749(%rip), %rdi     # 0x82600
xorl %eax, %eax
movl %eax, %r8d
leaq 0x4c846(%rip), %rcx     # 0x70709
movq %r8, %rdx
callq 0x19010
movq -0x230(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %edx
xorl %eax, %eax
movl %eax, %esi
callq 0x19340
movq %rax, -0x230(%rbp)
jmp 0x23e39
cmpq $0x0, -0x228(%rbp)
jne 0x23f06
callq 0x185f0
jmp 0x23f20
movq -0x228(%rbp), %rdi
movq -0x228(%rbp), %rax
movq 0x110(%rax), %rsi
callq 0x19240
jmp 0x23f22
movl $0x0, -0x4(%rbp)
jmp 0x24773
movq -0x10(%rbp), %rax
movl 0x47c(%rax), %eax
movl %eax, -0xc4c(%rbp)
subl $0x1, %eax
je 0x23f55
jmp 0x23f45
movl -0xc4c(%rbp), %eax
subl $0x2, %eax
je 0x23faa
jmp 0x23ffd
movq 0x5e6a4(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0xc58(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc60(%rbp)
leaq 0x4c613(%rip), %rdi     # 0x7058c
movq 0x5e680(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0xc60(%rbp), %rdi
movl %eax, %edx
movq -0xc58(%rbp), %rax
movl $0x5, %esi
movss 0x4c4e0(%rip), %xmm0    # 0x70480
xorps %xmm2, %xmm2
movaps %xmm2, %xmm1
callq *%rax
jmp 0x23ffd
movq 0x5e64f(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0xc68(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc70(%rbp)
leaq 0x4c5d1(%rip), %rdi     # 0x7059f
movq 0x5e62b(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0xc70(%rbp), %rdi
movl %eax, %edx
movq -0xc68(%rbp), %rax
movl $0x5, %esi
movss 0x4c48b(%rip), %xmm0    # 0x70480
xorps %xmm2, %xmm2
movaps %xmm2, %xmm1
callq *%rax
leaq -0x840(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq 0x4c6f3(%rip), %rsi     # 0x70714
movb $0x0, %al
callq 0x19940
leaq -0xc30(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq -0x220(%rbp), %rcx
leaq 0x4c6d9(%rip), %rsi     # 0x7072c
movb $0x0, %al
callq 0x19940
movq -0x18(%rbp), %rdi
movl $0xb, %esi
movl $0x1, %edx
callq 0x19550
movq -0x18(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x19550
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rsi
addq $0xc0, %rsi
addq $0x200, %rsi            # imm = 0x200
movq 0x5ed03(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq 0x5e557(%rip), %rdi     # 0x82600
xorl %eax, %eax
movl %eax, %r8d
leaq 0x4c691(%rip), %rcx     # 0x70746
movl $0x1, %r9d
movq %r8, %rdx
callq 0x19010
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0xdf4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xdf4(%rax)
movq 0x5ecbf(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movss %xmm0, 0x10f0(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %edi
leaq -0x840(%rbp), %rsi
leaq -0xc30(%rbp), %rdx
callq 0x19b40
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %edx
xorl %eax, %eax
movl %eax, %edi
callq 0x19340
movq %rax, -0x238(%rbp)
cmpq $0x0, -0x238(%rbp)
je 0x2429f
movq 0x5ec52(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm1
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
movss 0x4bd9e(%rip), %xmm0    # 0x6ff04
addss 0x10f4(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x24275
leaq -0x840(%rbp), %rdi
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rcx
addq $0xc0, %rcx
addq $0x200, %rcx            # imm = 0x200
leaq -0x220(%rbp), %r8
leaq 0x4c594(%rip), %rsi     # 0x7074f
movb $0x0, %al
callq 0x19940
leaq -0x840(%rbp), %rsi
movl $0x2, %edi
callq 0x19470
movq -0x238(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x19550
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rsi
addq $0xc0, %rsi
addq $0x200, %rsi            # imm = 0x200
movq 0x5eb97(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq 0x5e3eb(%rip), %rdi     # 0x82600
xorl %eax, %eax
movl %eax, %r8d
leaq 0x4c45a(%rip), %rcx     # 0x7067b
movl $0x1, %r9d
movq %r8, %rdx
callq 0x19010
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
movl 0xdf4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xdf4(%rax)
movq -0x238(%rbp), %rax
movq 0x58(%rax), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x10f4(%rax)
movq -0x238(%rbp), %rdi
movl $0xa, %esi
movl $0x1, %edx
callq 0x19550
movq -0x238(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %edx
callq 0x19340
movq %rax, -0x238(%rbp)
jmp 0x24139
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x19240
movl $0x0, -0x4(%rbp)
jmp 0x24773
movq -0x10(%rbp), %rax
cmpl $0x1, 0x47c(%rax)
jne 0x242e8
movq 0x5e6cc(%rip), %rax     # 0x82998
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x242e8
movl $0x0, -0x4(%rbp)
jmp 0x24773
movq -0x10(%rbp), %rax
cmpl $0x2, 0x47c(%rax)
jne 0x24318
movq 0x5e69c(%rip), %rax     # 0x82998
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x24318
movl $0x0, -0x4(%rbp)
jmp 0x24773
jmp 0x2431a
movq -0x18(%rbp), %rax
movl 0x40(%rax), %ecx
orl $0x100, %ecx            # imm = 0x100
movl %ecx, 0x40(%rax)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x47c(%rax)
jne 0x24349
movq -0x18(%rbp), %rax
movl 0x44(%rax), %ecx
orl $0x400, %ecx            # imm = 0x400
movl %ecx, 0x44(%rax)
jmp 0x24368
movq -0x10(%rbp), %rax
cmpl $0x1, 0x47c(%rax)
jne 0x24366
movq -0x18(%rbp), %rax
movl 0x44(%rax), %ecx
orl $0x1000, %ecx           # imm = 0x1000
movl %ecx, 0x44(%rax)
jmp 0x24368
leaq -0x840(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq 0x4c3e5(%rip), %rsi     # 0x70771
movb $0x0, %al
callq 0x19940
leaq -0xc30(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
leaq -0x220(%rbp), %rcx
leaq 0x4c3c8(%rip), %rsi     # 0x70786
movb $0x0, %al
callq 0x19940
movq -0x18(%rbp), %rdi
movl $0xc, %esi
movl $0x1, %edx
callq 0x19550
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rsi
addq $0xc0, %rsi
addq $0x200, %rsi            # imm = 0x200
movq 0x5e9ab(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq 0x5e1ff(%rip), %rdi     # 0x82600
xorl %eax, %eax
movl %eax, %r8d
leaq 0x4c390(%rip), %rcx     # 0x7079d
xorl %r9d, %r9d
movq %r8, %rdx
callq 0x19010
movq -0x10(%rbp), %rax
movl 0x47c(%rax), %edi
leaq -0x840(%rbp), %rsi
leaq -0xc30(%rbp), %rdx
callq 0x19b40
movq -0x10(%rbp), %rdi
callq 0x19650
cmpl $0x0, %eax
je 0x24570
movq 0x5e1b2(%rip), %rax     # 0x82600
movq -0x10(%rbp), %rcx
movq %rcx, -0xc88(%rbp)
movq 0x20(%rax), %rcx
movq %rcx, -0xc80(%rbp)
movq 0x48(%rax), %rax
leaq 0x4c337(%rip), %rdi     # 0x707a6
callq *%rax
movq -0xc88(%rbp), %rdi
movl %eax, %edx
movq -0xc80(%rbp), %rax
xorl %esi, %esi
movss 0x4c005(%rip), %xmm0    # 0x70490
movss 0x4ba59(%rip), %xmm1    # 0x6feec
xorps %xmm2, %xmm2
callq *%rax
movq -0x10(%rbp), %rax
movl 0x47c(%rax), %eax
movl %eax, -0xc74(%rbp)
subl $0x1, %eax
je 0x244bf
jmp 0x244af
movl -0xc74(%rbp), %eax
subl $0x2, %eax
je 0x24514
jmp 0x24569
movq 0x5e13a(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0xc90(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc98(%rbp)
leaq 0x4c2d2(%rip), %rdi     # 0x707b5
movq 0x5e116(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0xc98(%rbp), %rdi
movl %eax, %edx
movq -0xc90(%rbp), %rax
movl $0x5, %esi
movss 0x4bf76(%rip), %xmm0    # 0x70480
xorps %xmm2, %xmm2
movaps %xmm2, %xmm1
callq *%rax
jmp 0x2456b
movq 0x5e0e5(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0xca0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xca8(%rbp)
leaq 0x4c28e(%rip), %rdi     # 0x707c6
movq 0x5e0c1(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0xca8(%rbp), %rdi
movl %eax, %edx
movq -0xca0(%rbp), %rax
movl $0x5, %esi
movss 0x4bf21(%rip), %xmm0    # 0x70480
xorps %xmm2, %xmm2
movaps %xmm2, %xmm1
callq *%rax
jmp 0x2456b
jmp 0x2456b
jmp 0x2468a
movq 0x5e829(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movss 0x4b978(%rip), %xmm1    # 0x6fefc
addss 0x63c54(%rip), %xmm1    # 0x881e0
ucomiss %xmm1, %xmm0
jbe 0x24688
movq 0x5e804(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movss %xmm0, 0x63c37(%rip)    # 0x881e0
movq -0x10(%rbp), %rax
movl 0x47c(%rax), %eax
movl %eax, -0xcac(%rbp)
subl $0x1, %eax
je 0x245d0
jmp 0x245c0
movl -0xcac(%rbp), %eax
subl $0x2, %eax
je 0x2462a
jmp 0x24684
movq 0x5e029(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0xcb8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xcc0(%rbp)
leaq 0x4c1c1(%rip), %rdi     # 0x707b5
movq 0x5e005(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0xcc0(%rbp), %rdi
movl %eax, %edx
movq -0xcb8(%rbp), %rax
movl $0x5, %esi
movss 0x4be65(%rip), %xmm0    # 0x70480
movss 0x4b8c9(%rip), %xmm1    # 0x6feec
xorps %xmm2, %xmm2
callq *%rax
jmp 0x24686
movq 0x5dfcf(%rip), %rax     # 0x82600
movq 0x20(%rax), %rax
movq %rax, -0xcc8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xcd0(%rbp)
leaq 0x4c178(%rip), %rdi     # 0x707c6
movq 0x5dfab(%rip), %rax     # 0x82600
callq *0x48(%rax)
movq -0xcd0(%rbp), %rdi
movl %eax, %edx
movq -0xcc8(%rbp), %rax
movl $0x5, %esi
movss 0x4be0b(%rip), %xmm0    # 0x70480
movss 0x4b86f(%rip), %xmm1    # 0x6feec
xorps %xmm2, %xmm2
callq *%rax
jmp 0x24686
jmp 0x24686
jmp 0x24688
jmp 0x2468a
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x110(%rax)
movq -0x10(%rbp), %rax
movl 0x11c(%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x11c(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x108(%rax)
movq 0x5df3c(%rip), %rax     # 0x82600
movq 0x90(%rax), %rax
movq -0x10(%rbp), %rdi
callq *%rax
movss 0x4bbbb(%rip), %xmm0    # 0x70294
movq 0x5e6c0(%rip), %rax     # 0x82da0
addss 0x4(%rax), %xmm0
movq -0x10(%rbp), %rax
movss %xmm0, 0x200(%rax)
movq -0x10(%rbp), %rax
movq 0x5dec4(%rip), %rcx     # 0x825c0
movq %rcx, 0x210(%rax)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x110(%rax), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0xcd8(%rbp)
movq -0x10(%rbp), %rax
movq 0x330(%rax), %rax
movq 0x5e6fc(%rip), %rcx     # 0x82e40
subq %rcx, %rax
movl $0x88, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0xcd8(%rbp), %rax
movl 0x318(%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, 0x318(%rax,%rcx,4)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xce0, %rsp            # imm = 0xCE0
popq %rbp
retq
nop