// File: /workspace/github_c_makefile_star2_O3/cyb70289[P]tt/src/apn/integer/basic.c
// Function: div_buf_classic
static int div_buf_classic(_tt_word *qt, int *msb_qt, _tt_word *rm, int *msb_rm,
		const _tt_word *dd, int msb_dd, const _tt_word *ds, int msb_ds)
{
	/* Allocate working buffer */
	const int sz_tmpmul = msb_ds + 1;
	_tt_word *workbuf = malloc((msb_dd+sz_tmpmul)*_tt_word_sz);
	if (workbuf == NULL)
		return TT_ENOMEM;
	_tt_word *_dd = workbuf;
	_tt_word *tmpmul = _dd + msb_dd;

	memcpy(_dd, dd, msb_dd*_tt_word_sz);

	int qt_idx = msb_dd - msb_ds - 1, topmsb = msb_ds;
	_tt_word *dd_top = _dd + msb_dd - msb_ds;

	*msb_qt = msb_dd - msb_ds;
	if (_tt_int_cmp_buf(dd_top, msb_ds, ds, msb_ds) >= 0) {
		/* First digit */
		qt[(*msb_qt)++] = 1;
		topmsb = _tt_int_sub_buf(dd_top, msb_ds, ds, msb_ds);
	}
	if (*msb_qt == 0)
		*msb_qt = 1;

	while (qt_idx >= 0) {
		if (!(topmsb == 1 && *dd_top == 0))
			topmsb++;
		dd_top--;

		_tt_word q = guess_quotient(dd_top, topmsb, ds, msb_ds);
		if (q) {
			memset(tmpmul, 0, sz_tmpmul*_tt_word_sz);
			int mulmsb = mul_buf_classic(tmpmul, ds, msb_ds, &q, 1);

			while (_tt_int_cmp_buf(tmpmul, mulmsb, dd_top, topmsb)
					> 0) {
				mulmsb = _tt_int_sub_buf(tmpmul, mulmsb,
						ds, msb_ds);
				q--;
			}
			tt_assert_fa(topmsb >= mulmsb);
			topmsb = _tt_int_sub_buf(dd_top, topmsb,
					tmpmul, mulmsb);
		}
		qt[qt_idx] = q;
		qt_idx--;
	}
	tt_assert_fa(dd_top == _dd);

	/* Remainder */
	tt_assert_fa(topmsb <= msb_ds);
	memcpy(rm, _dd, topmsb*_tt_word_sz);
	*msb_rm = topmsb;

	free(workbuf);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r13d
movq %r8, %rbp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, 0x28(%rsp)
movl 0x88(%rsp), %r15d
leal (%r15,%r13), %eax
incl %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1140
testq %rax, %rax
je 0x67fb
movq %r14, 0x30(%rsp)
leal 0x1(%r15), %ecx
movl %ecx, 0x10(%rsp)
movq %rbp, %rsi
movq %rax, %rbp
movq %rbx, 0x38(%rsp)
movslq %r13d, %rbx
leaq (%rax,%rbx,8), %r14
leal (,%r13,8), %eax
movslq %eax, %rdx
movq %rbp, %rdi
callq 0x1120
subl %r15d, %r13d
movslq %r15d, %rax
movq %rax, 0x40(%rsp)
leaq (,%rax,8), %rcx
movq %r14, 0x18(%rsp)
subq %rcx, %r14
movl %r13d, (%r12)
movl %r15d, %eax
movq %rbx, 0x8(%rsp)
leaq (,%rbx,8), %rdx
subq %rcx, %rdx
movq %rbp, 0x20(%rsp)
leaq (%rdx,%rbp), %rcx
addq $-0x8, %rcx
testl %eax, %eax
jle 0x65c9
movq (%rcx,%rax,8), %rdx
movq 0x80(%rsp), %rsi
movq -0x8(%rsi,%rax,8), %rsi
cmpq %rsi, %rdx
ja 0x65c9
decq %rax
cmpq %rsi, %rdx
jae 0x6595
movq %r12, %r15
movl %r13d, %ebx
movl 0x88(%rsp), %ebp
movl %ebp, %r12d
jmp 0x6602
leal 0x1(%r13), %ebx
movq %r12, %r15
movl %ebx, (%r12)
movslq %r13d, %rax
movq 0x28(%rsp), %rcx
movq $0x1, (%rcx,%rax,8)
movq %r14, %rdi
movl 0x88(%rsp), %ebp
movl %ebp, %esi
movq 0x80(%rsp), %rdx
movl %ebp, %ecx
callq 0x58f2
movl %eax, %r12d
testl %ebx, %ebx
jne 0x660d
movl $0x1, (%r15)
testl %r13d, %r13d
jle 0x67c0
movl 0x10(%rsp), %eax
shll $0x3, %eax
cltq
movq %rax, 0x10(%rsp)
movl %r13d, %edi
movq 0x20(%rsp), %rax
movq 0x8(%rsp), %rcx
leaq (%rax,%rcx,8), %r15
addq $-0x8, %r15
movq %r14, %rbx
cmpl $0x1, %r12d
jne 0x664c
cmpq $0x0, (%rbx)
je 0x67b1
incl %r12d
leaq -0x8(%rbx), %r14
cmpl %ebp, %r12d
jle 0x666c
movq %rdi, 0x8(%rsp)
cmpl %ebp, %r12d
jne 0x669b
movq $0x1, (%rsp)
jmp 0x66eb
jl 0x6694
movl %r12d, %eax
testl %eax, %eax
jle 0x6658
movq -0x10(%rbx,%rax,8), %rcx
movq 0x80(%rsp), %rdx
movq -0x8(%rdx,%rax,8), %rdx
cmpq %rdx, %rcx
ja 0x6658
decq %rax
cmpq %rdx, %rcx
jae 0x6671
xorl %eax, %eax
jmp 0x6794
movslq %r12d, %rax
movq -0x8(%r14,%rax,8), %rdi
movq %rdi, %rsi
shrq %rsi
shlq $0x3f, %rdi
orq -0x10(%r14,%rax,8), %rdi
movq 0x80(%rsp), %rax
movq 0x40(%rsp), %rcx
movq -0x8(%rax,%rcx,8), %rdx
xorl %ecx, %ecx
callq 0xaad0
movabsq $-0x7fffffffffffffff, %rcx # imm = 0x8000000000000001
cmpq %rcx, %rax
jae 0x680f
movq %rax, (%rsp)
testq %rax, %rax
je 0x67bc
movq %rbp, %r13
movq %r14, %rbp
movq 0x18(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
callq 0x10e0
movq %r14, %rdi
movq %rbp, %r14
movq 0x80(%rsp), %rsi
movl %r13d, %edx
movq %rsp, %rcx
movl $0x1, %r8d
callq 0x5aa0
movq (%rsp), %rbp
cmpl %r12d, %eax
jle 0x6751
movq 0x18(%rsp), %rdi
movl %eax, %esi
movq 0x80(%rsp), %rdx
movl 0x88(%rsp), %ecx
callq 0x58f2
decq %rbp
movq %rbp, (%rsp)
jmp 0x6728
jl 0x676f
movl %eax, %ecx
testl %ecx, %ecx
jle 0x676f
movq (%r15,%rcx,8), %rdx
movq -0x10(%rbx,%rcx,8), %rsi
cmpq %rsi, %rdx
ja 0x672d
decq %rcx
cmpq %rsi, %rdx
jae 0x6755
movq %r14, %rdi
movl %r12d, %esi
movq 0x18(%rsp), %rdx
movl %eax, %ecx
callq 0x58f2
movl %eax, %r12d
movq (%rsp), %rax
movl 0x88(%rsp), %ebp
movq 0x8(%rsp), %rdi
leaq -0x1(%rdi), %rcx
movl %ecx, %edx
movq 0x28(%rsp), %rsi
movq %rax, (%rsi,%rdx,8)
cmpl $0x1, %edi
movq %rcx, %rdi
jg 0x6639
jmp 0x67c0
movl $0x1, %r12d
jmp 0x664f
xorl %eax, %eax
jmp 0x678f
movq 0x20(%rsp), %rbx
cmpq %rbx, %r14
jne 0x6814
cmpl %ebp, %r12d
jg 0x6819
leal (,%r12,8), %eax
movslq %eax, %rdx
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x1120
movq 0x38(%rsp), %rax
movl %r12d, (%rax)
movq %rbx, %rdi
callq 0x1030
xorl %eax, %eax
jmp 0x6800
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1826
callq 0x1850
callq 0x187a