// File: /workspace/github_c_makefile_star2_O3/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 0x132e
cmpl $0x0, (%rbx)
jne 0x1485
movsd (%rdi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x135c
jp 0x135c
movl $0x4, %edi
callq 0x1040
testq %rax, %rax
je 0x147f
movl $0x302e30, (%rax)       # imm = 0x302E30
jmp 0x1472
movsd (%rdi), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x135c
jp 0x135c
movl $0x4, %edi
callq 0x1040
testq %rax, %rax
je 0x1485
movl $0x302e30, (%rax)       # imm = 0x302E30
jmp 0x1487
movb $0x0, (%rsp)
movzwl 0x18(%rdi), %ecx
testq %rcx, %rcx
je 0x13a4
movl $0x1, %esi
movabsq $-0x3333333333333333, %r8 # imm = 0xCCCCCCCCCCCCCCCD
movq %rcx, %rax
mulq %r8
shrq $0x3, %rdx
leal (%rdx,%rdx), %eax
leal (%rax,%rax,4), %eax
movl %ecx, %r9d
subl %eax, %r9d
orb $0x30, %r9b
movb %r9b, (%rsp,%rsi)
incq %rsi
cmpq $0x9, %rcx
movq %rdx, %rcx
ja 0x1378
jmp 0x13ae
movb $0x30, 0x1(%rsp)
movl $0x2, %esi
movb $0x2e, (%rsp,%rsi)
testq %rbx, %rbx
je 0x13c4
cmpl $0x0, (%rbx)
je 0x13c4
incq %rsi
movq %rsi, %r14
jmp 0x1428
movq 0x10(%rdi), %rdx
leaq 0x1(%rsi), %r14
testq %rdx, %rdx
setle %al
cmpq $0xf, %r14
setae %cl
orb %al, %cl
jne 0x141e
movabsq $-0x3333333333333333, %r8 # imm = 0xCCCCCCCCCCCCCCCD
movq %rdx, %rcx
movq %rdx, %rax
mulq %r8
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,%rsi)
incq %rsi
cmpq $0xa, %rcx
jb 0x1418
cmpq $0xe, %rsi
jb 0x13e7
movq %rsi, %r14
incq %r14
testq %rbx, %rbx
je 0x1437
cmpl $0x0, (%rbx)
je 0x1437
movq %r14, %rdi
callq 0x1040
testq %rax, %rax
jne 0x1456
jmp 0x147f
cmpb $0x0, 0x8(%rdi)
je 0x1449
addq $0x2, %rsi
movb $0x2d, (%rsp,%r14)
movq %rsi, %r14
movq %r14, %rdi
callq 0x1040
testq %rax, %rax
je 0x147a
testq %r14, %r14
je 0x146d
movq %rax, %rcx
movb -0x1(%rsp,%r14), %dl
movb %dl, (%rcx)
incq %rcx
decq %r14
jne 0x145e
testq %rbx, %rbx
je 0x1487
movl $0x0, (%rbx)
jmp 0x1487
testq %rbx, %rbx
je 0x1485
movl $0x80000001, (%rbx)     # imm = 0x80000001
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
retq