// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq 0x60(%rdi), %rdi
callq 0x4311
movq %rax, %r12
movq 0x60(%rbx), %rdi
callq 0x42f1
movq %rax, %r15
movq 0x60(%rbx), %rdi
callq 0x4311
movq %rax, %r14
movq %rbx, 0x28(%rsp)
movq 0x60(%rbx), %rdi
callq 0x42f1
leaq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movslq %r14d, %rcx
movq %r12, %r14
addq %rax, %rcx
movl $0x1, %edx
movq %r15, 0x30(%rsp)
movq %r15, %rbx
movq %rcx, %r15
movq %rcx, 0x38(%rsp)
movq 0x18(%rsp), %rbp
cmpq %r15, %rbp
jae 0xadfc
xorl %eax, %eax
cmpb $0x25, (%rbp)
jne 0xac6b
leaq 0x1(%rbp), %rax
movq %rax, 0x18(%rsp)
movb $0x1, %r12b
cmpq %r15, %rax
je 0xadf3
cmpb $0x30, (%rax)
sete %al
jne 0xac16
addq $0x2, %rbp
movq %rbp, 0x18(%rsp)
cmpq %r15, %rbp
je 0xadf3
movl %eax, 0x24(%rsp)
movl %edx, 0xc(%rsp)
movq %r14, 0x10(%rsp)
callq 0x3340
movq (%rax), %rcx
movq 0x18(%rsp), %r14
movzbl (%r14), %eax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0xac7e
xorl %r13d, %r13d
cmpb $0x2a, %al
jne 0xac9a
movq 0x28(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x4311
incq %r14
movq %r14, 0x18(%rsp)
cmpq %r15, %r14
jne 0xac97
movq 0x10(%rsp), %r14
movl 0xc(%rsp), %edx
jmp 0xadf3
movl $0x1, %r15d
movl $0x1, %r13d
xorl %ecx, %ecx
jmp 0xad71
movq %r14, %rdi
leaq 0x18(%rsp), %rsi
movl $0xa, %edx
callq 0x32d0
cmpq %r15, 0x18(%rsp)
je 0xac5d
movq %rax, %r13
movq 0x18(%rsp), %rax
movzbl (%rax), %eax
movb $0x1, %r14b
movl $0xa, %ebp
xorl %r12d, %r12d
cmpl $0x63, %eax
jg 0xacc7
cmpl $0x54, %eax
movl 0xc(%rsp), %edx
jg 0xad02
cmpl $0x44, %eax
je 0xad28
cmpl $0x53, %eax
je 0xacda
jmp 0xad0c
cmpl $0x74, %eax
movl 0xc(%rsp), %edx
jg 0xad16
cmpl $0x64, %eax
je 0xad28
cmpl $0x73, %eax
jne 0xad0c
movq 0x28(%rsp), %r14
movq 0x60(%r14), %rdi
callq 0x4311
movq %rax, %r15
movq 0x60(%r14), %rdi
callq 0x42f1
movl 0xc(%rsp), %edx
movq %rax, %rbp
movq 0x10(%rsp), %r14
jmp 0xad6b
cmpl $0x55, %eax
je 0xad25
cmpl $0x58, %eax
je 0xad20
movq 0x10(%rsp), %r14
jmp 0xadf3
cmpl $0x75, %eax
je 0xad25
cmpl $0x78, %eax
jne 0xad0c
movl $0x10, %ebp
xorl %r14d, %r14d
movq 0x28(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x4311
movslq %eax, %rdi
leaq 0x40(%rsp), %r15
movq %r15, %rsi
movl %ebp, %edx
testb %r14b, %r14b
je 0xad4f
callq 0xb557
jmp 0xad54
callq 0xb65c
movq 0x10(%rsp), %r14
movq %r15, %rdi
callq 0x30e0
movq %r15, %rbp
movq %rax, %r15
movl 0xc(%rsp), %edx
xorl %eax, %eax
movl 0x24(%rsp), %ecx
testl %edx, %edx
je 0xade4
testl %r13d, %r13d
cmovel %r15d, %r13d
xorl %eax, %eax
cmpl %r14d, %r13d
setle %dl
cmovgel %r14d, %r13d
cmpl %r15d, %r13d
jle 0xadc7
movq %r14, %r12
movl %r15d, %r14d
notl %r14d
addl %r13d, %r14d
movb %dl, 0xc(%rsp)
leaq 0x1(%r14), %rdx
movzbl %cl, %esi
shll $0x4, %esi
orl $0x20, %esi
movq %rbx, %rdi
callq 0x3130
movb 0xc(%rsp), %dl
xorl %eax, %eax
addl %r15d, %r12d
addq %r14, %rbx
incq %rbx
movq %r12, %r14
subl %r13d, %r14d
movb %dl, %al
movslq %r15d, %r13
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %eax, %ebp
callq 0x3200
movl %ebp, %eax
addq %r13, %rbx
subl %r15d, %r14d
incq 0x18(%rsp)
xorl %r12d, %r12d
movl %eax, %edx
movq 0x38(%rsp), %r15
testb %r12b, %r12b
je 0xabcd
movq %rbx, %r15
movq 0x28(%rsp), %rbx
movq 0x60(%rbx), %rdi
movq 0x30(%rsp), %r14
movq %r14, %rsi
movl %edx, %ebp
callq 0x436a
movq 0x60(%rbx), %rdi
subq %r14, %r15
movq %r15, %rsi
callq 0x437b
movq 0x60(%rbx), %rdi
xorl %esi, %esi
testl %ebp, %ebp
setne %sil
callq 0x437b
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq