// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x150f
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpl (%rcx), %eax
je 0x150f
movq $0x0, -0x8(%rbp)
jmp 0x175c
movq -0x10(%rbp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1595
jp 0x1595
movl $0x4, %edi
callq 0x1070
movq %rax, -0x20(%rbp)
xorl %eax, %eax
cmpq -0x20(%rbp), %rax
jne 0x1557
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x154a
movq -0x18(%rbp), %rax
movl $0x80000001, (%rax)     # imm = 0x80000001
movq $0x0, -0x8(%rbp)
jmp 0x175c
movq -0x20(%rbp), %rax
movb $0x30, (%rax)
movq -0x20(%rbp), %rax
movb $0x2e, 0x1(%rax)
movq -0x20(%rbp), %rax
movb $0x30, 0x2(%rax)
movq -0x20(%rbp), %rax
movb $0x0, 0x3(%rax)
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x1588
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x175c
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movb $0x0, -0x40(%rbp,%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1060
movzwl %ax, %eax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
cmpq -0x50(%rbp), %rax
jne 0x15e3
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movb $0x30, -0x40(%rbp,%rax)
jmp 0x162d
jmp 0x15e5
cmpq $0x0, -0x50(%rbp)
jle 0x162b
movq -0x50(%rbp), %rax
movl $0xa, %ecx
cqto
idivq %rcx
movb %dl, %al
movzbl %al, %eax
addl $0x30, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, -0x40(%rbp,%rax)
movq -0x50(%rbp), %rax
movl $0xa, %ecx
cqto
idivq %rcx
movq %rax, -0x50(%rbp)
jmp 0x15e5
jmp 0x162d
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movb $0x2e, -0x40(%rbp,%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1040
movq %rax, -0x50(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x50(%rbp)
movb %al, -0x51(%rbp)
jle 0x1669
cmpq $0xe, -0x48(%rbp)
setbe %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x1672
jmp 0x16b1
movq -0x50(%rbp), %rax
movl $0xa, %ecx
cqto
idivq %rcx
movb %dl, %al
movzbl %al, %eax
addl $0x30, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x48(%rbp)
movb %cl, -0x40(%rbp,%rax)
movq -0x50(%rbp), %rax
movl $0xa, %ecx
cqto
idivq %rcx
movq %rax, -0x50(%rbp)
jmp 0x1652
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1050
cmpb $0x0, %al
je 0x16d6
movq -0x48(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x48(%rbp)
movb $0x2d, -0x40(%rbp,%rax)
movq -0x48(%rbp), %rdi
shlq $0x0, %rdi
callq 0x1070
movq %rax, -0x20(%rbp)
xorl %eax, %eax
cmpq -0x20(%rbp), %rax
jne 0x170b
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x1701
movq -0x18(%rbp), %rax
movl $0x80000001, (%rax)     # imm = 0x80000001
movq $0x0, -0x8(%rbp)
jmp 0x175c
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x48(%rbp)
jbe 0x1742
movq -0x48(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movb -0x40(%rbp,%rax), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1713
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x1754
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq