// File: /workspace/github_c_makefile_star2_O2/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 0x3690b(%rip), %rax     # 0x667d8
cmpl $0x7, (%rax)
je 0x2fef3
movq 0x36777(%rip), %rax     # 0x66650
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x2fef3
popq %rbx
popq %r14
popq %r15
jmp 0x18a10
xorl %eax, %eax
callq 0x180d0
callq 0x19bd0
movq 0x36712(%rip), %rax     # 0x66618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
testb $0x20, %al
jne 0x2ff62
movq 0x36ebf(%rip), %r14     # 0x66dd8
cmpl $-0x2, (%r14)
jne 0x2ff7a
movq 0x36e7a(%rip), %r15     # 0x66da0
cmpb $0x0, 0x88(%r15)
je 0x30050
callq 0x198d0
movq %rax, %rbx
leaq 0x1f63f(%rip), %rax     # 0x4f582
movq %rax, 0x138(%rbx)
movl $0x88, %eax
addq 0x36e4a(%rip), %rax     # 0x66da0
movq %rax, 0x270(%rbx)
jmp 0x30043
movq 0x36e37(%rip), %rdi     # 0x66da0
addq $0x48, %rdi
callq 0x19930
movq %rax, %rdi
jmp 0x30046
callq 0x198d0
movq %rax, %rbx
leaq 0x1f5f9(%rip), %rax     # 0x4f582
movq %rax, 0x138(%rbx)
movl (%r14), %eax
movq 0x3697e(%rip), %rcx     # 0x66918
movzwl (%rcx), %edx
pushq $0x20
popq %rsi
movq 0x36e91(%rip), %rdi     # 0x66e38
movq 0x3681a(%rip), %rcx     # 0x667c8
movslq %eax, %r8
cmpw %dx, (%rdi,%r8,2)
jne 0x2ffd9
testl %eax, %eax
js 0x2ffd0
imulq $0x18, %r8, %r9
xorl %r8d, %r8d
cmpq $0x0, (%rcx,%r9)
je 0x2ffcd
movl %eax, %r8d
movl %r8d, %eax
incl %eax
movl %eax, (%r14)
decl %esi
jne 0x2ffae
movq 0x36b78(%rip), %rdx     # 0x66b58
movq (%rdx), %rdx
cvttss2si 0x20(%rdx), %edx
btl $0xc, %edx
jb 0x30017
movslq %eax, %rsi
imulq $0x18, %rsi, %rax
movq (%rcx,%rax), %rdx
movq %rdx, 0x270(%rbx)
movq 0x365f9(%rip), %rcx     # 0x66600
incl %esi
leaq 0x23293(%rip), %rdi     # 0x532a3
xorl %eax, %eax
callq *0x8(%rcx)
jmp 0x30040
callq 0x195f0
movl %eax, %edi
callq 0x186f0
movq (%rax), %rsi
movq %rsi, 0x270(%rbx)
movq 0x365cc(%rip), %rcx     # 0x66600
leaq 0x2329c(%rip), %rdi     # 0x532d7
xorl %eax, %eax
callq *0x8(%rcx)
incl (%r14)
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x18f70
leaq 0x1f52b(%rip), %r14     # 0x4f582
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
movq %r14, %rdx
callq 0x195e0
movq %rax, %rbx
testq %rax, %rax
jne 0x30043
callq 0x198d0
movq %rax, %rbx
movq %r14, 0x138(%rax)
addq $0x48, %r15
movq %r15, 0x270(%rax)
jmp 0x30043