// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/g_spawn.c
// Function: ReadEntFile
char* ReadEntFile(char* mapname, char* entities)
{
	FILE* fp;

	char	name[MAX_QPATH];
	size_t	size;
	char* tempbuf = NULL;
	int count, ch;
	cvar_t* vs;
	cvar_t* mop;

	if (!deathmatch->value)
		return entities;

	// expose these cvars so we can inspect them
	vs = gi.cvar("version", "", 0);
	mop = gi.cvar("map_override_path", "", 0);
	
	//R1Q2 allows us to modify entities.
	if (strstr(vs->string, "R1Q2") == NULL)
	{
		if(strcmp(mop->string, "") == 0)
			gi.dprintf("LMCTF Error: map_override_path not set for q2pro server.\n");
		return entities;  //Must use q2pro's internal entity management.
	}

	strcpy(name, gamedir->string);
	strcat(name, "/ent/");
	strcat(name, mapname);
	strcat(name, ".ent");

	fp = fopen(name, "rt");
	if (!fp)
		return entities;

	// Prescan to get size we need.
	for (count = 0; (ch = fgetc(fp)) != EOF; count++);
	fseek(fp, 0, SEEK_SET);  //rewind

	if (count >= 0x40000)	//QW// This constant comes from MAX_MAP_ENTSTRING
	{
		gi.dprintf("Error: ent file %s rejected, entity string exceeds game limits.\n", name);
		return entities;
	}

	tempbuf = (char*)gi.TagMalloc(count + 2, TAG_LEVEL);

	if (tempbuf) {
		size = (int)fread(tempbuf, 1, count, fp);
		fclose(fp);

		if (size)
		{
			if ((strncmp(tempbuf, ":append", 7) == 0) && strlen(entities) + count < 0x40000)
			{
				gi.dprintf("Using .ent file for added ents.\n");
				strcat(entities, &tempbuf[8]);
			}
			else
			{
				gi.dprintf("Using .ent file for replaced ents.\n");
				strcpy(entities, tempbuf);
			}
		}
		else
		{
			gi.dprintf("Error: entity file empty.\n");
		}
		gi.TagFree(tempbuf);
	}
	else
	{
		gi.dprintf("Error: unable to allocate memory for entities.\n");
	}

	return entities;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq $0x0, -0x70(%rbp)
movq 0x37ffe(%rip), %rax     # 0x82ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x4aee1
jp 0x4aee1
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4b160
leaq 0x27a3b(%rip), %rdi     # 0x72923
leaq 0x26091(%rip), %rsi     # 0x70f80
xorl %edx, %edx
movq 0x37708(%rip), %rax     # 0x82600
callq *0x120(%rax)
movq %rax, -0x80(%rbp)
leaq 0x2a371(%rip), %rdi     # 0x7527a
leaq 0x26070(%rip), %rsi     # 0x70f80
xorl %edx, %edx
movq 0x376e7(%rip), %rax     # 0x82600
callq *0x120(%rax)
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2a357(%rip), %rsi     # 0x7528c
callq 0x19bf0
cmpq $0x0, %rax
jne 0x4af7c
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x2602e(%rip), %rsi     # 0x70f80
callq 0x18bf0
cmpl $0x0, %eax
jne 0x4af6f
leaq 0x2a32e(%rip), %rdi     # 0x75291
movq 0x37696(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4b160
leaq -0x60(%rbp), %rdi
movq 0x37f29(%rip), %rax     # 0x82eb0
movq (%rax), %rax
movq 0x8(%rax), %rsi
callq 0x182c0
leaq -0x60(%rbp), %rdi
leaq 0x2a2d3(%rip), %rsi     # 0x75271
callq 0x19880
leaq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x19880
leaq -0x60(%rbp), %rdi
leaq 0x26fe9(%rip), %rsi     # 0x71fa4
callq 0x19880
leaq -0x60(%rbp), %rdi
leaq 0x2557d(%rip), %rsi     # 0x70548
callq 0x196a0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x4afe8
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4b160
movl $0x0, -0x74(%rbp)
movq -0x20(%rbp), %rdi
callq 0x18980
movl %eax, -0x78(%rbp)
cmpl $-0x1, %eax
je 0x4b00d
jmp 0x4b002
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x4afef
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x192d0
cmpl $0x40000, -0x74(%rbp)   # imm = 0x40000
jl 0x4b04c
movq 0x375d4(%rip), %rax     # 0x82600
movq 0x8(%rax), %rcx
leaq -0x60(%rbp), %rsi
leaq 0x2a290(%rip), %rdi     # 0x752cb
movb $0x0, %al
callq *%rcx
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4b160
movq 0x375ad(%rip), %rax     # 0x82600
movq 0x108(%rax), %rax
movl -0x74(%rbp), %edi
addl $0x2, %edi
movl $0x2fe, %esi            # imm = 0x2FE
callq *%rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
je 0x4b145
movq -0x70(%rbp), %rdi
movslq -0x74(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x18430
cltq
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rdi
callq 0x18600
cmpq $0x0, -0x68(%rbp)
je 0x4b11c
movq -0x70(%rbp), %rdi
leaq 0x2a25f(%rip), %rsi     # 0x7530c
movl $0x7, %edx
callq 0x18200
cmpl $0x0, %eax
jne 0x4b0fa
movq -0x18(%rbp), %rdi
callq 0x186e0
movslq -0x74(%rbp), %rcx
addq %rcx, %rax
cmpq $0x40000, %rax          # imm = 0x40000
jae 0x4b0fa
leaq 0x2a239(%rip), %rdi     # 0x75314
movq 0x3751e(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rsi
addq $0x8, %rsi
callq 0x19880
jmp 0x4b11a
leaq 0x2a234(%rip), %rdi     # 0x75335
movq 0x374f8(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x182c0
jmp 0x4b12f
leaq 0x2a236(%rip), %rdi     # 0x75359
movq 0x374d6(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
movq 0x374ca(%rip), %rax     # 0x82600
movq 0x110(%rax), %rax
movq -0x70(%rbp), %rdi
callq *%rax
jmp 0x4b158
leaq 0x257cd(%rip), %rdi     # 0x70919
movq 0x374ad(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
movq -0x18(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)