// File: /workspace/github_c_makefile_star2_O3/hoobaa[P]ficl/primitives.c
// Function: ficlPrimitiveSprintf
static void ficlPrimitiveSprintf(ficlVm *vm) /*  */
{
	int bufferLength = ficlStackPopInteger(vm->dataStack);
	char *buffer = (char *)ficlStackPopPointer(vm->dataStack);
	char *bufferStart = buffer;

	int formatLength = ficlStackPopInteger(vm->dataStack);
	char *format = (char *)ficlStackPopPointer(vm->dataStack);
	char *formatStop = format + formatLength;

	int base = 10;
	int unsignedInteger = 0; /* false */

	int append = 1; /* true */

	while (format < formatStop)
	{
		char scratch[64];
		char *source;
		int actualLength;
		int desiredLength;
		int leadingZeroes;


		if (*format != '%')
		{
			source = format;
			actualLength = desiredLength = 1;
			leadingZeroes = 0;
		}
		else
		{
			format++;
			if (format == formatStop)
				break;

			leadingZeroes = (*format == '0');
			if (leadingZeroes)
				{
				format++;
				if (format == formatStop)
					break;
				}

			desiredLength = isdigit((unsigned char)*format);
			if (desiredLength)
				{
				desiredLength = strtoul(format, &format, 10);
				if (format == formatStop)
					break;
				}
			else if (*format == '*')
				{
				desiredLength = ficlStackPopInteger(vm->dataStack);
				format++;
				if (format == formatStop)
					break;
				}


			switch (*format)
			{
				case 's':
				case 'S':
				{
					actualLength = ficlStackPopInteger(vm->dataStack);
					source = (char *)ficlStackPopPointer(vm->dataStack);
					break;
				}
				case 'x':
				case 'X':
					base = 16;
				case 'u':
				case 'U':
					unsignedInteger = 1; /* true */
				case 'd':
				case 'D':
				{
					int integer = ficlStackPopInteger(vm->dataStack);
					if (unsignedInteger)
						ficlUltoa(integer, scratch, base);
					else
						ficlLtoa(integer, scratch, base);
					base = 10;
					unsignedInteger = 0; /* false */
					source = scratch;
					actualLength = strlen(scratch);
					break;
				}
				case '%':
					source = format;
					actualLength = 1;
				default:
					continue;
			}
		}

		if (append)
		{
			if (!desiredLength)
				desiredLength = actualLength;
			if (desiredLength > bufferLength)
			{
				append = 0; /* false */
				desiredLength = bufferLength;
			}
			while (desiredLength > actualLength)
				{
				*buffer++ = (char)((leadingZeroes) ? '0' : ' ');
				bufferLength--;
				desiredLength--;
				}
			memcpy(buffer, source, actualLength);
			buffer += actualLength;
			bufferLength -= actualLength;
		}

		format++;
	}

	ficlStackPushPointer(vm->dataStack, bufferStart);
	ficlStackPushInteger(vm->dataStack, buffer - bufferStart);
	ficlStackPushInteger(vm->dataStack, append && FICL_TRUE);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %r14
movq 0x60(%rdi), %rdi
callq 0x42bd
movq %rax, %r12
movq 0x60(%r14), %rdi
callq 0x429d
movq %rax, %r15
movq 0x60(%r14), %rdi
callq 0x42bd
movq %rax, %rbx
movq %r14, 0x28(%rsp)
movq 0x60(%r14), %rdi
callq 0x429d
movq %rax, %rbp
movq %rax, 0x10(%rsp)
movslq %ebx, %rax
testq %rax, %rax
movq %r15, 0x38(%rsp)
jle 0xad0f
addq %rbp, %rax
movl $0x1, %ecx
movq %r15, 0x20(%rsp)
movq %r12, %rbx
movq %rax, %r15
movq %rax, 0x30(%rsp)
xorl %eax, %eax
cmpb $0x25, (%rbp)
jne 0xab3b
movq %rbx, 0x18(%rsp)
leaq 0x1(%rbp), %r13
movq %r13, 0x10(%rsp)
cmpq %r15, %r13
je 0xad19
movb (%r13), %bl
cmpb $0x30, %bl
sete %al
movl %eax, 0xc(%rsp)
jne 0xab06
addq $0x2, %rbp
movq %rbp, 0x10(%rsp)
cmpq %r15, %rbp
je 0xad19
movb (%rbp), %bl
movq %rbp, %r13
movl %ecx, %r12d
callq 0x3340
movq (%rax), %rax
movzbl %bl, %ecx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0xab57
xorl %r14d, %r14d
cmpb $0x2a, %bl
jne 0xab84
movq 0x28(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x42bd
incq %r13
movq %r13, 0x10(%rsp)
jmp 0xab6e
movq %rbp, %r13
movl $0x1, %r15d
movl $0x1, %r14d
movl $0x0, 0xc(%rsp)
jmp 0xac5f
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
movl $0xa, %edx
callq 0x32d0
movq 0x10(%rsp), %r13
cmpq %r15, %r13
movl %r12d, %ecx
je 0xad19
movq %rax, %r14
leaq 0x40(%rsp), %rbp
jmp 0xab8c
leaq 0x40(%rsp), %rbp
movl %r12d, %ecx
movzbl (%r13), %eax
movl $0x10, %ebx
cmpl $0x63, %eax
jg 0xabb4
cmpl $0x54, %eax
jg 0xabea
cmpl $0x44, %eax
je 0xac0a
cmpl $0x53, %eax
je 0xabc3
movq 0x18(%rsp), %rbx
jmp 0xacfc
cmpl $0x74, %eax
jg 0xabf6
cmpl $0x64, %eax
je 0xac0a
cmpl $0x73, %eax
jne 0xabaa
movq 0x28(%rsp), %rbx
movq 0x60(%rbx), %rdi
callq 0x42bd
movq %rax, %r15
movq 0x60(%rbx), %rdi
callq 0x429d
movl %r12d, %ecx
movq %rax, %rbp
movq 0x18(%rsp), %rbx
jmp 0xac5d
cmpl $0x55, %eax
je 0xac2a
cmpl $0x58, %eax
je 0xac2f
jmp 0xac00
cmpl $0x75, %eax
je 0xac2a
cmpl $0x78, %eax
je 0xac2f
movq 0x18(%rsp), %rbx
jmp 0xad01
movq 0x28(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x42bd
movslq %eax, %rdi
movq %rbp, %rsi
movl $0xa, %edx
callq 0xb433
jmp 0xac4a
movl $0xa, %ebx
movq 0x28(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x42bd
movslq %eax, %rdi
movq %rbp, %rsi
movl %ebx, %edx
callq 0xb538
movq %rbp, %rdi
callq 0x30e0
movq %rax, %r15
movq 0x18(%rsp), %rbx
movl %r12d, %ecx
xorl %eax, %eax
testl %ecx, %ecx
je 0xacf2
testl %r14d, %r14d
cmovel %r15d, %r14d
xorl %eax, %eax
cmpl %ebx, %r14d
setle %cl
cmovgel %ebx, %r14d
cmpl %r15d, %r14d
jle 0xacc4
movq 0x20(%rsp), %r12
movq %rbx, %r13
movl %r15d, %ebx
notl %ebx
addl %r14d, %ebx
leaq 0x1(%rbx), %rdx
movzbl 0xc(%rsp), %esi
shll $0x4, %esi
orl $0x20, %esi
movq %r12, %rdi
movb %cl, 0xc(%rsp)
callq 0x3130
movb 0xc(%rsp), %cl
addl %r15d, %r13d
addq %rbx, %r12
incq %r12
movq %r12, 0x20(%rsp)
xorl %eax, %eax
movq %r13, %rbx
subl %r14d, %ebx
movb %cl, %al
movslq %r15d, %r14
movl %eax, %r13d
movq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x3200
addq %r14, %r12
movq %r12, 0x20(%rsp)
movl %r13d, %eax
subl %r15d, %ebx
movq 0x10(%rsp), %r13
incq %r13
movq %r13, 0x10(%rsp)
movl %eax, %ecx
movq 0x30(%rsp), %r15
movq %r13, %rbp
cmpq %r15, %r13
jb 0xaabf
jmp 0xad19
movl $0x1, %ecx
movq %r15, 0x20(%rsp)
movq 0x28(%rsp), %rbx
movq 0x60(%rbx), %rdi
movq 0x38(%rsp), %r14
movq %r14, %rsi
movl %ecx, %ebp
callq 0x4316
movq 0x60(%rbx), %rdi
movq 0x20(%rsp), %rsi
subq %r14, %rsi
callq 0x4327
movq 0x60(%rbx), %rdi
xorl %esi, %esi
testl %ebp, %ebp
setne %sil
callq 0x4327
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq