// File: gersteinlab[P]MUSIC/src/ms_ansi_string.cpp
// Function: t_string::sprintf(char*, ...)
void t_string::sprintf(char* fmt_string, ...)
{
	va_list pars;
	va_start(pars, fmt_string);

	// Initialize string as having nothing.
	this->copy("");

	// Go over the string: Every time a formatting string is found by %.., it is processed.
	for(int i_str = 0; i_str < string_length(fmt_string); i_str++)
	{
		if(fmt_string[i_str] == '%')
		{
			// Check the formatter character.
			i_str++;

			if(fmt_string[i_str] == 'd')
			{
				int _num = va_arg(pars,int);
				this->concat_int(_num);
			}
			else if(fmt_string[i_str] == 'c')
			{
				int _char = va_arg(pars,int);
				this->concat_char(_char);
			}
			else if(fmt_string[i_str] == 's')
			{
				char* _str = (char*)va_arg(pars, void*);
				this->concat_string(_str);
			}
			else if(fmt_string[i_str] == '%')
			{
				this->concat_char(fmt_string[i_str]);
			}

			// The for loop jumps over formatter character.
			//i_str++;
		}
		else // This is a regular character, just copy it.
		{
			this->concat_char(fmt_string[i_str]);
		}
	}

	va_end(pars);
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
testb %al, %al
je 0x4a37b
movaps %xmm0, 0x80(%rsp)
movaps %xmm1, 0x90(%rsp)
movaps %xmm2, 0xa0(%rsp)
movaps %xmm3, 0xb0(%rsp)
movaps %xmm4, 0xc0(%rsp)
movaps %xmm5, 0xd0(%rsp)
movaps %xmm6, 0xe0(%rsp)
movaps %xmm7, 0xf0(%rsp)
movq %r9, 0x78(%rsp)
movq %r8, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rdi, 0x140(%rsp)
movq %rsi, 0x138(%rsp)
movq 0x140(%rsp), %rdi
movq %rdi, 0x48(%rsp)
leaq 0x120(%rsp), %rax
leaq 0x50(%rsp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x150(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
leaq 0xbde8(%rip), %rsi      # 0x561c5
callq 0x47360
movl $0x0, 0x11c(%rsp)
movl 0x11c(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x138(%rsp), %rdi
callq 0x47640
movl %eax, %ecx
movl 0x44(%rsp), %eax
cmpl %ecx, %eax
jge 0x4a663
movq 0x138(%rsp), %rax
movslq 0x11c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x25, %eax
jne 0x4a62d
movl 0x11c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x11c(%rsp)
movq 0x138(%rsp), %rax
movslq 0x11c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x64, %eax
jne 0x4a4d0
leaq 0x120(%rsp), %rax
movq %rax, 0x38(%rsp)
movl 0x120(%rsp), %eax
movl %eax, 0x40(%rsp)
cmpl $0x28, %eax
ja 0x4a493
movq 0x38(%rsp), %rcx
movl 0x40(%rsp), %edx
movslq %edx, %rax
addq 0x10(%rcx), %rax
addl $0x8, %edx
movl %edx, (%rcx)
movq %rax, 0x30(%rsp)
jmp 0x4a4ac
movq 0x38(%rsp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x8(%rcx)
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rdi
movq 0x30(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x118(%rsp)
movl 0x118(%rsp), %esi
callq 0x4a670
jmp 0x4a62b
movq 0x138(%rsp), %rax
movslq 0x11c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x63, %eax
jne 0x4a562
leaq 0x120(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x120(%rsp), %eax
movl %eax, 0x2c(%rsp)
cmpl $0x28, %eax
ja 0x4a522
movq 0x20(%rsp), %rcx
movl 0x2c(%rsp), %edx
movslq %edx, %rax
addq 0x10(%rcx), %rax
addl $0x8, %edx
movl %edx, (%rcx)
movq %rax, 0x18(%rsp)
jmp 0x4a53b
movq 0x20(%rsp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x8(%rcx)
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x114(%rsp)
movl 0x114(%rsp), %eax
movsbl %al, %esi
callq 0x481d0
jmp 0x4a629
movq 0x138(%rsp), %rax
movslq 0x11c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x73, %eax
jne 0x4a5ee
leaq 0x120(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x120(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpl $0x28, %eax
ja 0x4a5b3
movq 0x8(%rsp), %rcx
movl 0x14(%rsp), %edx
movslq %edx, %rax
addq 0x10(%rcx), %rax
addl $0x8, %edx
movl %edx, (%rcx)
movq %rax, (%rsp)
jmp 0x4a5cb
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, 0x8(%rcx)
movq %rax, (%rsp)
movq 0x48(%rsp), %rdi
movq (%rsp), %rax
movq (%rax), %rax
movq %rax, 0x108(%rsp)
movq 0x108(%rsp), %rsi
callq 0x4a6e0
jmp 0x4a627
movq 0x138(%rsp), %rax
movslq 0x11c(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x25, %eax
jne 0x4a625
movq 0x48(%rsp), %rdi
movq 0x138(%rsp), %rax
movslq 0x11c(%rsp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x481d0
jmp 0x4a627
jmp 0x4a629
jmp 0x4a62b
jmp 0x4a64b
movq 0x48(%rsp), %rdi
movq 0x138(%rsp), %rax
movslq 0x11c(%rsp), %rcx
movsbl (%rax,%rcx), %esi
callq 0x481d0
jmp 0x4a64d
movl 0x11c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x11c(%rsp)
jmp 0x4a3ed
addq $0x148, %rsp            # imm = 0x148
retq
nopl (%rax,%rax)