// File: /workspace/github_c_makefile_star2_O1/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, (%rsp)
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %rbp
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 0x6817
movq %rax, %r12
movq %rbx, 0x30(%rsp)
movq %r14, 0x38(%rsp)
leal 0x1(%r15), %eax
movl %eax, 0x18(%rsp)
movslq %r13d, %r14
leaq (%r12,%r14,8), %rbx
leal (,%r13,8), %eax
movslq %eax, %rdx
movq %r12, %rdi
movq (%rsp), %rsi
callq 0x1120
subl %r15d, %r13d
movslq %r15d, %rax
movq %rax, 0x40(%rsp)
leaq (,%rax,8), %rcx
movq %rbx, (%rsp)
subq %rcx, %rbx
movl %r13d, (%rbp)
movl %r15d, %eax
movq %r14, 0x20(%rsp)
leaq (,%r14,8), %rdx
subq %rcx, %rdx
leaq (%rdx,%r12), %rcx
addq $-0x8, %rcx
movq %r12, 0x10(%rsp)
testl %eax, %eax
jle 0x6617
movq (%rcx,%rax,8), %rdx
movq 0x80(%rsp), %rsi
movq -0x8(%rsi,%rax,8), %rsi
cmpq %rsi, %rdx
ja 0x6617
decq %rax
cmpq %rsi, %rdx
jae 0x65e8
movl 0x88(%rsp), %r15d
movl %r15d, %r12d
jmp 0x664f
leal 0x1(%r13), %eax
movl %eax, (%rbp)
movslq %r13d, %rax
movq 0x28(%rsp), %rcx
movq $0x1, (%rcx,%rax,8)
movq %rbx, %rdi
movl 0x88(%rsp), %r15d
movl %r15d, %esi
movq 0x80(%rsp), %rdx
movl %r15d, %ecx
callq 0x593d
movl %eax, %r12d
cmpl $0x0, (%rbp)
jne 0x665c
movl $0x1, (%rbp)
testl %r13d, %r13d
jle 0x681e
movl 0x18(%rsp), %eax
shll $0x3, %eax
cltq
movq %rax, 0x18(%rsp)
movl %r13d, %r14d
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
leaq (%rax,%rcx,8), %rbp
addq $-0x8, %rbp
cmpl $0x1, %r12d
jne 0x6698
cmpq $0x0, (%rbx)
je 0x680c
incl %r12d
leaq -0x8(%rbx), %r13
cmpl %r15d, %r12d
jle 0x66f2
movl $0x1, %eax
cmpl %r15d, %r12d
je 0x671c
movslq %r12d, %rax
movq -0x8(%r13,%rax,8), %rdi
movq %rdi, %rsi
shrq %rsi
shlq $0x3f, %rdi
orq -0x10(%r13,%rax,8), %rdi
movq 0x80(%rsp), %rax
movq 0x40(%rsp), %rcx
movq -0x8(%rax,%rcx,8), %rdx
xorl %ecx, %ecx
callq 0xa870
movabsq $-0x7fffffffffffffff, %rcx # imm = 0x8000000000000001
cmpq %rcx, %rax
jb 0x671c
jmp 0x6870
jl 0x671a
movl %r12d, %eax
testl %eax, %eax
jle 0x66a4
movq -0x10(%rbx,%rax,8), %rcx
movq 0x80(%rsp), %rdx
movq -0x8(%rdx,%rax,8), %rdx
cmpq %rdx, %rcx
ja 0x66a4
decq %rax
cmpq %rdx, %rcx
jae 0x66f7
xorl %eax, %eax
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x67e6
movq %r12, 0x20(%rsp)
movq %r14, %r12
movq %r13, %r14
movq %r15, %r13
movq (%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x10e0
movq %r15, %rdi
movq 0x80(%rsp), %rsi
movl %r13d, %edx
movq %r14, %r13
movq %r12, %r14
movq 0x20(%rsp), %r12
leaq 0x8(%rsp), %rcx
movl $0x1, %r8d
callq 0x5ae5
movq 0x8(%rsp), %r15
cmpl %r12d, %eax
jle 0x67a2
movq (%rsp), %rdi
movl %eax, %esi
movq 0x80(%rsp), %rdx
movl 0x88(%rsp), %ecx
callq 0x593d
decq %r15
movq %r15, 0x8(%rsp)
jmp 0x6779
jl 0x67c1
movl %eax, %ecx
testl %ecx, %ecx
jle 0x67c1
movq (%rbp,%rcx,8), %rdx
movq -0x10(%rbx,%rcx,8), %rsi
cmpq %rsi, %rdx
ja 0x677e
decq %rcx
cmpq %rsi, %rdx
jae 0x67a6
cmpl %r12d, %eax
jg 0x686b
movq %r13, %rdi
movl %r12d, %esi
movq (%rsp), %rdx
movl %eax, %ecx
callq 0x593d
movl %eax, %r12d
movl 0x88(%rsp), %r15d
leaq -0x1(%r14), %rax
movq 0x8(%rsp), %rcx
movl %eax, %edx
movq 0x28(%rsp), %rsi
movq %rcx, (%rsi,%rdx,8)
movq %r13, %rbx
cmpl $0x1, %r14d
movq %rax, %r14
jg 0x6688
jmp 0x6821
movl $0x1, %r12d
jmp 0x669b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x685c
movq %rbx, %r13
cmpq 0x10(%rsp), %r13
jne 0x6875
cmpl %r15d, %r12d
jg 0x687a
leal (,%r12,8), %eax
movslq %eax, %rdx
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x1120
movq 0x38(%rsp), %rax
movl %r12d, (%rax)
movq %rbx, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x18a4
callq 0x187a
callq 0x18ce
callq 0x18f8