// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x24bc
movzbl (%r14), %eax
cmpl $0x2b, %eax
je 0x2c40
cmpl $0x2d, %eax
jne 0x2c43
movw $0x1, (%rbx)
incq %r14
leaq 0x14bba(%rip), %rsi     # 0x17804
movq %r14, %rdi
callq 0x1040
testl %eax, %eax
je 0x2d78
leaq 0x14ba7(%rip), %rsi     # 0x17808
movq %r14, %rdi
callq 0x1040
testl %eax, %eax
je 0x2d80
xorl %r15d, %r15d
movzbl (%r14,%r15), %eax
testl %eax, %eax
je 0x2c8c
cmpl $0x45, %eax
je 0x2c8c
cmpl $0x65, %eax
je 0x2c8c
incq %r15
jmp 0x2c74
testq %r15, %r15
je 0x2e79
leal -0x1(%r15), %ebp
movb $0x1, %al
xorl %ecx, %ecx
movl %ebp, %edx
movl %edx, %edx
movl %ebp, %ebp
movb (%r14,%rcx), %sil
cmpb $0x2e, %sil
jne 0x2cbf
incq %rdx
cmpl %r15d, %edx
jne 0x2e79
xorl %eax, %eax
movl %ecx, %edx
jmp 0x2ce1
leal -0x30(%rsi), %edi
cmpb $0x9, %dil
ja 0x2e79
leaq 0x1(%rbp), %rdi
cmpb $0x30, %sil
movl %ecx, %esi
cmovel %ebp, %esi
cmpl %r15d, %edi
cmovnel %ebp, %esi
movl %esi, %ebp
incq %rcx
cmpq %rcx, %r15
jne 0x2c9f
notb %al
movl %edx, %ecx
subq %r15, %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
cmpl %ebp, %edx
setg %cl
andb %al, %cl
movzbl %cl, %r12d
negl %r12d
movl %r12d, %ecx
subl %ebp, %ecx
addq %r15, %rcx
movl %ecx, 0x14(%rbx)
movl %r15d, %eax
leaq (%r14,%rax), %r13
decq %r13
movl 0x8(%rbx), %r8d
cmpl %r8d, %ecx
jle 0x2d8d
leaq 0x14b1d(%rip), %rsi     # 0x17848
leaq 0x14b21(%rip), %rdx     # 0x17853
movl $0x2, %edi
xorl %eax, %eax
callq 0x8cca
movl 0x8(%rbx), %ecx
movl %r12d, %eax
subl %ecx, %eax
subl %ebp, %eax
addq %r15, %rax
addl 0x14(%rbx), %ecx
addl %ebp, %ecx
subl %r12d, %ecx
subl %r15d, %ecx
movl %ecx, 0x14(%rbx)
movl %eax, %ecx
cmpq %r14, %r13
jbe 0x2d96
cmpb $0x2e, (%r13)
je 0x2d6b
decl %ecx
je 0x2d94
decq %r13
cmpq %r14, %r13
ja 0x2d60
movq %r14, %r13
jmp 0x2d96
movw $0x2, 0x2(%rbx)
jmp 0x2d86
movw $0x1, 0x2(%rbx)
xorl %ebp, %ebp
jmp 0x2e86
xorl %ebp, %ebp
movb $0x1, %r8b
jmp 0x2e02
xorl %ecx, %ecx
leaq -0x1(%r13), %r12
cmpq %r14, %r12
jb 0x2f14
testl %ecx, %ecx
jne 0x2f14
movq 0x8(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x8(%rsp)
movq %r12, %rax
movzbl (%rax), %edi
decq %rax
cmpl $0x2e, %edi
je 0x2dba
movzbl (%r13), %esi
incq %r13
cmpl $0x2e, %esi
je 0x2dc5
leal -0x30(%rdi), %eax
cmpb $0x9, %al
ja 0x2f0f
cmpb $0x30, %sil
jl 0x2f0f
andl $0x1, %edi
addl $-0x30, %esi
xorl %edx, %edx
callq 0x90d6
testl %eax, %eax
sete %r8b
movl $0xc9, %ebp
movq %r12, %r13
cmpq %r14, %r13
jb 0x2e52
movq 0x18(%rbx), %rax
movl $0x1, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movsbl (%r13), %edi
cmpl $0x2e, %edi
je 0x2e32
addl $-0x30, %edi
imull %esi, %edi
addl %edi, %ecx
incl %edx
cmpl $0x9, %edx
je 0x2e3c
addl %esi, %esi
leal (%rsi,%rsi,4), %esi
decq %r13
cmpq %r14, %r13
jae 0x2e14
jmp 0x2e4c
movl %ecx, (%rax)
addq $0x4, %rax
decq %r13
cmpq %r14, %r13
jae 0x2e0b
jmp 0x2e52
testl %edx, %edx
je 0x2e52
movl %ecx, (%rax)
movl $0x0, 0x4(%rsp)
cmpb $0x0, (%r14,%r15)
je 0x2e97
movl %r8d, %r12d
leaq (%r14,%r15), %rdi
incq %rdi
leaq 0x4(%rsp), %rsi
callq 0x8c42
testl %eax, %eax
je 0x2e9b
movq %rbx, %rdi
callq 0x24bc
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x2ea2
movl 0x4(%rsp), %eax
movl %r12d, %r8d
addl 0x8(%rsp), %eax
movl %eax, 0x4(%rbx)
testb %r8b, %r8b
jne 0x2ee7
leaq 0x14(%rsp), %rcx
movl $0x1, (%rcx)
movzwl (%rbx), %esi
leaq 0x18(%rsp), %rdx
movw %si, (%rdx)
movw $0x0, 0x2(%rdx)
movl %eax, 0x4(%rdx)
movaps 0x14b7c(%rip), %xmm0    # 0x17a50
movups %xmm0, 0x8(%rdx)
movq %rcx, 0x18(%rdx)
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x3168
cmpl $0x1, 0x14(%rbx)
jne 0x2e86
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax)
jne 0x2e86
cmpw $0x0, 0x2(%rbx)
jne 0x2e86
cmpl $0x0, 0x4(%rbx)
jle 0x2e86
movl $0x0, 0x4(%rbx)
jmp 0x2e86
callq 0x1272
callq 0x129a