// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/apn/integer/str.c
// Function: int_to_dec
static int int_to_dec(_tt_word *_int, int msb_int, int lshift,
		uint *dec, int msb_dec)
{
	if (msb_int < dec9[DEC9_CROSS_IDX].msb * 2) {
		/* Adopt classic way on small input */
		/* Shift back */
		msb_int = _tt_int_shift_buf(_int, msb_int, -lshift);

		if (msb_int == 1 && _int[0] == 0)
			return 0;

		int len = 0;
		void *workbuf = malloc(msb_int*_tt_word_sz);
		_tt_word *quo = workbuf;

		/* Divide 10^9 till quotient = 0 */
		while (msb_int) {
			memset(quo, 0, msb_int*_tt_word_sz);
			dec[len++] = div_dec9(_int, quo, &msb_int);
			__tt_swap(_int, quo);
		}
		tt_assert_fa(len <= msb_dec);

		free(workbuf);
		return 0;
	}

	/* Divide & Conquer */
	int ret = 0;

	/* Pick max radix */
	int idx = ARRAY_SIZE(dec9) - 1;
	while (idx > DEC9_CROSS_IDX) {
		if (msb_int >= dec9[idx].msb * 2)
			break;
		idx--;
	}

	/* Shift dividend to match normalized divisor */
	msb_int = _tt_int_shift_buf(_int, msb_int, dec9[idx].shift-lshift);

	/* Allocate working buffer */
	int msb_qt = msb_int - dec9[idx].msb + 2;	/* One extra word */
	int msb_rm = dec9[idx].msb + 1;			/* " */
	void *workbuf = calloc(msb_qt+msb_rm, _tt_word_sz);
	if (!workbuf)
		return TT_ENOMEM;
	_tt_word *qt = workbuf;
	_tt_word *rm = qt + msb_qt;

	/* Divide 10^n */
	ret = _tt_int_div_buf(qt, &msb_qt, rm, &msb_rm,
			_int, msb_int, dec9[idx]._int, dec9[idx].msb);
	if (ret)
		goto out;

	/* Combine */
	const int msb_dec9 = 1 << idx;
	ret = int_to_dec(rm, msb_rm, dec9[idx].shift, dec, msb_dec9);
	if (ret)
		goto out;
	ret = int_to_dec(qt, msb_qt, 0, dec+msb_dec9, msb_dec-msb_dec9);

out:
	free(workbuf);
	return ret;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movl %esi, 0x74(%rsp)
movl %edx, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movl %r8d, 0x64(%rsp)
cmpl $0x20, 0x74(%rsp)
jge 0x8339
movq 0x78(%rsp), %rdi
movl 0x74(%rsp), %esi
xorl %edx, %edx
subl 0x70(%rsp), %edx
callq 0x6d10
movl %eax, 0x74(%rsp)
cmpl $0x1, 0x74(%rsp)
jne 0x8243
movq 0x78(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x8243
movl $0x0, 0x84(%rsp)
jmp 0x852c
movl $0x0, 0x60(%rsp)
movl 0x74(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1160
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rsp)
cmpl $0x0, 0x74(%rsp)
je 0x82d4
movq 0x50(%rsp), %rdi
movl 0x74(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0x78(%rsp), %rdi
movq 0x50(%rsp), %rsi
leaq 0x74(%rsp), %rdx
callq 0x8540
movl %eax, %edx
movq 0x68(%rsp), %rax
movl 0x60(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x60(%rsp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq 0x78(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0x8269
jmp 0x82d6
movl 0x60(%rsp), %eax
cmpl 0x64(%rsp), %eax
setle %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x831d
xorl %edi, %edi
leaq 0x16581(%rip), %rsi     # 0x1e87e
leaq 0x9dda(%rip), %rdx      # 0x120de
leaq 0x16514(%rip), %rcx     # 0x1e81f
movl $0x6b, %r8d
movb $0x0, %al
callq 0xe010
callq 0x1060
jmp 0x831f
movq 0x58(%rsp), %rdi
callq 0x1030
movl $0x0, 0x84(%rsp)
jmp 0x852c
movl $0x0, 0x44(%rsp)
movl $0xc, 0x40(%rsp)
cmpl $0x5, 0x40(%rsp)
jle 0x837f
movl 0x74(%rsp), %eax
movslq 0x40(%rsp), %rdx
leaq 0x19940(%rip), %rcx     # 0x21ca0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
shll %ecx
cmpl %ecx, %eax
jl 0x8372
jmp 0x837f
movl 0x40(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x8349
movq 0x78(%rsp), %rdi
movl 0x74(%rsp), %esi
movslq 0x40(%rsp), %rcx
leaq 0x1990c(%rip), %rax     # 0x21ca0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
subl 0x70(%rsp), %edx
callq 0x6d10
movl %eax, 0x74(%rsp)
movl 0x74(%rsp), %eax
movslq 0x40(%rsp), %rdx
leaq 0x198e6(%rip), %rcx     # 0x21ca0
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
subl 0x10(%rcx), %eax
addl $0x2, %eax
movl %eax, 0x3c(%rsp)
movslq 0x40(%rsp), %rcx
leaq 0x198c9(%rip), %rax     # 0x21ca0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
movl 0x3c(%rsp), %eax
addl 0x38(%rsp), %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x1110
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x841a
movl $0xffffffff, 0x84(%rsp) # imm = 0xFFFFFFFF
jmp 0x852c
movq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movslq 0x3c(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rdx
movq 0x78(%rsp), %r8
movl 0x74(%rsp), %r9d
movslq 0x40(%rsp), %rcx
leaq 0x19846(%rip), %rax     # 0x21ca0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %r10
movslq 0x40(%rsp), %rcx
leaq 0x1982f(%rip), %rax     # 0x21ca0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
leaq 0x3c(%rsp), %rsi
leaq 0x38(%rsp), %rcx
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x96f0
movl %eax, 0x44(%rsp)
cmpl $0x0, 0x44(%rsp)
je 0x849f
jmp 0x8517
movl 0x40(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x1c(%rsp)
movq 0x20(%rsp), %rdi
movl 0x38(%rsp), %esi
movslq 0x40(%rsp), %rcx
leaq 0x197dd(%rip), %rax     # 0x21ca0
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %edx
movq 0x68(%rsp), %rcx
movl 0x1c(%rsp), %r8d
callq 0x81e0
movl %eax, 0x44(%rsp)
cmpl $0x0, 0x44(%rsp)
je 0x84e8
jmp 0x8517
movq 0x28(%rsp), %rdi
movl 0x3c(%rsp), %esi
movq 0x68(%rsp), %rcx
movslq 0x1c(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rcx
movl 0x64(%rsp), %r8d
subl 0x1c(%rsp), %r8d
xorl %edx, %edx
callq 0x81e0
movl %eax, 0x44(%rsp)
movq 0x30(%rsp), %rdi
callq 0x1030
movl 0x44(%rsp), %eax
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq
nopl (%rax,%rax)