// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
movq %rsi, 0x40(%rsp)
movq 0x48(%rsp), %rdi
callq 0x20a0
movq 0x40(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x2f6f
movq 0x48(%rsp), %rax
movw $0x1, (%rax)
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x2f8c
movq 0x40(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x2f8a
movq 0x40(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40(%rsp)
jmp 0x2f8c
movq 0x40(%rsp), %rdi
leaq 0x1b76c(%rip), %rsi     # 0x1e704
callq 0x1050
cmpl $0x0, %eax
jne 0x2fba
movq 0x48(%rsp), %rax
movw $0x2, 0x2(%rax)
movl $0x0, 0x54(%rsp)
jmp 0x317f
movq 0x40(%rsp), %rdi
leaq 0x1b742(%rip), %rsi     # 0x1e708
callq 0x1050
cmpl $0x0, %eax
jne 0x2fe8
movq 0x48(%rsp), %rax
movw $0x1, 0x2(%rax)
movl $0x0, 0x54(%rsp)
jmp 0x317f
jmp 0x2fea
movl $0x0, 0x38(%rsp)
movq 0x40(%rsp), %rax
movslq 0x38(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3037
movq 0x40(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x45, %eax
je 0x3028
movq 0x40(%rsp), %rax
movslq 0x38(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x65, %eax
jne 0x302a
jmp 0x3037
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x2ff2
cmpl $0x0, 0x38(%rsp)
jne 0x3043
jmp 0x316d
movl $0x0, 0x34(%rsp)
movl $0x0, 0x30(%rsp)
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x38(%rsp), %edx
leaq 0x34(%rsp), %rcx
leaq 0x30(%rsp), %r8
callq 0x3190
movl %eax, 0x3c(%rsp)
cmpl $0x0, 0x3c(%rsp)
jge 0x3080
jmp 0x316d
movl $0x0, 0x2c(%rsp)
movq 0x40(%rsp), %rax
movslq 0x38(%rsp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x30bf
movq 0x40(%rsp), %rdi
movslq 0x38(%rsp), %rax
addq %rax, %rdi
addq $0x1, %rdi
leaq 0x2c(%rsp), %rsi
callq 0xde60
cmpl $0x0, %eax
je 0x30bd
jmp 0x316d
jmp 0x30bf
movl 0x2c(%rsp), %ecx
addl 0x34(%rsp), %ecx
movq 0x48(%rsp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x0, 0x30(%rsp)
je 0x313c
movl $0x1, 0x28(%rsp)
movq 0x48(%rsp), %rax
movw (%rax), %ax
movw %ax, 0x8(%rsp)
movw $0x0, 0xa(%rsp)
movq 0x48(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0xc(%rsp)
movl $0x1, 0x10(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x4, 0x18(%rsp)
movl $0x1, 0x1c(%rsp)
leaq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rdi
movq 0x48(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x3af0
movq 0x48(%rsp), %rdi
callq 0x3610
testb $0x1, %al
jne 0x314c
jmp 0x3163
movq 0x48(%rsp), %rax
cmpl $0x0, 0x4(%rax)
jle 0x3163
movq 0x48(%rsp), %rax
movl $0x0, 0x4(%rax)
movl 0x3c(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0x317f
movq 0x48(%rsp), %rdi
callq 0x20a0
movl $0xfffffffe, 0x54(%rsp) # imm = 0xFFFFFFFE
movl 0x54(%rsp), %eax
addq $0x58, %rsp
retq
nopl (%rax,%rax)