// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/apn/integer/basic.c
// Function: tt_int_div_buf
int _tt_int_div_buf(_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)
{
	if (msb_ds < BINDIV_CROSS)
		return div_buf_classic(qt, msb_qt, rm, msb_rm,
				dd, msb_dd, ds, msb_ds);

	if (msb_dd <= msb_ds*2)
		return div_buf_bin(qt, msb_qt, rm, msb_rm,
				dd, msb_dd, ds, msb_ds);

	int ret;
	int _msb_qt, _msb_rm = 0;
	int offset = msb_dd - msb_ds*2;

	*msb_qt = 0;	/* Invalidate */

	/* Temporary dividend buffer */
	_tt_word *_dd = malloc(msb_ds*2*_tt_word_sz);
	memcpy(_dd, dd+offset, msb_ds*2*_tt_word_sz);

	while (1) {
		/* Partial division */
		int _msb_dd = _tt_int_get_msb(_dd, msb_ds*2);
		if (_tt_int_cmp_buf(_dd, _msb_dd, ds, msb_ds) >= 0) {
			ret = div_buf_bin(qt+offset, &_msb_qt, rm, &_msb_rm,
					_dd, _msb_dd, ds, msb_ds);
			if (ret)
				goto out;
		} else {
			_msb_qt = 1;
			_msb_rm = msb_ds;
			memcpy(rm, _dd, _msb_dd*_tt_word_sz);
		}

		/* Calculate quotient MSB on first division */
		if (*msb_qt == 0)
			*msb_qt = _msb_qt + offset;

		/* Get next dividend MSB */
		if (_msb_rm == 1 && rm[0] == 0)
			_msb_rm = 0;
		msb_dd = offset + _msb_rm;
		offset -= (msb_ds*2 - _msb_rm);
		if (offset <= 0)
			break;

		/* Combine remainder to next dividend */
		memcpy(_dd, dd+offset, (msb_ds*2-_msb_rm)*_tt_word_sz);
		memcpy(_dd+msb_ds*2-_msb_rm, rm, _msb_rm*_tt_word_sz);
		memset(rm, 0, msb_ds*_tt_word_sz);
	}

	/* Last division */
	memcpy(_dd, dd, (msb_dd-_msb_rm)*_tt_word_sz);
	memcpy(_dd+msb_dd-_msb_rm, rm, _msb_rm*_tt_word_sz);
	memset(_dd+msb_dd, 0, (msb_ds*2-msb_dd)*_tt_word_sz);
	msb_dd = _tt_int_get_msb(_dd, msb_dd);
	if (_tt_int_cmp_buf(_dd, msb_dd, ds, msb_ds) >= 0) {
		memset(rm, 0, msb_ds*_tt_word_sz);
		ret = div_buf_bin(qt, &_msb_qt, rm, msb_rm,
				_dd, msb_dd, ds, msb_ds);
	} else {
		memcpy(rm, _dd, msb_dd*_tt_word_sz);
		memset(rm+msb_dd, 0, (msb_ds-msb_dd)*_tt_word_sz);
		*msb_rm = msb_dd;
		ret = 0;
	}

out:
	free(_dd);
	return ret;
}

// Assembly:
subq $0x68, %rsp
movl 0x78(%rsp), %eax
movq 0x70(%rsp), %rax
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movl %r9d, 0x34(%rsp)
cmpl $0x1e, 0x78(%rsp)
jge 0x975f
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r8
movl 0x34(%rsp), %r9d
movq 0x70(%rsp), %r10
movl 0x78(%rsp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x9b00
movl %eax, 0x64(%rsp)
jmp 0x9aef
movl 0x34(%rsp), %eax
movl 0x78(%rsp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0x97aa
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x38(%rsp), %r8
movl 0x34(%rsp), %r9d
movq 0x70(%rsp), %r10
movl 0x78(%rsp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x9ed0
movl %eax, 0x64(%rsp)
jmp 0x9aef
movl $0x0, 0x28(%rsp)
movl 0x34(%rsp), %eax
movl 0x78(%rsp), %ecx
shll %ecx
subl %ecx, %eax
movl %eax, 0x24(%rsp)
movq 0x50(%rsp), %rax
movl $0x0, (%rax)
movl 0x78(%rsp), %eax
shll %eax
shll $0x3, %eax
movslq %eax, %rdi
callq 0x1160
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %rsi
movslq 0x24(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl 0x78(%rsp), %eax
shll %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x18(%rsp), %rdi
movl 0x78(%rsp), %esi
shll %esi
callq 0x8b90
movl %eax, 0x14(%rsp)
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %esi
movq 0x70(%rsp), %rdx
movl 0x78(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jl 0x988c
movq 0x58(%rsp), %rdi
movslq 0x24(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq 0x48(%rsp), %rdx
movq 0x18(%rsp), %r8
movl 0x14(%rsp), %r9d
movq 0x70(%rsp), %r10
movl 0x78(%rsp), %eax
leaq 0x2c(%rsp), %rsi
leaq 0x28(%rsp), %rcx
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x9ed0
movl %eax, 0x30(%rsp)
cmpl $0x0, 0x30(%rsp)
je 0x988a
jmp 0x9add
jmp 0x98b5
movl $0x1, 0x2c(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x50(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x98ce
movl 0x2c(%rsp), %ecx
addl 0x24(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, (%rax)
cmpl $0x1, 0x28(%rsp)
jne 0x98e8
movq 0x48(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x98e8
movl $0x0, 0x28(%rsp)
movl 0x24(%rsp), %eax
addl 0x28(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x78(%rsp), %ecx
shll %ecx
subl 0x28(%rsp), %ecx
movl 0x24(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jg 0x9911
jmp 0x9990
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %rsi
movslq 0x24(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl 0x78(%rsp), %eax
shll %eax
subl 0x28(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x18(%rsp), %rdi
movl 0x78(%rsp), %eax
shll %eax
cltq
shlq $0x3, %rax
addq %rax, %rdi
movslq 0x28(%rsp), %rcx
xorl %eax, %eax
subq %rcx, %rax
shlq $0x3, %rax
addq %rax, %rdi
movq 0x48(%rsp), %rsi
movl 0x28(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x48(%rsp), %rdi
movl 0x78(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
jmp 0x980a
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl 0x34(%rsp), %eax
subl 0x28(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x18(%rsp), %rdi
movslq 0x34(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movslq 0x28(%rsp), %rcx
xorl %eax, %eax
subq %rcx, %rax
shlq $0x3, %rax
addq %rax, %rdi
movq 0x48(%rsp), %rsi
movl 0x28(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x18(%rsp), %rdi
movslq 0x34(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x78(%rsp), %eax
shll %eax
subl 0x34(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0x18(%rsp), %rdi
movl 0x34(%rsp), %esi
callq 0x8b90
movl %eax, 0x34(%rsp)
movq 0x18(%rsp), %rdi
movl 0x34(%rsp), %esi
movq 0x70(%rsp), %rdx
movl 0x78(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jl 0x9a89
movq 0x48(%rsp), %rdi
movl 0x78(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0x58(%rsp), %rdi
movq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x18(%rsp), %r8
movl 0x34(%rsp), %r9d
movq 0x70(%rsp), %r10
movl 0x78(%rsp), %eax
leaq 0x2c(%rsp), %rsi
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x9ed0
movl %eax, 0x30(%rsp)
jmp 0x9adb
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x34(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0x48(%rsp), %rdi
movslq 0x34(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x78(%rsp), %eax
subl 0x34(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movl 0x34(%rsp), %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movl $0x0, 0x30(%rsp)
jmp 0x9add
movq 0x18(%rsp), %rdi
callq 0x1030
movl 0x30(%rsp), %eax
movl %eax, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopl (%rax,%rax)