// File: /workspace/github_c_makefile_star2_O2/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, %r15d
movq %r8, %r14
movq %rcx, %rbx
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, 0x18(%rsp)
movl 0x88(%rsp), %r13d
leal (%r15,%r13), %eax
incl %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1140
testq %rax, %rax
je 0x5b03
movq %r12, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq %rax, %rdi
movq 0x80(%rsp), %r12
movslq %r15d, %rax
leaq (%rdi,%rax,8), %rbx
leal (,%r15,8), %eax
movslq %eax, %rdx
movq %rdi, 0x30(%rsp)
movq %r14, %rsi
callq 0x1120
subl %r13d, %r15d
movslq %r13d, %rax
movq %rax, 0x38(%rsp)
leaq (,%rax,8), %rax
movq %rbx, %r14
subq %rax, %r14
movl %r15d, (%rbp)
movq %r14, %rdi
movl %r13d, %esi
movq %r12, %rdx
movl %r13d, %ecx
callq 0x4dca
movq %r13, %rsi
movl %r15d, %r13d
movl %esi, %r12d
testl %eax, %eax
js 0x5948
leal 0x1(%r15), %r13d
movl %r13d, (%rbp)
movslq %r15d, %rax
movq 0x18(%rsp), %rcx
movq $0x1, (%rcx,%rax,8)
movq %r14, %rdi
movq 0x80(%rsp), %rdx
movl %esi, %ecx
movq %rsi, %r12
callq 0x4d64
movq %r12, %rsi
movl %eax, %r12d
movq %rbp, %rcx
movq 0x80(%rsp), %rbp
leal 0x1(%rsi), %eax
testl %r13d, %r13d
jne 0x5961
movl $0x1, (%rcx)
shll $0x3, %eax
cltq
movq %rax, 0x40(%rsp)
movl %r15d, %esi
movl 0x88(%rsp), %r13d
testl %esi, %esi
jle 0x5ac0
movq %rsi, 0x10(%rsp)
cmpl $0x1, %r12d
jne 0x5993
cmpq $0x0, (%r14)
pushq $0x1
popq %r15
je 0x5999
incl %r12d
movl %r12d, %r15d
addq $-0x8, %r14
movq %r14, %rdi
movl %r15d, %esi
movq %rbp, %r12
movq %rbp, %rdx
movl %r13d, %ecx
callq 0x4dca
testl %eax, %eax
js 0x5aa3
cmpl %r13d, %r15d
jne 0x59c9
movq $0x1, 0x8(%rsp)
jmp 0x5a12
movslq %r15d, %rax
movq -0x8(%r14,%rax,8), %rdi
movq %rdi, %rsi
shrq %rsi
shlq $0x3f, %rdi
orq -0x10(%r14,%rax,8), %rdi
movq 0x38(%rsp), %rax
movq -0x8(%r12,%rax,8), %rdx
xorl %ecx, %ecx
callq 0x9910
movabsq $-0x7fffffffffffffff, %rcx # imm = 0x8000000000000001
cmpq %rcx, %rax
jae 0x5b34
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x5aa3
movq %rbx, %rdi
xorl %esi, %esi
movq 0x40(%rsp), %rdx
callq 0x10e0
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
leaq 0x8(%rsp), %rcx
pushq $0x1
popq %r8
callq 0x4eea
movl %eax, %r12d
movq 0x8(%rsp), %r13
decq %r13
movq %rbx, %rdi
movl %r12d, %esi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x4dca
testl %eax, %eax
jle 0x5a77
movq %rbx, %rdi
movl %r12d, %esi
movq %rbp, %rdx
movl 0x88(%rsp), %ecx
callq 0x4d64
movl %eax, %r12d
movq %r13, 0x8(%rsp)
jmp 0x5a40
cmpl %r12d, %r15d
jl 0x5b15
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
movl %r12d, %ecx
callq 0x4d64
movl %eax, %r15d
movq 0x8(%rsp), %rax
movl 0x88(%rsp), %r13d
jmp 0x5aa5
xorl %eax, %eax
movq 0x10(%rsp), %rsi
decq %rsi
movl %esi, %ecx
movq 0x18(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movl %r15d, %r12d
jmp 0x5976
movq 0x30(%rsp), %rbx
cmpq %rbx, %r14
jne 0x5b5d
cmpl %r13d, %r12d
jg 0x5b7c
leal (,%r12,8), %eax
movslq %eax, %rdx
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x1120
movq 0x28(%rsp), %rax
movl %r12d, (%rax)
movq %rbx, %rdi
callq 0x1030
xorl %eax, %eax
jmp 0x5b06
pushq $-0x1
popq %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10e88(%rip), %rsi     # 0x169a4
leaq 0x455f(%rip), %rdx      # 0xa082
leaq 0x10e42(%rip), %rcx     # 0x1696c
xorl %edi, %edi
movl $0x25a, %r8d            # imm = 0x25A
jmp 0x5b51
leaq 0x10e79(%rip), %rsi     # 0x169b4
leaq 0x4540(%rip), %rdx      # 0xa082
leaq 0x10e23(%rip), %rcx     # 0x1696c
xorl %edi, %edi
movl $0x22c, %r8d            # imm = 0x22C
xorl %eax, %eax
callq 0x7de8
callq 0x1050
leaq 0x10e40(%rip), %rsi     # 0x169a4
leaq 0x4517(%rip), %rdx      # 0xa082
leaq 0x10dfa(%rip), %rcx     # 0x1696c
xorl %edi, %edi
movl $0x261, %r8d            # imm = 0x261
jmp 0x5b51
leaq 0x10e21(%rip), %rsi     # 0x169a4
leaq 0x44f8(%rip), %rdx      # 0xa082
leaq 0x10ddb(%rip), %rcx     # 0x1696c
xorl %edi, %edi
movl $0x264, %r8d            # imm = 0x264
jmp 0x5b51