// File: /workspace/github_c_makefile_star2_O3/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 0x35df8(%rip), %rax     # 0x687d8
cmpl $0x7, (%rax)
je 0x32a0e
movq 0x35c64(%rip), %rcx     # 0x68650
movq (%rcx), %rcx
movss 0x20(%rcx), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x32a0e
movl $0x5, (%rax)
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x18970
xorl %eax, %eax
callq 0x180d0
callq 0x199f0
movq 0x35bf7(%rip), %rax     # 0x68618
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
testb $0x20, %al
jne 0x32a81
movq 0x363a4(%rip), %r14     # 0x68dd8
cmpl $-0x2, (%r14)
jne 0x32acb
movq 0x3635b(%rip), %r15     # 0x68da0
cmpb $0x0, 0x88(%r15)
je 0x32ba3
callq 0x19700
movq %rax, %rbx
leaq 0x20b20(%rip), %rax     # 0x53582
movq %rax, 0x138(%rbx)
movl $0x88, %eax
addq 0x3632b(%rip), %rax     # 0x68da0
movq %rax, 0x270(%rbx)
jmp 0x32b96
callq 0x19700
movq %rax, %rbx
leaq 0x20af2(%rip), %rax     # 0x53582
movq %rax, 0x138(%rbx)
movq 0x36302(%rip), %rcx     # 0x68da0
leaq 0x88(%rcx), %r14
addq $0x48, %rcx
leaq 0x1fefd(%rip), %rdx     # 0x529ad
movq %r14, %rdi
movl $0x40, %esi
xorl %eax, %eax
callq 0x18e10
movq %r14, 0x270(%rbx)
jmp 0x32b96
callq 0x19700
movq %rax, %rbx
leaq 0x20aa8(%rip), %rax     # 0x53582
movq %rax, 0x138(%rbx)
movl (%r14), %eax
movq 0x35e2d(%rip), %rcx     # 0x68918
movzwl (%rcx), %edx
movl $0x20, %esi
movq 0x3633e(%rip), %rdi     # 0x68e38
movq 0x35cc7(%rip), %rcx     # 0x687c8
movslq %eax, %r8
cmpw %dx, (%rdi,%r8,2)
jne 0x32b2c
testl %eax, %eax
js 0x32b23
leaq (%r8,%r8,2), %r9
xorl %r8d, %r8d
cmpq $0x0, (%rcx,%r9,8)
je 0x32b20
movl %eax, %r8d
movl %r8d, %eax
incl %eax
movl %eax, (%r14)
decl %esi
jne 0x32b01
movq 0x36025(%rip), %rdx     # 0x68b58
movq (%rdx), %rdx
cvttss2si 0x20(%rdx), %edx
btl $0xc, %edx
jb 0x32b6a
movslq %eax, %rsi
leaq (%rsi,%rsi,2), %rax
movq (%rcx,%rax,8), %rdx
movq %rdx, 0x270(%rbx)
movq 0x35aa6(%rip), %rcx     # 0x68600
incl %esi
leaq 0x24760(%rip), %rdi     # 0x572c3
xorl %eax, %eax
callq *0x8(%rcx)
jmp 0x32b93
callq 0x19440
movl %eax, %edi
callq 0x186b0
movq (%rax), %rsi
movq %rsi, 0x270(%rbx)
movq 0x35a79(%rip), %rcx     # 0x68600
leaq 0x24769(%rip), %rdi     # 0x572f7
xorl %eax, %eax
callq *0x8(%rcx)
incl (%r14)
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x18e50
leaq 0x209d8(%rip), %r14     # 0x53582
xorl %edi, %edi
movl $0x138, %esi            # imm = 0x138
movq %r14, %rdx
callq 0x19430
movq %rax, %rbx
testq %rax, %rax
jne 0x32b96
callq 0x19700
movq %rax, %rbx
movq %r14, 0x138(%rax)
addq $0x48, %r15
movq %r15, 0x270(%rax)
jmp 0x32b96