// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x20(%rsp), %rsi
movq %rdx, 0x10(%rsi)
movq %rcx, 0x18(%rsi)
movq %r8, 0x20(%rsi)
movq %r9, 0x28(%rsi)
testb %al, %al
je 0x28a73
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq %rsi, 0x10(%rsp)
leaq 0x100(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
xorl %ebp, %ebp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
incl %eax
cmpb $0x0, (%rbx,%rax)
jne 0x28a9a
cmpl %eax, %ebp
jge 0x28ba1
movslq %ebp, %rcx
movb (%rbx,%rcx), %al
cmpb $0x25, %al
jne 0x28ae6
movzbl 0x1(%rbx,%rcx), %eax
incq %rcx
movl %ecx, %ebp
cmpl $0x63, %eax
jg 0x28af5
cmpl $0x25, %eax
je 0x28b18
cmpl $0x63, %eax
jne 0x28af1
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x28b3b
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x28b49
movsbl %al, %esi
movq %r14, %rdi
callq 0x2724c
incl %ebp
jmp 0x28a95
cmpl $0x73, %eax
je 0x28b22
cmpl $0x64, %eax
jne 0x28af1
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x28b4e
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x28b5c
movq %r14, %rdi
movl $0x25, %esi
jmp 0x28aec
movl (%rsp), %ecx
cmpq $0x28, %rcx
ja 0x28b68
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x28b76
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movsbl (%rax), %esi
jmp 0x28ae9
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
movq %r14, %rdi
callq 0x28bb0
jmp 0x28af1
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %r15
movb (%r15), %al
testb %al, %al
je 0x28af1
incq %r15
movsbl %al, %esi
movq %r14, %rdi
callq 0x2724c
movb (%r15), %al
incq %r15
testb %al, %al
jne 0x28b87
jmp 0x28af1
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop