// File: /workspace/github_c_makefile_star2_O0/cyb70289[P]tt/src/apn/integer/basic.c
// Function: div_buf_bin
static int div_buf_bin(_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)
{
	int ret = 0;
	const int m = msb_dd - msb_ds, h = m / 2;

	if (m < BINDIV_CROSS)
		return div_buf_classic(qt, msb_qt, rm, msb_rm,
				dd, msb_dd, ds, msb_ds);

	/* Working buffer
	 *
	 * - For high quotient
	 *   +------------------------+-------------------------+
	 *   |         nextdd         |          qt_ds          |
	 *   +------------------------+-------------------------+
	 *   |<----- msb_ds+h+1 ----->|<-- msb_dd-msb_ds+h+2 -->|
	 *
	 * - For low quotient
	 *   +------------------------+----------+---------+
	 *   |         nextdd         |   qt_ds  |   qtl   |
	 *   +------------------------+----------+---------+
	 *   |<----- msb_ds+h+1 ----->|<- 2h+2 ->|<- h+2 ->|
	 */
	const int bufsz = msb_ds + h*4 + 5;
	_tt_word *workbuf = calloc(bufsz, _tt_word_sz);
	if (workbuf == NULL)
		return TT_ENOMEM;
	_tt_word *nextdd = workbuf, *nextdd_rm = nextdd + h*2;
	_tt_word *qt_ds = nextdd + msb_ds + h + 1;
	_tt_word *qtl = qt_ds + h*2 + 2;

	/* Guess higher part quotient
	 *
	 * - Dividend:
	 *   +-----------------+-------------+
	 *   |       dd1       |     dd0     |
	 *   +-----------------+-------------+
	 *   |                 |<--- h*2 --->|
	 *   |<--------- msb_dd ------------>|
	 *
	 * - Divisor:
	 *   +---------+-------+
	 *   |   ds1   |  ds0  |
	 *   +---------+-------+
	 *   |         |<- h ->|
	 *   |<--- msb_ds ---->|
	 *
	 * - (qt, rm) = dd1 .divide. ds1
	 *   qt_max_size = msb_dd - msb_ds - h + 2 (one extra word)
	 *   rm_max_size = msb_ds - h
	 */
	int msb_qth, msb_rmh;
	_tt_word *qth = qt + h;

	ret = div_buf_bin(qth, &msb_qth, nextdd_rm, &msb_rmh,
			dd+h*2, msb_dd-h*2, ds+h, msb_ds-h);
	if (ret)
		goto out;

	/* Adjust quotient (Next dividend >= Quotient*Divisor)
	 *
	 * - Next dividend (max_size = msb_ds + h + 1) (one extra word)
	 *   +------+-------------+
	 *   |  rm  |     dd0     |
	 *   +------+-------------+
	 *          |<--- h*2 --->|
	 *
	 * - Quotient*Divisor (max_size = msb_dd - msb_ds + h + 2)
	 *   +------------+-------+
	 *   |  qt * ds0  |   0   |
	 *   +------------+-------+
	 *                |<- h ->|
	 */
	memcpy(nextdd, dd, h*2*_tt_word_sz);
	int msb_nextdd = _tt_int_get_msb(nextdd, msb_rmh + h*2);
	int msb_qt_ds = _tt_int_mul_buf(qt_ds+h, qth, msb_qth,
			ds, _tt_int_get_msb(ds, h)) + h;
	msb_qt_ds = _tt_int_get_msb(qt_ds, msb_qt_ds);

	while (_tt_int_cmp_buf(nextdd, msb_nextdd, qt_ds, msb_qt_ds) < 0) {
		const _tt_word one = 1;
		msb_qth = _tt_int_sub_buf(qth, msb_qth, &one, 1);
		if (msb_qt_ds > h &&
				_tt_int_cmp_buf(qt_ds+h, msb_qt_ds-h,
					ds, msb_ds) > 0) {
			/* Decrease subtrahend */
			msb_qt_ds = _tt_int_sub_buf(qt_ds+h, msb_qt_ds-h,
					ds, msb_ds) + h;
		} else {
			/* Increase minuend */
			int msb_tmp = msb_nextdd - h;
			if (msb_tmp <= 0)
				msb_tmp = 1;
			msb_nextdd = _tt_int_add_buf(nextdd+h, msb_tmp,
					ds, msb_ds) + h;
			break;
		}
	}
	msb_nextdd = _tt_int_sub_buf(nextdd, msb_nextdd, qt_ds, msb_qt_ds);

	/* Clear used buffer */
	memset(qt_ds+h, 0, (msb_dd-msb_ds+2)*_tt_word_sz);

	/* Get lower part quotient
	 *
	 * - Next dividend (max_size = msb_ds + h + 1)
	 *   +--------------+----------+
	 *   |   next_dd1   | next_dd0 |
	 *   +--------------+----------+
	 *                  |<-- h --->|
	 *
	 * - (qt, rm) = next_dd1 .divide. ds1
	 *   qt_max_size = h + 2 (one extra word)
	 *   rm_max_size = msb_ds - h + 1 (one extra word)
	 */
	int msb_qtl, msb_rml;
	_tt_word *rml = rm + h;

	if (msb_nextdd > h &&
			_tt_int_cmp_buf(nextdd+h, msb_nextdd-h,
				ds+h, msb_ds-h) >= 0) {
		ret = div_buf_bin(qtl, &msb_qtl, rml, &msb_rml,
				nextdd+h, msb_nextdd-h, ds+h, msb_ds-h);
		if (ret)
			goto out;
	} else {
		msb_qtl = msb_rml = 1;
		if (msb_nextdd > h) {
			msb_rml = msb_nextdd - h;
			memcpy(rml, nextdd+h, msb_rml*_tt_word_sz);
		}
	}

	/* Adjust quotient (Remainder >= Quotient*Divisor)
	 *
	 * - Remainder (maxsize = msb_ds)
	 *   +-------+----------+
	 *   |  rml  | next_dd0 |
	 *   +-------+----------+
	 *           |<-- h --->|
	 *
	 * - Quotient*Divisor (maxize = 2h+2)
	 *   +---------+
	 *   | qtl*ds0 |
	 *   +---------+
	 */
	memcpy(rm, nextdd, h*_tt_word_sz);
	msb_rml = _tt_int_get_msb(rm, msb_rml+h);
	msb_qt_ds = _tt_int_mul_buf(qt_ds, qtl, msb_qtl,
			ds, _tt_int_get_msb(ds, h));

	while (_tt_int_cmp_buf(rm, msb_rml, qt_ds, msb_qt_ds) < 0) {
		const _tt_word one = 1;
		msb_qtl = _tt_int_sub_buf(qtl, msb_qtl, &one, 1);
		if (_tt_int_cmp_buf(qt_ds, msb_qt_ds, ds, msb_ds) > 0) {
			/* Decrease subtrahend */
			msb_qt_ds = _tt_int_sub_buf(qt_ds, msb_qt_ds,
					ds, msb_ds);
		} else {
			/* Increase minuend */
			msb_rml = _tt_int_add_buf(rm, msb_rml, ds, msb_ds);
			break;
		}
	}
	*msb_rm = _tt_int_sub_buf(rm, msb_rml, qt_ds, msb_qt_ds);

	*msb_qt = _tt_int_add_buf(qt, msb_qth+h, qtl, msb_qtl);

out:
	free(workbuf);
	return ret;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movl 0x118(%rsp), %eax
movq 0x110(%rsp), %rax
movq %rdi, 0xf8(%rsp)
movq %rsi, 0xf0(%rsp)
movq %rdx, 0xe8(%rsp)
movq %rcx, 0xe0(%rsp)
movq %r8, 0xd8(%rsp)
movl %r9d, 0xd4(%rsp)
movl $0x0, 0xd0(%rsp)
movl 0xd4(%rsp), %eax
subl 0x118(%rsp), %eax
movl %eax, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0xc8(%rsp)
cmpl $0x1e, 0xcc(%rsp)
jge 0x9fae
movq 0xf8(%rsp), %rdi
movq 0xf0(%rsp), %rsi
movq 0xe8(%rsp), %rdx
movq 0xe0(%rsp), %rcx
movq 0xd8(%rsp), %r8
movl 0xd4(%rsp), %r9d
movq 0x110(%rsp), %r10
movl 0x118(%rsp), %eax
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x9b00
movl %eax, 0x104(%rsp)
jmp 0xa739
movl 0x118(%rsp), %eax
movl 0xc8(%rsp), %ecx
shll $0x2, %ecx
addl %ecx, %eax
addl $0x5, %eax
movl %eax, 0xc4(%rsp)
movslq 0xc4(%rsp), %rdi
movl $0x8, %esi
callq 0x1110
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xb8(%rsp)
jne 0xa000
movl $0xffffffff, 0x104(%rsp) # imm = 0xFFFFFFFF
jmp 0xa739
movq 0xb8(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movl 0xc8(%rsp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0xa8(%rsp)
movq 0xb0(%rsp), %rax
movslq 0x118(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq 0xc8(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, 0xa0(%rsp)
movq 0xa0(%rsp), %rax
movl 0xc8(%rsp), %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
addq $0x10, %rax
movq %rax, 0x98(%rsp)
movq 0xf8(%rsp), %rax
movslq 0xc8(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rdi
movq 0xa8(%rsp), %rdx
movq 0xd8(%rsp), %r8
movl 0xc8(%rsp), %eax
shll %eax
cltq
shlq $0x3, %rax
addq %rax, %r8
movl 0xd4(%rsp), %r9d
movl 0xc8(%rsp), %eax
shll %eax
subl %eax, %r9d
movq 0x110(%rsp), %r10
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %r10
movl 0x118(%rsp), %eax
subl 0xc8(%rsp), %eax
leaq 0x94(%rsp), %rsi
leaq 0x90(%rsp), %rcx
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x9ed0
movl %eax, 0xd0(%rsp)
cmpl $0x0, 0xd0(%rsp)
je 0xa141
jmp 0xa71e
movq 0xb0(%rsp), %rdi
movq 0xd8(%rsp), %rsi
movl 0xc8(%rsp), %eax
shll %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0xb0(%rsp), %rdi
movl 0x90(%rsp), %esi
movl 0xc8(%rsp), %eax
shll %eax
addl %eax, %esi
callq 0x8b90
movl %eax, 0x84(%rsp)
movq 0xa0(%rsp), %rax
movslq 0xc8(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0x94(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x110(%rsp), %rdi
movl 0xc8(%rsp), %esi
callq 0x8b90
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x4c(%rsp), %edx
movq 0x50(%rsp), %rcx
movl %eax, %r8d
callq 0x8be0
addl 0xc8(%rsp), %eax
movl %eax, 0x80(%rsp)
movq 0xa0(%rsp), %rdi
movl 0x80(%rsp), %esi
callq 0x8b90
movl %eax, 0x80(%rsp)
movq 0xb0(%rsp), %rdi
movl 0x84(%rsp), %esi
movq 0xa0(%rsp), %rdx
movl 0x80(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jge 0xa37e
movq $0x1, 0x78(%rsp)
movq 0x88(%rsp), %rdi
movl 0x94(%rsp), %esi
leaq 0x78(%rsp), %rdx
movl $0x1, %ecx
callq 0x8940
movl %eax, 0x94(%rsp)
movl 0x80(%rsp), %eax
cmpl 0xc8(%rsp), %eax
jle 0xa319
movq 0xa0(%rsp), %rdi
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x80(%rsp), %esi
subl 0xc8(%rsp), %esi
movq 0x110(%rsp), %rdx
movl 0x118(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jle 0xa319
movq 0xa0(%rsp), %rdi
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x80(%rsp), %esi
subl 0xc8(%rsp), %esi
movq 0x110(%rsp), %rdx
movl 0x118(%rsp), %ecx
callq 0x8940
addl 0xc8(%rsp), %eax
movl %eax, 0x80(%rsp)
jmp 0xa379
movl 0x84(%rsp), %eax
subl 0xc8(%rsp), %eax
movl %eax, 0x74(%rsp)
cmpl $0x0, 0x74(%rsp)
jg 0xa33a
movl $0x1, 0x74(%rsp)
movq 0xb0(%rsp), %rdi
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x74(%rsp), %esi
movq 0x110(%rsp), %rdx
movl 0x118(%rsp), %ecx
callq 0x87d0
addl 0xc8(%rsp), %eax
movl %eax, 0x84(%rsp)
jmp 0xa37e
jmp 0xa224
movq 0xb0(%rsp), %rdi
movl 0x84(%rsp), %esi
movq 0xa0(%rsp), %rdx
movl 0x80(%rsp), %ecx
callq 0x8940
movl %eax, 0x84(%rsp)
movq 0xa0(%rsp), %rdi
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0xd4(%rsp), %eax
subl 0x118(%rsp), %eax
addl $0x2, %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
movq 0xe8(%rsp), %rax
movslq 0xc8(%rsp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x60(%rsp)
movl 0x84(%rsp), %eax
cmpl 0xc8(%rsp), %eax
jle 0xa4ed
movq 0xb0(%rsp), %rdi
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x84(%rsp), %esi
subl 0xc8(%rsp), %esi
movq 0x110(%rsp), %rdx
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movl 0x118(%rsp), %ecx
subl 0xc8(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jl 0xa4ed
movq 0x98(%rsp), %rdi
movq 0x60(%rsp), %rdx
movq 0xb0(%rsp), %r8
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %r8
movl 0x84(%rsp), %r9d
subl 0xc8(%rsp), %r9d
movq 0x110(%rsp), %r10
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %r10
movl 0x118(%rsp), %eax
subl 0xc8(%rsp), %eax
leaq 0x70(%rsp), %rsi
leaq 0x6c(%rsp), %rcx
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
callq 0x9ed0
movl %eax, 0xd0(%rsp)
cmpl $0x0, 0xd0(%rsp)
je 0xa4eb
jmp 0xa71e
jmp 0xa54c
movl $0x1, 0x6c(%rsp)
movl $0x1, 0x70(%rsp)
movl 0x84(%rsp), %eax
cmpl 0xc8(%rsp), %eax
jle 0xa54a
movl 0x84(%rsp), %eax
subl 0xc8(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0x60(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movslq 0xc8(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl 0x6c(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
jmp 0xa54c
movq 0xe8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movl 0xc8(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
movq 0xe8(%rsp), %rdi
movl 0x6c(%rsp), %esi
addl 0xc8(%rsp), %esi
callq 0x8b90
movl %eax, 0x6c(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x70(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x110(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x110(%rsp), %rdi
movl 0xc8(%rsp), %esi
callq 0x8b90
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl 0x2c(%rsp), %edx
movq 0x30(%rsp), %rcx
movl %eax, %r8d
callq 0x8be0
movl %eax, 0x80(%rsp)
movq 0xe8(%rsp), %rdi
movl 0x6c(%rsp), %esi
movq 0xa0(%rsp), %rdx
movl 0x80(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jge 0xa6bf
movq $0x1, 0x58(%rsp)
movq 0x98(%rsp), %rdi
movl 0x70(%rsp), %esi
leaq 0x58(%rsp), %rdx
movl $0x1, %ecx
callq 0x8940
movl %eax, 0x70(%rsp)
movq 0xa0(%rsp), %rdi
movl 0x80(%rsp), %esi
movq 0x110(%rsp), %rdx
movl 0x118(%rsp), %ecx
callq 0x8ad0
cmpl $0x0, %eax
jle 0xa694
movq 0xa0(%rsp), %rdi
movl 0x80(%rsp), %esi
movq 0x110(%rsp), %rdx
movl 0x118(%rsp), %ecx
callq 0x8940
movl %eax, 0x80(%rsp)
jmp 0xa6ba
movq 0xe8(%rsp), %rdi
movl 0x6c(%rsp), %esi
movq 0x110(%rsp), %rdx
movl 0x118(%rsp), %ecx
callq 0x87d0
movl %eax, 0x6c(%rsp)
jmp 0xa6bf
jmp 0xa5ef
movq 0xe8(%rsp), %rdi
movl 0x6c(%rsp), %esi
movq 0xa0(%rsp), %rdx
movl 0x80(%rsp), %ecx
callq 0x8940
movl %eax, %ecx
movq 0xe0(%rsp), %rax
movl %ecx, (%rax)
movq 0xf8(%rsp), %rdi
movl 0x94(%rsp), %esi
addl 0xc8(%rsp), %esi
movq 0x98(%rsp), %rdx
movl 0x70(%rsp), %ecx
callq 0x87d0
movl %eax, %ecx
movq 0xf0(%rsp), %rax
movl %ecx, (%rax)
movq 0xb8(%rsp), %rdi
callq 0x1030
movl 0xd0(%rsp), %eax
movl %eax, 0x104(%rsp)
movl 0x104(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
retq
nopl (%rax,%rax)