// File: /workspace/github_c_makefile_star2_O0/phluid61[P]hsf/src/decimal.c
// Function: SH_Decimal__init
SH_Decimal*
SH_Decimal__init(sh_float_t value, int* err) {
	SH_Decimal* obj;
	sh_bool_t n; /*negative?*/
	sh_int_t i;  /*(abs) int val*/
	uint16_t f;  /*fraction part*/

	__cascade(err, (SH_Decimal*)0);

	i = (sh_int_t)value;
	if (i < 0) {
		i = -i;
		n = SH_TRUE;
	} else {
		n = SH_FALSE;
	}

	if (i > SH_INT_C(999999999999)) {
		__raise(err, SH_E_DECIMAL_OUT_OF_BOUNDS);
		return (SH_Decimal*)0;
	}

	/* FIXME: wrong round (to infinity, should be to even) */
	f = (uint16_t)(
			(uint64_t)(
				(sh_float_t)fabs((double)(value * FFACTOR)) + SH_FLOAT_C(0.5)
			) % IFACTOR
		);

	obj = (SH_Decimal*)malloc(sizeof(SH_Decimal));
	if ((SH_Decimal*)0 == obj) {
		__raise(err, SH_E_MALLOC_ERROR);
		return (SH_Decimal*)0;
	}

	obj->value = (n ? SH_FLOAT_C(-1.0) : SH_FLOAT_C(1.0)) * ((sh_float_t)i + ((sh_float_t)f / FFACTOR));
	obj->_neg = n;
	obj->_int = i;
	obj->_frac = f;

	__clear(err);
	return obj;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movsd %xmm0, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x1180
movq -0x18(%rbp), %rcx
xorl %eax, %eax
cmpl (%rcx), %eax
je 0x1180
movq $0x0, -0x8(%rbp)
jmp 0x12e4
cvttsd2si -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jge 0x11a1
xorl %eax, %eax
subq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movb $-0x1, -0x21(%rbp)
jmp 0x11a5
movb $0x0, -0x21(%rbp)
movabsq $0xe8d4a50fff, %rax     # imm = 0xE8D4A50FFF
cmpq %rax, -0x30(%rbp)
jle 0x11d4
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x11c7
movq -0x18(%rbp), %rax
movl $0x120001, (%rax)       # imm = 0x120001
movq $0x0, -0x8(%rbp)
jmp 0x12e4
movsd -0x10(%rbp), %xmm0
movsd 0xe1f(%rip), %xmm1      # 0x2000
mulsd %xmm1, %xmm0
movaps 0xe34(%rip), %xmm1      # 0x2020
pand %xmm1, %xmm0
movsd 0xe10(%rip), %xmm1      # 0x2008
addsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0xdfd(%rip), %xmm1      # 0x2010
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divq %rcx
movw %dx, %ax
movw %ax, -0x32(%rbp)
movl $0x20, %edi
callq 0x1070
movq %rax, -0x20(%rbp)
xorl %eax, %eax
cmpq -0x20(%rbp), %rax
jne 0x1265
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x125b
movq -0x18(%rbp), %rax
movl $0x80000001, (%rax)     # imm = 0x80000001
movq $0x0, -0x8(%rbp)
jmp 0x12e4
movb -0x21(%rbp), %al
testb %al, %al
setne %al
movzbl %al, %eax
movl %eax, %ecx
leaq 0xdb7(%rip), %rax       # 0x2030
movsd (%rax,%rcx,8), %xmm0
cvtsi2sdq -0x30(%rbp), %xmm1
movzwl -0x32(%rbp), %eax
cvtsi2sd %eax, %xmm2
movsd 0xd6c(%rip), %xmm3      # 0x2000
divsd %xmm3, %xmm2
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movb -0x21(%rbp), %cl
movq -0x20(%rbp), %rax
movb %cl, 0x8(%rax)
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movw -0x32(%rbp), %cx
movq -0x20(%rbp), %rax
movw %cx, 0x18(%rax)
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x12dc
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop