// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/g_skins.c
// Function: SkinsReadFile
void SkinsReadFile()
{
	FILE	*fp;

	char	name[MAX_INFO_STRING], *newb = NULL;
	size_t	size;
	char    *tempbuf;
	char	line[MAX_INFO_STRING] = { 0 };
	int		colorindex;
	char	skin[MAX_INFO_STRING] = { 0 };
	char	model[MAX_INFO_STRING] = { 0 };
	int		red, blue;
	int		count, ch;

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

	
	// Open the skins file
	fp = fopen (name, "rt");
	if (!fp)
		return;

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

	// Read the whole skins file and place it in a spot of memory
	
	tempbuf = (char *) gi.TagMalloc(count + 2, TAG_GAME);
	if (tempbuf)
	{
		size = fread(tempbuf, 1, count, fp);
		fclose(fp);

		if (size)
		{
			newb = tempbuf;
			newb[size] = 0;
		}
		else
		{
			if (size >= (size_t)count + 1)
				gi.dprintf("Error: skins file truncated.\n");
			else
				gi.dprintf("Error: skins file empty.\n");
			return;
		}

	}
	else
	{
		gi.dprintf("Error: unable to allocate memory for entities.\n");
		return;
	}

	// Parse our input
	// One list of red skins, one of blue
	// Each list contains model and skin name
	
	red = blue = 0;
	skinlist[SKIN_RED][red][SKIN_MODELNAME] = NULL;
	skinlist[SKIN_RED][red][SKIN_SKINNAME] = NULL;
	skinlist[SKIN_BLUE][blue][SKIN_MODELNAME] = NULL;
	skinlist[SKIN_BLUE][blue][SKIN_SKINNAME] = NULL;

	if (!newb)
		return; // No valid file

	skinlistinuse = true;
	colorindex = SKIN_RED;

	while (tempbuf - newb < (ptrdiff_t)size && sscanf(tempbuf,"%[^\n]", line))
	{
		tempbuf += strlen(line);
		
		// Step over newline
		while (*tempbuf == '\n')
			tempbuf++;

		// Ignore lines with # or / or ;
		if (line[0] == '#' || line[0] == '/' || line[0] == ';')
			continue;

		// Determine which skinset we are dealing with
		if (!strcmp(line, "[red]"))
			colorindex = SKIN_RED;
		if (!strcmp(line, "[blue]"))
			colorindex = SKIN_BLUE;

		// If it is a skin, add it to the list
		if (strlen(line) && sscanf(line, "%[^/]/%s", model, skin) == 2)
		{
			// Add to the red list?
			if (colorindex == SKIN_RED)
			{
				skinlist[SKIN_RED][red][SKIN_MODELNAME] = CopyString(model);
				skinlist[SKIN_RED][red][SKIN_SKINNAME] = CopyString(skin);
				red++;
				skinlist[SKIN_RED][red][SKIN_MODELNAME] = NULL;
				skinlist[SKIN_RED][red][SKIN_SKINNAME] = NULL;
			}
			else if (colorindex == SKIN_BLUE)
			{
				skinlist[SKIN_BLUE][blue][SKIN_MODELNAME] = CopyString(model);
				skinlist[SKIN_BLUE][blue][SKIN_SKINNAME] = CopyString(skin);
				blue++;
				skinlist[SKIN_BLUE][blue][SKIN_MODELNAME] = NULL;
				skinlist[SKIN_BLUE][blue][SKIN_SKINNAME] = NULL;
			}

		}
	}

	// Free the memory
	gi.TagFree(newb);

	if (skin_debug->value)
	{
		red = 0;
		gi.dprintf("[red]\n");
		while (skinlist[SKIN_RED][red][SKIN_MODELNAME])
		{
			gi.dprintf("MODEL: [%s]  SKIN: [%s]\n",
				skinlist[SKIN_RED][red][SKIN_MODELNAME],
				skinlist[SKIN_RED][red][SKIN_SKINNAME]);
			red++;
		}
		red = 0;
		gi.dprintf("\n[blue]\n");
		while (skinlist[SKIN_BLUE][red][SKIN_MODELNAME])
		{
			gi.dprintf("MODEL: [%s]  SKIN: [%s]\n",
				skinlist[SKIN_BLUE][red][SKIN_MODELNAME],
				skinlist[SKIN_BLUE][red][SKIN_SKINNAME]);
			red++;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x860, %rsp            # imm = 0x860
movq $0x0, -0x218(%rbp)
leaq -0x430(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x188f0
leaq -0x640(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x188f0
leaq -0x840(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x188f0
leaq -0x210(%rbp), %rdi
movq 0x5d8d3(%rip), %rax     # 0x82eb0
movq (%rax), %rax
movq 0x8(%rax), %rsi
callq 0x182c0
leaq -0x210(%rbp), %rdi
leaq 0x4c9ab(%rip), %rsi     # 0x71fa2
callq 0x19880
leaq -0x210(%rbp), %rdi
movq 0x5d08e(%rip), %rax     # 0x82698
movq (%rax), %rax
movq 0x8(%rax), %rsi
callq 0x19880
leaq -0x210(%rbp), %rdi
leaq 0x4af24(%rip), %rsi     # 0x70548
callq 0x196a0
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x25639
jmp 0x25c39
movl $0x0, -0x84c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x18980
movl %eax, -0x850(%rbp)
cmpl $-0x1, %eax
je 0x2566a
jmp 0x25659
movl -0x84c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84c(%rbp)
jmp 0x25643
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x192d0
movq 0x5cf80(%rip), %rax     # 0x82600
movq 0x108(%rax), %rax
movl -0x84c(%rbp), %edi
addl $0x2, %edi
movl $0x2fd, %esi            # imm = 0x2FD
callq *%rax
movq %rax, -0x228(%rbp)
cmpq $0x0, -0x228(%rbp)
je 0x2574a
movq -0x228(%rbp), %rdi
movslq -0x84c(%rbp), %rdx
movq -0x8(%rbp), %rcx
movl $0x1, %esi
callq 0x18430
movq %rax, -0x220(%rbp)
movq -0x8(%rbp), %rdi
callq 0x18600
cmpq $0x0, -0x220(%rbp)
je 0x25704
movq -0x228(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x218(%rbp), %rax
movq -0x220(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x25748
movq -0x220(%rbp), %rax
movslq -0x84c(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jb 0x25730
leaq 0x4b1bf(%rip), %rdi     # 0x708e1
movq 0x5ced7(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
jmp 0x25743
leaq 0x4b1c8(%rip), %rdi     # 0x708ff
movq 0x5cec2(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
jmp 0x25c39
jmp 0x25762
leaq 0x4b1c8(%rip), %rdi     # 0x70919
movq 0x5cea8(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
jmp 0x25c39
movl $0x0, -0x848(%rbp)
movl $0x0, -0x844(%rbp)
movslq -0x844(%rbp), %rcx
movq 0x5cdf4(%rip), %rax     # 0x82578
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movslq -0x844(%rbp), %rcx
movq 0x5cdd8(%rip), %rax     # 0x82578
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
movslq -0x848(%rbp), %rcx
movq 0x5cdbb(%rip), %rax     # 0x82578
addq $0x1000, %rax           # imm = 0x1000
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movslq -0x848(%rbp), %rcx
movq 0x5cd99(%rip), %rax     # 0x82578
addq $0x1000, %rax           # imm = 0x1000
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
cmpq $0x0, -0x218(%rbp)
jne 0x25803
jmp 0x25c39
movq 0x5d1fe(%rip), %rax     # 0x82a08
movl $0x1, (%rax)
movl $0x0, -0x434(%rbp)
movq -0x228(%rbp), %rcx
movq -0x218(%rbp), %rax
subq %rax, %rcx
xorl %eax, %eax
cmpq -0x220(%rbp), %rcx
movb %al, -0x851(%rbp)
jge 0x25864
movq -0x228(%rbp), %rdi
leaq -0x430(%rbp), %rdx
leaq 0x4c4bc(%rip), %rsi     # 0x71d0d
movb $0x0, %al
callq 0x19180
cmpl $0x0, %eax
setne %al
movb %al, -0x851(%rbp)
movb -0x851(%rbp), %al
testb $0x1, %al
jne 0x25873
jmp 0x25acd
leaq -0x430(%rbp), %rdi
callq 0x186e0
addq -0x228(%rbp), %rax
movq %rax, -0x228(%rbp)
movq -0x228(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x258b0
movq -0x228(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x228(%rbp)
jmp 0x2588d
movsbl -0x430(%rbp), %eax
cmpl $0x23, %eax
je 0x258d4
movsbl -0x430(%rbp), %eax
cmpl $0x2f, %eax
je 0x258d4
movsbl -0x430(%rbp), %eax
cmpl $0x3b, %eax
jne 0x258d9
jmp 0x2581a
leaq -0x430(%rbp), %rdi
leaq 0x4b062(%rip), %rsi     # 0x70949
callq 0x18bf0
cmpl $0x0, %eax
jne 0x258fb
movl $0x0, -0x434(%rbp)
leaq -0x430(%rbp), %rdi
leaq 0x4b046(%rip), %rsi     # 0x7094f
callq 0x18bf0
cmpl $0x0, %eax
jne 0x2591d
movl $0x1, -0x434(%rbp)
leaq -0x430(%rbp), %rdi
callq 0x186e0
cmpq $0x0, %rax
je 0x25ac8
leaq -0x430(%rbp), %rdi
leaq -0x840(%rbp), %rdx
leaq -0x640(%rbp), %rcx
leaq 0x4b007(%rip), %rsi     # 0x70956
movb $0x0, %al
callq 0x19180
cmpl $0x2, %eax
jne 0x25ac8
cmpl $0x0, -0x434(%rbp)
jne 0x25a08
leaq -0x840(%rbp), %rdi
callq 0x18300
movq %rax, %rcx
movslq -0x844(%rbp), %rdx
movq 0x5cbef(%rip), %rax     # 0x82578
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
leaq -0x640(%rbp), %rdi
callq 0x18300
movq %rax, %rcx
movslq -0x844(%rbp), %rdx
movq 0x5cbc8(%rip), %rax     # 0x82578
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x844(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x844(%rbp)
movslq -0x844(%rbp), %rcx
movq 0x5cba0(%rip), %rax     # 0x82578
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movslq -0x844(%rbp), %rcx
movq 0x5cb84(%rip), %rax     # 0x82578
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
jmp 0x25ac6
cmpl $0x1, -0x434(%rbp)
jne 0x25ac4
leaq -0x840(%rbp), %rdi
callq 0x18300
movq %rax, %rcx
movslq -0x848(%rbp), %rdx
movq 0x5cb46(%rip), %rax     # 0x82578
addq $0x1000, %rax           # imm = 0x1000
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
leaq -0x640(%rbp), %rdi
callq 0x18300
movq %rax, %rcx
movslq -0x848(%rbp), %rdx
movq 0x5cb19(%rip), %rax     # 0x82578
addq $0x1000, %rax           # imm = 0x1000
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x848(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x848(%rbp)
movslq -0x848(%rbp), %rcx
movq 0x5caeb(%rip), %rax     # 0x82578
addq $0x1000, %rax           # imm = 0x1000
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movslq -0x848(%rbp), %rcx
movq 0x5cac9(%rip), %rax     # 0x82578
addq $0x1000, %rax           # imm = 0x1000
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, 0x8(%rax)
jmp 0x25ac6
jmp 0x25ac8
jmp 0x2581a
movq 0x5cb2c(%rip), %rax     # 0x82600
movq 0x110(%rax), %rax
movq -0x218(%rbp), %rdi
callq *%rax
movq 0x5cb1d(%rip), %rax     # 0x82608
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x25b02
jp 0x25b02
jmp 0x25c39
movl $0x0, -0x844(%rbp)
leaq 0x4ae4c(%rip), %rdi     # 0x7095f
movq 0x5cae6(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
movslq -0x844(%rbp), %rcx
movq 0x5ca4b(%rip), %rax     # 0x82578
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x25b92
movq 0x5cabf(%rip), %rax     # 0x82600
movq 0x8(%rax), %rcx
movslq -0x844(%rbp), %rdx
movq 0x5ca25(%rip), %rax     # 0x82578
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rax), %rsi
movslq -0x844(%rbp), %rdx
movq 0x5ca0d(%rip), %rax     # 0x82578
shlq $0x4, %rdx
addq %rdx, %rax
movq 0x8(%rax), %rdx
leaq 0x4ade9(%rip), %rdi     # 0x70966
movb $0x0, %al
callq *%rcx
movl -0x844(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x844(%rbp)
jmp 0x25b1f
movl $0x0, -0x844(%rbp)
leaq 0x4addc(%rip), %rdi     # 0x7097f
movq 0x5ca56(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x8(%rcx)
movslq -0x844(%rbp), %rcx
movq 0x5c9bb(%rip), %rax     # 0x82578
addq $0x1000, %rax           # imm = 0x1000
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x25c37
movq 0x5ca29(%rip), %rax     # 0x82600
movq 0x8(%rax), %rcx
movslq -0x844(%rbp), %rdx
movq 0x5c98f(%rip), %rax     # 0x82578
addq $0x1000, %rax           # imm = 0x1000
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rax), %rsi
movslq -0x844(%rbp), %rdx
movq 0x5c971(%rip), %rax     # 0x82578
addq $0x1000, %rax           # imm = 0x1000
shlq $0x4, %rdx
addq %rdx, %rax
movq 0x8(%rax), %rdx
leaq 0x4ad47(%rip), %rdi     # 0x70966
movb $0x0, %al
callq *%rcx
movl -0x844(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x844(%rbp)
jmp 0x25baf
jmp 0x25c39
addq $0x860, %rsp            # imm = 0x860
popq %rbp
retq
nopw %cs:(%rax,%rax)