// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/g_menu.c
// Function: SaveServer_Exec
void SaveServer_Exec(edict_t *ent)
{
	FILE	*fp;

	char	name[MAX_INFO_STRING];
	char	text[MAX_INFO_STRING];
	size_t	size;
	char*	tempbuf;
	size_t	i = 0;

	strcpy(name, gamedir->string);
	strcat(name,"/");
	strcat(name, server_file->string);

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

	tempbuf = (char *) gi.TagMalloc(40000, TAG_GAME); //server.cfg files must not exceed 40k arbitrary

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

		if (size > 0 && size < 40000)
		{
			ctf_SafePrint(ent,PRINT_HIGH,"Read server.cfg successfully");
		}
		else
		{
			ctf_SafePrint(ent,PRINT_HIGH,"Failed to read server.cfg");
		}

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

		//dump out the server settings we record
		sprintf(text, "set dmflags %d\n", (int) dmflags->value);
		fwrite(text, 1, strlen(text), fp);
		sprintf(text, "set ctfflags %d\n", (int) ctfflags->value);
		fwrite(text, 1, strlen(text), fp);
		sprintf(text, "set timelimit %d\n", (int) timelimit->value);
		fwrite(text, 1, strlen(text), fp);
		sprintf(text, "set fraglimit %d\n", (int) fraglimit->value);
		fwrite(text, 1, strlen(text), fp);

		//now dump out remainder of file, ignoring the things we dumped out above
		while (i <= size)
		{
			if (
				strncmp(&tempbuf[i], "set dmflags", 11) == 0 || strncmp(&tempbuf[i], "dmflags", 7) == 0 ||
				strncmp(&tempbuf[i], "set ctfflags", 12) == 0 || strncmp(&tempbuf[i], "ctfflags", 8) == 0 ||
				strncmp(&tempbuf[i], "set timelimit", 13) == 0 || strncmp(&tempbuf[i], "timelimit", 9) == 0 ||
				strncmp(&tempbuf[i], "set fraglimit", 13) == 0 || strncmp(&tempbuf[i], "fraglimit", 9) == 0
				)
			{
				while(tempbuf[i] != '\n' && i < size)
					i++;
				i++; //get past that additional \n character
			}
			else
			{
				while(tempbuf[i] != '\n' && i < size)
				{
					fwrite(&tempbuf[i], 1, 1, fp);
					i++;
				}
				fwrite("\n",1,1,fp);
				i++;
			}
		}
		fclose(fp);
		ctf_SafePrint(ent,PRINT_HIGH,"Success: Current server values saved to server.cfg.\n");

	}
	else
	{
		ctf_SafePrint(ent,PRINT_HIGH,"Error: unable to allocate memory for server.cfg read.\n");
	}

	gi.TagFree(tempbuf);
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movq %rdi, -0x8(%rbp)
movq $0x0, -0x428(%rbp)
leaq -0x210(%rbp), %rdi
movq 0x66e58(%rip), %rax     # 0x82eb0
movq (%rax), %rax
movq 0x8(%rax), %rsi
callq 0x182c0
leaq -0x210(%rbp), %rdi
leaq 0x55f30(%rip), %rsi     # 0x71fa2
callq 0x19880
leaq -0x210(%rbp), %rdi
movq 0x668bb(%rip), %rax     # 0x82940
movq (%rax), %rax
movq 0x8(%rax), %rsi
callq 0x19880
leaq -0x210(%rbp), %rdi
leaq 0x531cf(%rip), %rsi     # 0x6f26e
callq 0x196a0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x1c0b4
jmp 0x1c56d
movl $0x9c40, %edi           # imm = 0x9C40
movl $0x2fd, %esi            # imm = 0x2FD
movq 0x6653b(%rip), %rax     # 0x82600
callq *0x108(%rax)
movq %rax, -0x420(%rbp)
cmpq $0x0, -0x420(%rbp)
je 0x1c541
movq -0x420(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %esi
movl $0x9c40, %edx           # imm = 0x9C40
callq 0x18430
movq %rax, -0x418(%rbp)
movq -0x10(%rbp), %rdi
callq 0x18600
cmpq $0x0, -0x418(%rbp)
jbe 0x1c138
cmpq $0x9c40, -0x418(%rbp) # imm = 0x9C40
jae 0x1c138
movq -0x8(%rbp), %rdi
movl $0x2, %esi
leaq 0x53356(%rip), %rdx     # 0x6f487
callq 0x18f20
jmp 0x1c14d
movq -0x8(%rbp), %rdi
movl $0x2, %esi
leaq 0x5335c(%rip), %rdx     # 0x6f4a4
callq 0x18f20
leaq -0x210(%rbp), %rdi
leaq 0x5889c(%rip), %rsi     # 0x749f7
callq 0x196a0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x1c170
jmp 0x1c56d
leaq -0x410(%rbp), %rdi
movq 0x6649a(%rip), %rax     # 0x82618
movq (%rax), %rax
cvttss2si 0x20(%rax), %edx
leaq 0x53331(%rip), %rsi     # 0x6f4be
movb $0x0, %al
callq 0x19940
leaq -0x410(%rbp), %rax
movq %rax, -0x448(%rbp)
leaq -0x410(%rbp), %rdi
callq 0x186e0
movq -0x448(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
movl $0x1, %esi
callq 0x19960
leaq -0x410(%rbp), %rdi
movq 0x66984(%rip), %rax     # 0x82b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %edx
leaq 0x532eb(%rip), %rsi     # 0x6f4ce
movb $0x0, %al
callq 0x19940
leaq -0x410(%rbp), %rax
movq %rax, -0x440(%rbp)
leaq -0x410(%rbp), %rdi
callq 0x186e0
movq -0x440(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
movl $0x1, %esi
callq 0x19960
leaq -0x410(%rbp), %rdi
movq 0x66486(%rip), %rax     # 0x826b0
movq (%rax), %rax
cvttss2si 0x20(%rax), %edx
leaq 0x532a6(%rip), %rsi     # 0x6f4df
movb $0x0, %al
callq 0x19940
leaq -0x410(%rbp), %rax
movq %rax, -0x438(%rbp)
leaq -0x410(%rbp), %rdi
callq 0x186e0
movq -0x438(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
movl $0x1, %esi
callq 0x19960
leaq -0x410(%rbp), %rdi
movq 0x66b80(%rip), %rax     # 0x82e00
movq (%rax), %rax
cvttss2si 0x20(%rax), %edx
leaq 0x53262(%rip), %rsi     # 0x6f4f1
movb $0x0, %al
callq 0x19940
leaq -0x410(%rbp), %rax
movq %rax, -0x430(%rbp)
leaq -0x410(%rbp), %rdi
callq 0x186e0
movq -0x430(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
movl $0x1, %esi
callq 0x19960
movq -0x428(%rbp), %rax
cmpq -0x418(%rbp), %rax
ja 0x1c521
movq -0x420(%rbp), %rdi
addq -0x428(%rbp), %rdi
leaq 0x53212(%rip), %rsi     # 0x6f503
movl $0xb, %edx
callq 0x18200
cmpl $0x0, %eax
je 0x1c40c
movq -0x420(%rbp), %rdi
addq -0x428(%rbp), %rdi
leaq 0x531ee(%rip), %rsi     # 0x6f507
movl $0x7, %edx
callq 0x18200
cmpl $0x0, %eax
je 0x1c40c
movq -0x420(%rbp), %rdi
addq -0x428(%rbp), %rdi
leaq 0x531ce(%rip), %rsi     # 0x6f50f
movl $0xc, %edx
callq 0x18200
cmpl $0x0, %eax
je 0x1c40c
movq -0x420(%rbp), %rdi
addq -0x428(%rbp), %rdi
leaq 0x531aa(%rip), %rsi     # 0x6f513
movl $0x8, %edx
callq 0x18200
cmpl $0x0, %eax
je 0x1c40c
movq -0x420(%rbp), %rdi
addq -0x428(%rbp), %rdi
leaq 0x5318b(%rip), %rsi     # 0x6f51c
movl $0xd, %edx
callq 0x18200
cmpl $0x0, %eax
je 0x1c40c
movq -0x420(%rbp), %rdi
addq -0x428(%rbp), %rdi
leaq 0x5316b(%rip), %rsi     # 0x6f520
movl $0x9, %edx
callq 0x18200
cmpl $0x0, %eax
je 0x1c40c
movq -0x420(%rbp), %rdi
addq -0x428(%rbp), %rdi
leaq 0x53151(%rip), %rsi     # 0x6f52a
movl $0xd, %edx
callq 0x18200
cmpl $0x0, %eax
je 0x1c40c
movq -0x420(%rbp), %rdi
addq -0x428(%rbp), %rdi
leaq 0x53131(%rip), %rsi     # 0x6f52e
movl $0x9, %edx
callq 0x18200
cmpl $0x0, %eax
jne 0x1c47b
jmp 0x1c40e
movq -0x420(%rbp), %rax
movq -0x428(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x449(%rbp)
je 0x1c444
movq -0x428(%rbp), %rax
cmpq -0x418(%rbp), %rax
setb %al
movb %al, -0x449(%rbp)
movb -0x449(%rbp), %al
testb $0x1, %al
jne 0x1c450
jmp 0x1c464
movq -0x428(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x428(%rbp)
jmp 0x1c40e
movq -0x428(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x428(%rbp)
jmp 0x1c51c
jmp 0x1c47d
movq -0x420(%rbp), %rax
movq -0x428(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0xa, %ecx
movb %al, -0x44a(%rbp)
je 0x1c4b3
movq -0x428(%rbp), %rax
cmpq -0x418(%rbp), %rax
setb %al
movb %al, -0x44a(%rbp)
movb -0x44a(%rbp), %al
testb $0x1, %al
jne 0x1c4bf
jmp 0x1c4f2
movq -0x420(%rbp), %rdi
addq -0x428(%rbp), %rdi
movq -0x10(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x19960
movq -0x428(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x428(%rbp)
jmp 0x1c47d
movq -0x10(%rbp), %rcx
leaq 0x54a0b(%rip), %rdi     # 0x70f08
movl $0x1, %edx
movq %rdx, %rsi
callq 0x19960
movq -0x428(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x428(%rbp)
jmp 0x1c2c8
movq -0x10(%rbp), %rdi
callq 0x18600
movq -0x8(%rbp), %rdi
movl $0x2, %esi
leaq 0x52ffe(%rip), %rdx     # 0x6f538
callq 0x18f20
jmp 0x1c556
movq -0x8(%rbp), %rdi
movl $0x2, %esi
leaq 0x5301c(%rip), %rdx     # 0x6f56d
callq 0x18f20
movq 0x660a3(%rip), %rax     # 0x82600
movq 0x110(%rax), %rax
movq -0x420(%rbp), %rdi
callq *%rax
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq
nopw %cs:(%rax,%rax)