// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x4b70
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x4b30
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x4b70
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x4b30
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movslq -0x24(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0xa, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x1, -0x44(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0xf036
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x25, %eax
je 0xed75
movq -0x30(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x1, -0xa0(%rbp)
movl $0x1, -0x9c(%rbp)
movl $0x0, -0xa4(%rbp)
jmp 0xef5f
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0xed90
jmp 0xf036
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xa4(%rbp)
cmpl $0x0, -0xa4(%rbp)
je 0xedce
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0xedcc
jmp 0xf036
jmp 0xedce
callq 0x3310
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movzbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
movl %eax, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
je 0xee21
movq -0x30(%rbp), %rdi
leaq -0x30(%rbp), %rsi
movl $0xa, %edx
callq 0x32b0
movl %eax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0xee1f
jmp 0xf036
jmp 0xee5f
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0xee5d
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x4b70
movl %eax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0xee5b
jmp 0xf036
jmp 0xee5d
jmp 0xee5f
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
addl $-0x25, %eax
movl %eax, %ecx
movq %rcx, -0xb0(%rbp)
subl $0x53, %eax
ja 0xef58
movq -0xb0(%rbp), %rax
leaq 0x6b77(%rip), %rcx      # 0x15a00
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x4b70
movl %eax, -0x9c(%rbp)
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x4b30
movq %rax, -0x98(%rbp)
jmp 0xef5d
movl $0x10, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x4b70
movl %eax, -0xa8(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0xeefd
movslq -0xa8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl -0x3c(%rbp), %edx
callq 0xfe10
jmp 0xef13
movslq -0xa8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl -0x3c(%rbp), %edx
callq 0xfc30
movl $0xa, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x30d0
movl %eax, -0x9c(%rbp)
jmp 0xef5d
movq -0x30(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x1, -0x9c(%rbp)
jmp 0xed2d
jmp 0xef5f
cmpl $0x0, -0x44(%rbp)
je 0xf025
cmpl $0x0, -0xa0(%rbp)
jne 0xef7e
movl -0x9c(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
cmpl -0xc(%rbp), %eax
jle 0xef99
movl $0x0, -0x44(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xa0(%rbp)
jmp 0xef9b
movl -0xa0(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jle 0xefec
movl -0xa4(%rbp), %edx
movl $0x20, %eax
movl $0x30, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x18(%rbp)
movb %cl, (%rax)
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movl -0xa0(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0xef9b
movq -0x18(%rbp), %rdi
movq -0x98(%rbp), %rsi
movslq -0x9c(%rbp), %rdx
callq 0x31e0
movl -0x9c(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x9c(%rbp), %ecx
movl -0xc(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xc(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xed2d
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x4c60
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
subq %rax, %rsi
callq 0x4c90
movq -0x8(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0xc0(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x44(%rbp)
movb %al, -0xb1(%rbp)
je 0xf086
movb $0x1, %al
movb %al, -0xb1(%rbp)
jmp 0xf086
movq -0xc0(%rbp), %rdi
movb -0xb1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movslq %eax, %rsi
callq 0x4c90
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)