// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/apn/decimal/str.c
// Function: parse_coef
static int parse_coef(struct tt_dec *dec, const char *s, int len, int *adjexp,
		int *adjrnd)
{
	int ret = 0;

	/* Check syntax, point position, msb */
	bool nopoint = true;
	int ptpos = len - 1, msb = len - 1;
	for (int i = 0; i < len; i++) {
		if (s[i] == '.') {
			nopoint = false;
			if (ptpos == (len - 1))
				ptpos = i;
			else
				return TT_EINVAL;	/* More than one "." */
		} else if (s[i] >= '0' && s[i] <= '9') {
			if (msb == (len - 1) && s[i] != '0')
				msb = i;
		} else {
			return TT_EINVAL;
		}
	}

	/* Check exponent adjust, significand */
	*adjexp = -(len - ptpos - 1);
	int digs = len - msb;
	if (!nopoint && ptpos > msb)
		digs--;		/* Exclude "." from digits */
	dec->_msb = digs;

	/* Check rounding */
	const char *s2 = s + len - 1;
	if (digs > dec->_prec) {
		tt_info("DEC rounded: %d -> %d", digs, dec->_prec);
		ret = TT_APN_EROUNDED;

		/* Drop trailing digits */
		int drops = digs - dec->_prec;
		dec->_msb -= drops;
		*adjexp += drops;
		while (s2 > s) {
			if (*s2 != '.')
				if (--drops == 0)
					break;
			s2--;
		}
		s2--;
		tt_assert(s2 >= s && drops == 0);

		/* Check round adjust */
		const char *ssig = s2;
		const char *srnd = s2 + 1;
		while (*ssig == '.')
			ssig--;
		while (*srnd == '.')
			srnd++;
		tt_assert(*ssig >= '0' && *ssig <= '9' &&
				*srnd >= '0' && *ssig <= '9');
		*adjrnd = _tt_round((*ssig - '0') & 1, *srnd - '0', 0);
	}

	/* Conversion: digits in [s, s2], may contain one point */
	uint *dig32 = dec->_dig32;
	uint dig = 0, n10 = 1;
	int cnt = 0;
	while (s2 >= s) {
		if (*s2 != '.') {
			dig += (*s2 - '0') * n10;
			cnt++;
			n10 *= 10;
			if (cnt == 9) {
				*dig32++ = dig;
				cnt = 0;
				dig = 0;
				n10 = 1;
			}
		}
		s2--;
	}
	/* Partial digits at MSB */
	if (cnt)
		*dig32 = dig;

	return ret;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movl %edx, 0x6c(%rsp)
movq %rcx, 0x60(%rsp)
movq %r8, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movb $0x1, 0x53(%rsp)
movl 0x6c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x4c(%rsp)
movl 0x6c(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x48(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x32a1
movq 0x70(%rsp), %rax
movslq 0x44(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0x322b
movb $0x0, 0x53(%rsp)
movl 0x4c(%rsp), %eax
movl 0x6c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3219
movl 0x44(%rsp), %eax
movl %eax, 0x4c(%rsp)
jmp 0x3229
movl $0xfffffffe, 0x84(%rsp) # imm = 0xFFFFFFFE
jmp 0x35fe
jmp 0x328f
movq 0x70(%rsp), %rax
movslq 0x44(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
jl 0x327d
movq 0x70(%rsp), %rax
movslq 0x44(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x39, %eax
jg 0x327d
movl 0x48(%rsp), %eax
movl 0x6c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x327b
movq 0x70(%rsp), %rax
movslq 0x44(%rsp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x30, %eax
je 0x327b
movl 0x44(%rsp), %eax
movl %eax, 0x48(%rsp)
jmp 0x328d
movl $0xfffffffe, 0x84(%rsp) # imm = 0xFFFFFFFE
jmp 0x35fe
jmp 0x328f
jmp 0x3291
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x31da
movl 0x6c(%rsp), %eax
subl 0x4c(%rsp), %eax
subl $0x1, %eax
xorl %ecx, %ecx
subl %eax, %ecx
movq 0x60(%rsp), %rax
movl %ecx, (%rax)
movl 0x6c(%rsp), %eax
subl 0x48(%rsp), %eax
movl %eax, 0x40(%rsp)
testb $0x1, 0x53(%rsp)
jne 0x32df
movl 0x4c(%rsp), %eax
cmpl 0x48(%rsp), %eax
jle 0x32df
movl 0x40(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %ecx
movq 0x78(%rsp), %rax
movl %ecx, 0x14(%rax)
movq 0x70(%rsp), %rax
movslq 0x6c(%rsp), %rcx
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, 0x38(%rsp)
movl 0x40(%rsp), %eax
movq 0x78(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jle 0x3527
movl 0x40(%rsp), %ecx
movq 0x78(%rsp), %rax
movl 0x8(%rax), %r8d
movl $0x2, %edi
leaq 0x1b424(%rip), %rsi     # 0x1e750
leaq 0x1b428(%rip), %rdx     # 0x1e75b
movb $0x0, %al
callq 0xe010
movl $0xc9, 0x54(%rsp)
movl 0x40(%rsp), %eax
movq 0x78(%rsp), %rcx
subl 0x8(%rcx), %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %edx
movq 0x78(%rsp), %rax
movl 0x14(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x14(%rax)
movl 0x34(%rsp), %ecx
movq 0x60(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
cmpq 0x70(%rsp), %rax
jbe 0x33ad
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
je 0x339d
movl 0x34(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x34(%rsp)
cmpl $0x0, %eax
jne 0x339b
jmp 0x33ad
jmp 0x339d
movq 0x38(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x3370
movq 0x38(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rcx
xorl %eax, %eax
cmpq 0x70(%rsp), %rcx
movb %al, 0xb(%rsp)
jb 0x33d9
cmpl $0x0, 0x34(%rsp)
sete %al
movb %al, 0xb(%rsp)
movb 0xb(%rsp), %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x3419
xorl %edi, %edi
leaq 0x1b357(%rip), %rsi     # 0x1e750
leaq 0xecde(%rip), %rdx      # 0x120de
leaq 0x1b316(%rip), %rcx     # 0x1e71d
movl $0x3d, %r8d
movb $0x0, %al
callq 0xe010
callq 0x1060
jmp 0x341b
movq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x3450
movq 0x28(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x28(%rsp)
jmp 0x3433
jmp 0x3452
movq 0x20(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x346f
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x3452
jmp 0x3471
movq 0x28(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x30, %ecx
movb %al, 0xa(%rsp)
jl 0x34bc
movq 0x28(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x39, %ecx
movb %al, 0xa(%rsp)
jg 0x34bc
movq 0x20(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x30, %ecx
movb %al, 0xa(%rsp)
jl 0x34bc
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
setle %al
movb %al, 0xa(%rsp)
movb 0xa(%rsp), %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x34fc
xorl %edi, %edi
leaq 0x1b274(%rip), %rsi     # 0x1e750
leaq 0xebfb(%rip), %rdx      # 0x120de
leaq 0x1b233(%rip), %rcx     # 0x1e71d
movl $0x47, %r8d
movb $0x0, %al
callq 0xe010
callq 0x1060
jmp 0x34fe
movq 0x28(%rsp), %rax
movsbl (%rax), %edi
subl $0x30, %edi
andl $0x1, %edi
movq 0x20(%rsp), %rax
movsbl (%rax), %esi
subl $0x30, %esi
xorl %edx, %edx
callq 0xe9f0
movl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, (%rax)
movq 0x78(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x1, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x70(%rsp), %rax
jb 0x35e1
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
je 0x35ce
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
imull 0x10(%rsp), %eax
addl 0x14(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
imull $0xa, 0x10(%rsp), %eax
movl %eax, 0x10(%rsp)
cmpl $0x9, 0xc(%rsp)
jne 0x35cc
movl 0x14(%rsp), %ecx
movq 0x18(%rsp), %rax
movq %rax, %rdx
addq $0x4, %rdx
movq %rdx, 0x18(%rsp)
movl %ecx, (%rax)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x1, 0x10(%rsp)
jmp 0x35ce
movq 0x38(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x354d
cmpl $0x0, 0xc(%rsp)
je 0x35f3
movl 0x14(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %ecx, (%rax)
movl 0x54(%rsp), %eax
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopl (%rax)