// File: /workspace/github_c_makefile_star2_O1/QwazyWabbitWOS[P]lmctf60/g_main.c
// Function: EndDMLevel
void EndDMLevel (void)
{
edict_t		*ent;
int map_count = 0;


	if((matchstate != MATCH_RAILGUN_OVER) && (railtime->value > 0))
	{
		Set_Mode_Railgun_Shootout();
		return;
	}

	KillMatch();
	Write_Highscore_Table();


	// stay on same level flag
	if ((int)dmflags->value & DF_SAME_LEVEL)
	{
		BeginIntermission (CreateTargetChangeLevel (level.mapname) );
		return;
	}

	// CTF CODE -- LM_JORM
	else if (maplistindex != -2) // -2 means no list
	{	// go to a specific map
		ent = G_Spawn ();
		ent->classname = "target_changelevel";
		
		//bat
		while(Maps_Picked[maplistindex] == Last_Map)
		{
			if(maplistindex > -1 && !maplist[maplistindex].mapname) // Did we reach the end of the list?
				maplistindex = 0;

			maplistindex++;

			//if all the maps are the same, this is a precaution.
			if(map_count++ > 30)
				break;
		}

		if((int)ctfflags->value & CTF_RANDOM_MAPS)
		{
			MapInfo *map = getRandomMapByPlayerCount(playerCount());
			ent->map = map->mapname;
			gi.dprintf("Map :  %s\n",  map->mapname);
		}
		else
		{
			ent->map = maplist[maplistindex].mapname;
			gi.dprintf("Map #%d:  %s\n", maplistindex+1, maplist[maplistindex].mapname);
		}

		maplistindex++; 
	}
	// END CTF CODE -- LM_JORM

	else if (level.nextmap[0])
	{	// go to a specific map
		ent = G_Spawn ();
		ent->classname = "target_changelevel";
		ent->map = level.nextmap;
	}
	else
	{	// search for a changeleve
		ent = G_Find (NULL, FOFS(classname), "target_changelevel");
		if (!ent)
		{	// the map designer didn't include a changelevel,
			// so create a fake ent that goes back to the same level
			ent = G_Spawn ();
			ent->classname = "target_changelevel";
			ent->map = level.mapname;
		}
	}
	

	BeginIntermission (ent);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq 0x36896(%rip), %rax     # 0x697d8
cmpl $0x7, (%rax)
je 0x32f70
movq 0x36702(%rip), %rcx     # 0x69650
movq (%rcx), %rcx
movss 0x20(%rcx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x32f70
movl $0x5, (%rax)
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x18970
xorl %eax, %eax
callq 0x180d0
callq 0x19a00
movq 0x36695(%rip), %rax     # 0x69618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
testb $0x20, %al
jne 0x32fe3
movq 0x36e42(%rip), %r14     # 0x69dd8
cmpl $-0x2, (%r14)
jne 0x3302d
movq 0x36df9(%rip), %r15     # 0x69da0
cmpb $0x0, 0x88(%r15)
je 0x33107
callq 0x19710
movq %rax, %rbx
leaq 0x2158e(%rip), %rax     # 0x54552
movq %rax, 0x138(%rbx)
movl $0x88, %eax
addq 0x36dc9(%rip), %rax     # 0x69da0
movq %rax, 0x270(%rbx)
jmp 0x330fa
callq 0x19710
movq %rax, %rbx
leaq 0x21560(%rip), %rax     # 0x54552
movq %rax, 0x138(%rbx)
movq 0x36da0(%rip), %rcx     # 0x69da0
leaq 0x88(%rcx), %r14
addq $0x48, %rcx
leaq 0x2099b(%rip), %rdx     # 0x539ad
movq %r14, %rdi
movl $0x40, %esi
xorl %eax, %eax
callq 0x18e10
movq %r14, 0x270(%rbx)
jmp 0x330fa
callq 0x19710
movq %rax, %rbx
leaq 0x21516(%rip), %rax     # 0x54552
movq %rax, 0x138(%rbx)
movq 0x368ce(%rip), %rax     # 0x69918
movzwl (%rax), %ecx
movl (%r14), %edi
movl $0x20, %edx
movq 0x36ddc(%rip), %rsi     # 0x69e38
movq 0x36765(%rip), %rax     # 0x697c8
movslq %edi, %r8
cmpw %cx, (%rsi,%r8,2)
jne 0x3308e
testl %edi, %edi
js 0x33085
leaq (%r8,%r8,2), %r8
cmpq $0x0, (%rax,%r8,8)
jne 0x33085
movl $0x0, (%r14)
xorl %edi, %edi
incl %edi
movl %edi, (%r14)
decl %edx
jne 0x33063
movq 0x36ac3(%rip), %rcx     # 0x69b58
movq (%rcx), %rcx
cvttss2si 0x20(%rcx), %ecx
btl $0xc, %ecx
jb 0x330ce
movslq (%r14), %rcx
leaq (%rcx,%rcx,2), %rdx
movq (%rax,%rdx,8), %rdx
movq %rdx, 0x270(%rbx)
movq 0x36544(%rip), %r8      # 0x69600
leal 0x1(%rcx), %esi
leaq 0x25104(%rip), %rdi     # 0x581ca
xorl %eax, %eax
callq *0x8(%r8)
jmp 0x330f7
callq 0x19440
movl %eax, %edi
callq 0x186b0
movq (%rax), %rsi
movq %rsi, 0x270(%rbx)
movq 0x36515(%rip), %rcx     # 0x69600
leaq 0x2510c(%rip), %rdi     # 0x581fe
xorl %eax, %eax
callq *0x8(%rcx)
incl (%r14)
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x18e50
leaq 0x21444(%rip), %r14     # 0x54552
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
movq %r14, %rdx
callq 0x19430
movq %rax, %rbx
testq %rax, %rax
jne 0x330fa
callq 0x19710
movq %rax, %rbx
movq %r14, 0x138(%rax)
addq $0x48, %r15
movq %r15, 0x270(%rax)
jmp 0x330fa