// File: /workspace/github_c_makefile_star2_O2/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 0x1b01
movzbl (%r14), %eax
cmpl $0x2b, %eax
je 0x2224
cmpl $0x2d, %eax
jne 0x2227
movw $0x1, (%rbx)
incq %r14
leaq 0x145b6(%rip), %rsi     # 0x167e4
movq %r14, %rdi
callq 0x1040
testl %eax, %eax
je 0x22cd
leaq 0x145a3(%rip), %rsi     # 0x167e8
movq %r14, %rdi
callq 0x1040
testl %eax, %eax
je 0x22d5
xorl %r15d, %r15d
movzbl (%r14,%r15), %eax
testl %eax, %eax
je 0x2270
cmpl $0x45, %eax
je 0x2270
cmpl $0x65, %eax
je 0x2270
incq %r15
jmp 0x2258
testq %r15, %r15
je 0x244e
leal -0x1(%r15), %edx
movb $0x1, %al
xorl %ecx, %ecx
movl %edx, %ebp
movl %edx, %r12d
cmpq %rcx, %r15
je 0x22e2
movb (%r14,%rcx), %sil
cmpb $0x2e, %sil
jne 0x22a7
incq %r12
cmpl %r15d, %r12d
jne 0x244e
xorl %eax, %eax
movl %ecx, %edx
jmp 0x22c8
leal -0x30(%rsi), %edi
cmpb $0x9, %dil
ja 0x244e
movl %ebp, %edi
incq %rdi
cmpb $0x30, %sil
movl %ecx, %esi
cmovel %ebp, %esi
cmpl %r15d, %edi
cmovel %esi, %ebp
incq %rcx
jmp 0x2283
movw $0x2, 0x2(%rbx)
jmp 0x22db
movw $0x1, 0x2(%rbx)
xorl %ebp, %ebp
jmp 0x2459
subq %r15, %r12
incq %r12
cmpl %ebp, %edx
setg %cl
notb %al
andb %cl, %al
movq %rbx, %rdx
movzbl %al, %ebx
negl %ebx
movl %ebx, %ecx
subl %ebp, %ecx
addq %r15, %rcx
movl %ecx, 0x14(%rdx)
movl %r15d, %eax
leaq (%r14,%rax), %r13
decq %r13
movl 0x8(%rdx), %r8d
cmpl %r8d, %ecx
jle 0x236c
leaq 0x1450b(%rip), %rsi     # 0x16828
movq %rdx, 0x8(%rsp)
leaq 0x1450a(%rip), %rdx     # 0x16833
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x7de8
movq 0x8(%rsp), %rdx
movl 0x8(%rdx), %ecx
movl %ebx, %eax
subl %ecx, %eax
subl %ebp, %eax
addl %r15d, %eax
addl 0x14(%rdx), %ecx
addl %ebp, %ecx
subl %ebx, %ecx
subl %r15d, %ecx
movl %ecx, 0x14(%rdx)
movq %rdx, %rbx
addl %eax, %r12d
cmpq %r14, %r13
jbe 0x2378
cmpb $0x2e, (%r13)
je 0x2367
decl %eax
je 0x2376
decq %r13
jmp 0x2357
xorl %ebp, %ebp
movb $0x1, %r9b
movq %rdx, %rbx
jmp 0x23d8
xorl %eax, %eax
leaq -0x1(%r13), %rcx
cmpq %r14, %rcx
jb 0x24f6
testl %eax, %eax
jne 0x24f6
movq %rcx, %rax
movzbl (%rax), %edi
decq %rax
cmpl $0x2e, %edi
je 0x2390
movzbl (%r13), %esi
incq %r13
cmpl $0x2e, %esi
je 0x239b
leal -0x30(%rdi), %eax
cmpb $0x9, %al
ja 0x24dd
cmpb $0x30, %sil
jl 0x24dd
movq %rcx, %r13
andl $0x1, %edi
addl $-0x30, %esi
xorl %edx, %edx
callq 0x829c
testl %eax, %eax
sete %r9b
movl $0xc9, %ebp
movq 0x18(%rbx), %rax
pushq $0x1
popq %rcx
xorl %r8d, %r8d
movl %ecx, %edx
xorl %esi, %esi
cmpq %r14, %r13
jb 0x2423
movsbl (%r13), %edi
cmpl $0x2e, %edi
jne 0x23fa
movl %r8d, %edi
jmp 0x241b
addl $-0x30, %edi
imull %edx, %edi
addl %r8d, %edi
incl %esi
cmpl $0x9, %esi
je 0x240f
imull $0xa, %edx, %edx
jmp 0x241b
movl %edi, (%rax)
addq $0x4, %rax
xorl %edi, %edi
movl %ecx, %edx
xorl %esi, %esi
decq %r13
movl %edi, %r8d
jmp 0x23e6
testl %esi, %esi
je 0x242a
movl %r8d, (%rax)
andl $0x0, 0x4(%rsp)
cmpb $0x0, (%r14,%r15)
je 0x246a
movl %r9d, %r13d
leaq (%r14,%r15), %rdi
incq %rdi
leaq 0x4(%rsp), %rsi
callq 0x7d55
testl %eax, %eax
je 0x246e
movq %rbx, %rdi
callq 0x1b01
pushq $-0x2
popq %rbp
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x2475
movl 0x4(%rsp), %eax
movl %r13d, %r9d
addl %r12d, %eax
movl %eax, 0x4(%rbx)
testb %r9b, %r9b
jne 0x24b8
leaq 0x14(%rsp), %rcx
movl $0x1, (%rcx)
movzwl (%rbx), %esi
leaq 0x18(%rsp), %rdx
movw %si, (%rdx)
andw $0x0, 0x2(%rdx)
movl %eax, 0x4(%rdx)
movaps 0x1459b(%rip), %xmm0    # 0x16a40
movups %xmm0, 0x8(%rdx)
movq %rcx, 0x18(%rdx)
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x2760
cmpl $0x1, 0x14(%rbx)
jne 0x2459
movq 0x18(%rbx), %rax
cmpl $0x0, (%rax)
jne 0x2459
cmpw $0x0, 0x2(%rbx)
jne 0x2459
cmpl $0x0, 0x4(%rbx)
jle 0x2459
andl $0x0, 0x4(%rbx)
jmp 0x2459
leaq 0x14344(%rip), %rsi     # 0x16828
leaq 0x7b97(%rip), %rdx      # 0xa082
leaq 0x1430b(%rip), %rcx     # 0x167fd
pushq $0x47
jmp 0x250d
leaq 0x1432b(%rip), %rsi     # 0x16828
leaq 0x7b7e(%rip), %rdx      # 0xa082
leaq 0x142f2(%rip), %rcx     # 0x167fd
pushq $0x3d
popq %r8
xorl %edi, %edi
xorl %eax, %eax
callq 0x7de8
callq 0x1050