// File: /workspace/github_c_makefile_star2_O1/phluid61[P]hsf/src/decimal.c
// Function: SH_Decimal__to_s
sh_char_t*
SH_Decimal__to_s(SH_Decimal* obj, int* err) {
	sh_char_t* str;
	sh_char_t* ptr;
	sh_char_t  buffer[18]; /* sign + 12 digits + dot + 3 digits + null */
	size_t n;
	sh_int_t v;

	__cascade(err, (sh_char_t*)0);

	if (obj->value == SH_FLOAT_C(0)) {
		str = (sh_char_t*)malloc(sizeof(sh_char_t) * 4);
		if ((sh_char_t*)0 == str) {
			__raise(err, SH_E_MALLOC_ERROR);
			return (sh_char_t*)0;
		}

		str[0] = (sh_char_t)'0';
		str[1] = (sh_char_t)'.';
		str[2] = (sh_char_t)'0';
		str[3] = SH_CHAR_C(0);

		__clear(err);
		return str;
	}

	n = 0;
	buffer[n++] = SH_CHAR_C(0);

	/* fractional part */
	v = (sh_int_t)SH_Decimal__fractional_part(obj, err);

	if (SH_INT_C(0) == v) {
		buffer[n++] = SH_CHAR_C('0');
	} else {
		while (v > SH_INT_C(0)) {
			buffer[n++] = (sh_char_t)(v % 10) + SH_CHAR_C('0');
			v /= SH_INT_C(10);
		}
	}

	buffer[n++] = SH_CHAR_C('.');

	/* integer part and sign (same as SH_Integer) */
	v = SH_Decimal__integer_part(obj, err);

	while (v > SH_INT_C(0) && n <= 14) {
		buffer[n++] = (sh_char_t)(v % 10) + SH_CHAR_C('0');
		v /= SH_INT_C(10);
	}

	/* FIXME: if v > 0: invalid state? */

	if (SH_Decimal__negative(obj, err)) {
		buffer[n++] = (sh_char_t)'-';
	}

	str = (sh_char_t*)malloc(sizeof(sh_char_t) * n);
	if ((sh_char_t*)0 == str) {
		__raise(err, SH_E_MALLOC_ERROR);
		return (sh_char_t*)0;
	}

	ptr = str;
	while (n > 0) {
		n--;
		*ptr = buffer[n];
		ptr++;
	}

	__clear(err);
	return str;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
testq %rsi, %rsi
je 0x12ef
cmpl $0x0, (%rbx)
je 0x12ef
xorl %eax, %eax
jmp 0x144e
movsd (%rdi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x131d
jp 0x131d
movl $0x4, %edi
callq 0x1040
testq %rax, %rax
je 0x1440
movl $0x302e30, (%rax)       # imm = 0x302E30
jmp 0x1437
movb $0x0, (%rsp)
testq %rbx, %rbx
je 0x1335
cmpl $0x0, (%rbx)
je 0x132f
xorl %eax, %eax
jmp 0x1339
movl $0x0, (%rbx)
movzwl 0x18(%rdi), %eax
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
testw %ax, %ax
je 0x137d
movzwl %ax, %ecx
movl $0x1, %r8d
movq %rcx, %rax
mulq %rsi
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
movl %ecx, %r9d
subl %eax, %r9d
orb $0x30, %r9b
movb %r9b, (%rsp,%r8)
incq %r8
cmpq $0x9, %rcx
movq %rdx, %rcx
ja 0x1351
jmp 0x1388
movb $0x30, 0x1(%rsp)
movl $0x2, %r8d
movb $0x2e, (%rsp,%r8)
testq %rbx, %rbx
je 0x13a1
cmpl $0x0, (%rbx)
je 0x139b
xorl %edx, %edx
jmp 0x13a5
movl $0x0, (%rbx)
movq 0x10(%rdi), %rdx
leaq 0x1(%r8), %r14
testq %rdx, %rdx
setle %al
cmpq $0xf, %r14
setae %cl
orb %al, %cl
jne 0x13f1
movq %rdx, %rcx
movq %rdx, %rax
mulq %rsi
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
movl %ecx, %r9d
subl %eax, %r9d
orb $0x30, %r9b
movb %r9b, 0x1(%rsp,%r8)
incq %r8
cmpq $0xa, %rcx
jb 0x13eb
cmpq $0xe, %r8
jb 0x13ba
movq %r8, %r14
incq %r14
testq %rbx, %rbx
je 0x1401
cmpl $0x0, (%rbx)
jne 0x1413
movl $0x0, (%rbx)
cmpb $0x0, 0x8(%rdi)
je 0x1413
addq $0x2, %r8
movb $0x2d, (%rsp,%r14)
movq %r8, %r14
movq %r14, %rdi
callq 0x1040
testq %rax, %rax
je 0x1440
testq %r14, %r14
je 0x1437
movq %rax, %rcx
movb -0x1(%rsp,%r14), %dl
movb %dl, (%rcx)
incq %rcx
decq %r14
jne 0x1428
testq %rbx, %rbx
je 0x144e
xorl %ecx, %ecx
jmp 0x144c
movl $0x80000001, %ecx       # imm = 0x80000001
xorl %eax, %eax
testq %rbx, %rbx
je 0x144e
movl %ecx, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r14
retq