// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/g_replace.c
// Function: string_replace
void string_replace(edict_t *person, char *inmsg, char *outmsg, int outsize)
{
	char * result;
	char * msgptr;
	char * subptr;
	char * tmpstr;
	char * substr;
	
	
	strcpy(outmsg,inmsg); //in case anything fails, you'll say something
	substr = (char *)gi.TagMalloc(outsize * 2, TAG_LEVEL);
	result = (char *)gi.TagMalloc(outsize * 2, TAG_LEVEL);
	tmpstr = (char *)gi.TagMalloc(outsize * 2, TAG_LEVEL);
	
	//initialize strings empty
	tmpstr[0] = 0;
	result[0] = 0;
	substr[0] = 0;
	
	if ( (substr != NULL) && (result != NULL) && (tmpstr != NULL) )
	{
		msgptr = &inmsg[0]; //point to beginning of inmsg
		while (*msgptr != 0) //while not at end of the inmsg
		{
			if (*msgptr == '%')
			{
				//we are dealing with a substr
				msgptr++; //advance to start with character after %
				subptr = &substr[0]; //point to beginning of string
				do
				{
					*subptr = *msgptr;
					subptr++;
					msgptr++;
				}
				while ( (*msgptr != 0) && (*msgptr != '%') && (*msgptr != ' ') );

				msgptr--; //back off because we went past the end
				
				//now in theory we have the block of chars after %
				*subptr = 0; //should already be pointing to end of substr
				
				if (strlen(substr) == 1)
				{
					switch(tolower(substr[0])) //switch on the single character
					{
					case 'l' :
						replace_location(person, tmpstr, false, true);
						break;
					case 'a' :
						replace_armor(person, tmpstr);
						break;
					case 'h' :
						replace_health(person, tmpstr);
						break;
					case 't' :
						replace_artifact(person, tmpstr);
						break;
					case 'w' :
						replace_weapon(person, tmpstr);
						break;
					case 'n' :
						replace_team(person, tmpstr);
						break;
					case 'p' :
						replace_location(person, tmpstr, true, false);
						break;
					case 'f' :
						replace_flaginfo(person, tmpstr);
						break;
					case 'v' :
						replace_viewinfo(person, tmpstr);
						break;
					case 'c' :
						replace_carrierinfo(person, tmpstr);
						break;
					default:
						tmpstr[0] = substr[0];
						tmpstr[1] = 0;
						break;
					}
				}
				else
				{
					//use infovalueforkey feature
					strcpy(tmpstr, Info_ValueForKey(person->client->pers.userinfo, substr));
				}
				
			}
			else
			{
				tmpstr[0] = *msgptr;
				tmpstr[1] = 0;
				//above should cause us to strcat the single char
			}
			strcat(result, tmpstr);
			msgptr++;
		}
		result[outsize-2] = 0;
		strcpy(outmsg, result); //copy the resulting string
	}

	gi.TagFree(tmpstr);
	gi.TagFree(result);
	gi.TagFree(substr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x182c0
movq 0x63d95(%rip), %rax     # 0x82600
movq 0x108(%rax), %rax
movl -0x1c(%rbp), %edi
shll %edi
movl $0x2fe, %esi            # imm = 0x2FE
callq *%rax
movq %rax, -0x48(%rbp)
movq 0x63d77(%rip), %rax     # 0x82600
movq 0x108(%rax), %rax
movl -0x1c(%rbp), %edi
shll %edi
movl $0x2fe, %esi            # imm = 0x2FE
callq *%rax
movq %rax, -0x28(%rbp)
movq 0x63d59(%rip), %rax     # 0x82600
movq 0x108(%rax), %rax
movl -0x1c(%rbp), %edi
shll %edi
movl $0x2fe, %esi            # imm = 0x2FE
callq *%rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movb $0x0, (%rax)
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq -0x48(%rbp), %rax
movb $0x0, (%rax)
cmpq $0x0, -0x48(%rbp)
je 0x1eb26
cmpq $0x0, -0x28(%rbp)
je 0x1eb26
cmpq $0x0, -0x40(%rbp)
je 0x1eb26
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x1eb08
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
jne 0x1ead6
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movb (%rax), %cl
movq -0x38(%rbp), %rax
movb %cl, (%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x49(%rbp)
je 0x1e986
movq -0x30(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x25, %ecx
movb %al, -0x49(%rbp)
je 0x1e986
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
setne %al
movb %al, -0x49(%rbp)
movb -0x49(%rbp), %al
testb $0x1, %al
jne 0x1e930
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movb $0x0, (%rax)
movq -0x48(%rbp), %rdi
callq 0x186e0
cmpq $0x1, %rax
jne 0x1eaa8
movq -0x48(%rbp), %rax
movsbl (%rax), %edi
callq 0x19070
addl $-0x61, %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
subl $0x16, %eax
ja 0x1ea92
movq -0x58(%rbp), %rax
leaq 0x514a8(%rip), %rcx     # 0x6fe84
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x18ea0
jmp 0x1eaa6
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x195a0
jmp 0x1eaa6
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x18870
jmp 0x1eaa6
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x18460
jmp 0x1eaa6
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x189c0
jmp 0x1eaa6
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x19290
jmp 0x1eaa6
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x18ea0
jmp 0x1eaa6
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x19860
jmp 0x1eaa6
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x185a0
jmp 0x1eaa6
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x198b0
jmp 0x1eaa6
movq -0x48(%rbp), %rax
movb (%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, (%rax)
movq -0x40(%rbp), %rax
movb $0x0, 0x1(%rax)
jmp 0x1ead4
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
addq $0xc0, %rdi
movq -0x48(%rbp), %rsi
callq 0x18cb0
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x182c0
jmp 0x1eaea
movq -0x30(%rbp), %rax
movb (%rax), %cl
movq -0x40(%rbp), %rax
movb %cl, (%rax)
movq -0x40(%rbp), %rax
movb $0x0, 0x1(%rax)
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x19880
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x1e8fc
movq -0x28(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x182c0
movq 0x63ad3(%rip), %rax     # 0x82600
movq 0x110(%rax), %rax
movq -0x40(%rbp), %rdi
callq *%rax
movq 0x63abf(%rip), %rax     # 0x82600
movq 0x110(%rax), %rax
movq -0x28(%rbp), %rdi
callq *%rax
movq 0x63aab(%rip), %rax     # 0x82600
movq 0x110(%rax), %rax
movq -0x48(%rbp), %rdi
callq *%rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)