// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movq %rdi, %rbx
movq 0x60(%rdi), %rdi
callq 0x422e
movq %rax, 0x18(%rsp)
movq 0x60(%rbx), %rdi
callq 0x420e
movq %rax, %r12
movq 0x60(%rbx), %rdi
callq 0x422e
movq %rax, %r14
movq %rbx, 0x10(%rsp)
movq 0x60(%rbx), %rdi
callq 0x420e
movq %rax, %rsi
leaq 0x8(%rsp), %rax
movq %rsi, (%rax)
movslq %r14d, %r13
addq %rsi, %r13
pushq $0x1
popq %rcx
movq %r12, 0x28(%rsp)
movq %r13, 0x20(%rsp)
cmpq %r13, %rsi
jae 0xa662
cmpb $0x25, (%rsi)
jne 0xa4f7
movl %ecx, 0x4(%rsp)
leaq 0x1(%rsi), %r14
movq %r14, 0x8(%rsp)
cmpq %r13, %r14
je 0xa65e
movb (%r14), %bl
cmpb $0x30, %bl
sete %r15b
jne 0xa4c6
addq $0x2, %rsi
movq %rsi, 0x8(%rsp)
cmpq %r13, %rsi
je 0xa65e
movb (%rsi), %bl
movq %rsi, %r14
callq 0x3340
movq (%rax), %rax
movzbl %bl, %ecx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0xa50a
xorl %ebp, %ebp
cmpb $0x2a, %bl
jne 0xa52b
movq 0x10(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x422e
incq %r14
movq %r14, 0x8(%rsp)
jmp 0xa51f
movq %rsi, %r14
pushq $0x1
popq %rax
movl %eax, %r13d
movl %eax, %ebp
xorl %r15d, %r15d
jmp 0xa5d5
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x32d0
movq 0x8(%rsp), %r14
cmpq %r13, %r14
je 0xa65e
movq %rax, %rbp
movzbl (%r14), %eax
movb $0x1, %bl
cmpl $0x44, %eax
je 0xa582
cmpl $0x53, %eax
je 0xa561
cmpl $0x55, %eax
je 0xa580
cmpl $0x58, %eax
je 0xa586
pushq $0xa
popq %r13
cmpl $0x64, %eax
je 0xa58c
cmpl $0x78, %eax
je 0xa586
cmpl $0x75, %eax
je 0xa580
cmpl $0x73, %eax
jne 0xa653
movq 0x10(%rsp), %rbx
movq 0x60(%rbx), %rdi
callq 0x422e
movq %rax, %r13
movq 0x60(%rbx), %rdi
callq 0x420e
movq %rax, %rsi
jmp 0xa5d1
xorl %ebx, %ebx
pushq $0xa
jmp 0xa58a
xorl %ebx, %ebx
pushq $0x10
popq %r13
movq 0x10(%rsp), %rax
movq 0x60(%rax), %rdi
callq 0x422e
movslq %eax, %rdi
testb %bl, %bl
je 0xa5b3
leaq 0x30(%rsp), %rbx
movq %rbx, %rsi
movl %r13d, %edx
callq 0xada8
jmp 0xa5c3
leaq 0x30(%rsp), %rbx
movq %rbx, %rsi
movl %r13d, %edx
callq 0xae8b
movq %rbx, %rdi
callq 0x30e0
movq %rax, %r13
movq %rbx, %rsi
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
je 0xa63a
testl %ebp, %ebp
cmovel %r13d, %ebp
movq 0x18(%rsp), %rax
cmpl %eax, %ebp
cmovll %ebp, %eax
shlb $0x4, %r15b
orb $0x20, %r15b
xorl %ebx, %ebx
cmpl %r13d, %eax
jle 0xa603
movb %r15b, (%r12,%rbx)
decl %eax
incq %rbx
jmp 0xa5f3
movq 0x18(%rsp), %r15
cmpl %r15d, %ebp
movl $0x0, %ebp
setle %bpl
movslq %r13d, %r14
addq %rbx, %r12
movq %r12, %rdi
movq %r14, %rdx
callq 0x3200
addq %r14, %r12
subl %r13d, %r15d
subl %ebx, %r15d
movq %r15, 0x18(%rsp)
movq 0x8(%rsp), %r14
jmp 0xa63c
xorl %ebp, %ebp
incq %r14
movq %r14, 0x8(%rsp)
movl %ebp, %ecx
movq 0x20(%rsp), %r13
movq %r14, %rsi
jmp 0xa47f
movq 0x20(%rsp), %r13
movl 0x4(%rsp), %ecx
jmp 0xa64b
movl 0x4(%rsp), %ecx
movl %ecx, %ebp
movq 0x10(%rsp), %rbx
movq 0x60(%rbx), %rdi
movq 0x28(%rsp), %r14
movq %r14, %rsi
callq 0x4287
movq 0x60(%rbx), %rdi
subq %r14, %r12
movq %r12, %rsi
callq 0x4298
movq 0x60(%rbx), %rdi
xorl %esi, %esi
testl %ebp, %ebp
setne %sil
callq 0x4298
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq