// File: /workspace/github_c_makefile_star2_O1/cyb70289[P]tt/src/apn/decimal/str.c
// Function: tt_dec_from_string
int tt_dec_from_string(struct tt_dec *dec, const char *str)
{
	int ret;

	_tt_dec_zero(dec);

	/* Check leading "+", "-" */
	if (*str == '-') {
		dec->_sign = 1;
		str++;
	} else if (*str == '+') {
		str++;
	}

	/* Check "NaN", "Inf" */
	if (strcasecmp(str, "nan") == 0) {
		dec->_inf_nan = TT_DEC_NAN;
		return 0;
	} else if (strcasecmp(str, "inf") == 0) {
		dec->_inf_nan = TT_DEC_INF;
		return 0;
	}

	/* Cut coefficient */
	int epos = 0;
	while (str[epos]) {
		if (str[epos] == 'E' || str[epos] == 'e')
			break;
		epos++;
	}
	if (epos == 0)
		goto invalid;

	/* Parse coefficient */
	int adjexp = 0, adjrnd = 0;
	ret = parse_coef(dec, str, epos, &adjexp, &adjrnd);
	if (ret < 0)
		goto invalid;

	/* Parse exponent */
	int _exp = 0;
	if (str[epos]) {
		if (_tt_atoi(str+epos+1, &_exp))
			goto invalid;
	}
	dec->_exp = _exp + adjexp;

	/* Rounding */
	if (adjrnd) {
		uint one = 1;
		struct tt_dec dec_1 = {
			._sign = dec->_sign,
			._inf_nan = 0,
			._exp = dec->_exp,
			._prec = 1,
			._digsz = sizeof(one),
			._msb = 1,
			._dig32 = &one,
		};
		tt_dec_add(dec, dec, &dec_1);
	}

	/* Check zero */
	if (_tt_dec_is_zero(dec) && dec->_exp > 0)
		dec->_exp = 0;

	return ret;

invalid:
	_tt_dec_zero(dec);
	return TT_EINVAL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x2540
movzbl (%r15), %eax
cmpl $0x2b, %eax
je 0x2cc0
cmpl $0x2d, %eax
jne 0x2cc3
movw $0x1, (%rbx)
incq %r15
leaq 0x14b3a(%rip), %rsi     # 0x17804
movq %r15, %rdi
callq 0x1040
testl %eax, %eax
je 0x2d69
leaq 0x14b27(%rip), %rsi     # 0x17808
movq %r15, %rdi
callq 0x1040
testl %eax, %eax
je 0x2d71
xorl %r12d, %r12d
movzbl (%r15,%r12), %eax
testl %eax, %eax
je 0x2d0c
cmpl $0x45, %eax
je 0x2d0c
cmpl $0x65, %eax
je 0x2d0c
incq %r12
jmp 0x2cf4
testq %r12, %r12
je 0x2f2d
leal -0x1(%r12), %ebp
movb $0x1, %sil
xorl %edx, %edx
movl %ebp, %ecx
movb $0x1, %al
movb (%r15,%rdx), %dil
cmpb $0x2e, %dil
jne 0x2d3d
movl %ecx, %eax
incq %rax
cmpl %r12d, %eax
jne 0x2d7e
xorl %eax, %eax
movl %edx, %ecx
jmp 0x2d5b
leal -0x30(%rdi), %r8d
cmpb $0x9, %r8b
ja 0x2d80
movl %ebp, %esi
incq %rsi
cmpb $0x30, %dil
movl %edx, %edi
cmovel %ebp, %edi
cmpl %r12d, %esi
cmovel %edi, %ebp
incq %rdx
cmpq %r12, %rdx
setb %sil
jne 0x2d23
jmp 0x2d80
movw $0x2, 0x2(%rbx)
jmp 0x2d77
movw $0x1, 0x2(%rbx)
xorl %ebp, %ebp
jmp 0x2f3a
xorl %eax, %eax
testb $0x1, %sil
je 0x2d96
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
xorl %r13d, %r13d
xorl %r8d, %r8d
jmp 0x2eff
movl %ecx, %ecx
notb %al
movq %rcx, %rdx
subq %r12, %rdx
incq %rdx
movq %rdx, 0x10(%rsp)
cmpl %ebp, %ecx
setg %cl
andb %al, %cl
movzbl %cl, %r13d
negl %r13d
movl %r13d, %edx
subl %ebp, %edx
leaq (%rdx,%r12), %rcx
movl %ecx, 0x14(%rbx)
movl %r12d, %eax
leaq (%r15,%rax), %r14
decq %r14
movl 0x8(%rbx), %r8d
cmpl %r8d, %ecx
jle 0x2e32
leaq 0x14a6c(%rip), %rsi     # 0x17848
movq %rdx, 0x18(%rsp)
leaq 0x14a6b(%rip), %rdx     # 0x17853
movl $0x2, %edi
xorl %eax, %eax
callq 0x8c46
movq 0x18(%rsp), %rcx
movl 0x8(%rbx), %eax
subl %eax, %ecx
addq %r12, %rcx
addl %eax, %ebp
addl 0x14(%rbx), %ebp
subl %r13d, %ebp
subl %r12d, %ebp
movl %ebp, 0x14(%rbx)
movl %ecx, %eax
cmpq %r15, %r14
jbe 0x2e3e
movq 0x10(%rsp), %r13
cmpb $0x2e, (%r14)
je 0x2e25
decl %eax
je 0x2e45
decq %r14
cmpq %r15, %r14
ja 0x2e1b
movq %r15, %r14
jmp 0x2e47
xorl %r8d, %r8d
xorl %ebp, %ebp
movq 0x10(%rsp), %r13
jmp 0x2ea6
movq 0x10(%rsp), %r13
jmp 0x2e47
xorl %eax, %eax
leaq -0x1(%r14), %rdx
cmpq %r15, %rdx
jb 0x2fbd
testl %eax, %eax
jne 0x2fbd
addl %ecx, %r13d
movq %rdx, %rax
movzbl (%rax), %edi
decq %rax
cmpl $0x2e, %edi
je 0x2e62
movzbl (%r14), %esi
incq %r14
cmpl $0x2e, %esi
je 0x2e6d
leal -0x30(%rdi), %eax
cmpb $0x9, %al
ja 0x2fb8
cmpb $0x30, %sil
jl 0x2fb8
movq %rdx, %r14
andl $0x1, %edi
addl $-0x30, %esi
xorl %edx, %edx
callq 0x9052
movl %eax, %r8d
movl $0xc9, %ebp
movq 0x18(%rbx), %rax
cmpq %r15, %r14
jae 0x2eb5
movb $0x1, %dl
xorl %ecx, %ecx
jmp 0x2ef9
movl $0x1, %edx
xorl %esi, %esi
xorl %ecx, %ecx
movsbl (%r14), %edi
cmpl $0x2e, %edi
je 0x2eec
addl $-0x30, %edi
imull %edx, %edi
addl %edi, %ecx
incl %esi
cmpl $0x9, %esi
je 0x2edd
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
jmp 0x2eec
movl %ecx, (%rax)
addq $0x4, %rax
movl $0x1, %edx
xorl %ecx, %ecx
xorl %esi, %esi
decq %r14
cmpq %r15, %r14
jae 0x2ebe
testl %esi, %esi
sete %dl
testb %dl, %dl
jne 0x2eff
movl %ecx, (%rax)
testl %ebp, %ebp
js 0x2f2d
movl $0x0, 0xc(%rsp)
cmpb $0x0, (%r15,%r12)
je 0x2f4b
leaq (%r15,%r12), %rdi
incq %rdi
leaq 0xc(%rsp), %rsi
movl %r8d, %r14d
callq 0x8bbe
movl %r14d, %r8d
testl %eax, %eax
je 0x2f4b
movq %rbx, %rdi
callq 0x2540
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl 0xc(%rsp), %r13d
movl %r13d, 0x4(%rbx)
testl %r8d, %r8d
je 0x2f93
leaq 0x24(%rsp), %rax
movl $0x1, (%rax)
movzwl (%rbx), %ecx
leaq 0x28(%rsp), %rdx
movw %cx, (%rdx)
movw $0x0, 0x2(%rdx)
movl %r13d, 0x4(%rdx)
movaps 0x14ad0(%rip), %xmm0    # 0x17a50
movups %xmm0, 0x8(%rdx)
movq %rax, 0x18(%rdx)
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x3214
cmpl $0x1, 0x14(%rbx)
jne 0x2f3a
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax)
jne 0x2f3a
cmpw $0x0, 0x2(%rbx)
jne 0x2f3a
cmpl $0x0, 0x4(%rbx)
jle 0x2f3a
movl $0x0, 0x4(%rbx)
jmp 0x2f3a
callq 0x1272
callq 0x129a