// File: /workspace/github_c_makefile_star2_O2/cyb70289[P]tt/src/apn/integer/basic.c
// Function: mul_buf_kara
static int mul_buf_kara(_tt_word *intr, const _tt_word *int1, int msb1,
		const _tt_word *int2, int msb2, _tt_word *workbuf)
{
	/* Make int1 shorter than int2 */
	if (msb1 > msb2) {
		__tt_swap(msb1, msb2);
		__tt_swap(int1, int2);
	}

	/* Fallback to classic algorithm on small inputs */
	if (msb1 < KARA_CROSS)
		return mul_buf_classic(intr, int1, msb1, int2, msb2);

	/* On unbalanced input, Karatsuba performs even worse than classic
	 * algorithm. Fix it by splitting long input into pieces of the same
	 * size as short input.
	 */
	if (msb2 >= msb1*2)
		return mul_buf_unbalanced(intr, int1, msb1, int2, msb2,
				workbuf);

	const int square = (int1 == int2 && msb1 == msb2);

	const int div = msb2 / 2;
	int msb_a = msb1 - div;
	int msb_b = get_words(int1, div);
	int msb_c = msb2 - div;
	int msb_d = get_words(int2, div);

	/* Result = (A*C)*base^(div*2) + (A*D+B*C)*base^div + B*D */
	int msb, msb_ac, msb_bd = 0;

	/* B*D -> intr */
	if (msb_b && msb_d)
		msb_bd = mul_buf_kara(intr, int1, msb_b, int2, msb_d, workbuf);

	/* A*C -> intr+div*2 */
	msb_ac = mul_buf_kara(intr+div*2, int1+div, msb_a, int2+div, msb_c,
			workbuf);
	msb = msb_ac + div*2;

	/* A*D+B*C */
	if (msb_b || msb_d) {
		_tt_word *a_b = workbuf;
		_tt_word *c_d = a_b + (div+2);
		_tt_word *ad_bc = c_d + (div+2);
		_tt_word *nextbuf = ad_bc + 2*(div+2);
		int msb_ad_bc;
		memset(workbuf, 0, 4*(div+2)*_tt_word_sz);

		if (_tt_unlikely(square)) {
			/* Square: A*D*2 */
			msb_ad_bc = mul_buf_kara(ad_bc, int1+div, msb_a,
					int2, msb_d, nextbuf);
			int c = 0;
			for (int i = 0; i < msb_ad_bc; i++) {
				ad_bc[i] <<= 1;
				ad_bc[i] += c;
				if (ad_bc[i] & _tt_word_top_bit) {
					ad_bc[i] -= _tt_word_top_bit;
					c = 1;
				} else {
					c = 0;
				}
			}
			if (c)
				ad_bc[msb_ad_bc++] = 1;
		} else {
			/* A+B */
			int msb_a_b = msb_a;
			memcpy(a_b, int1+div, msb_a*_tt_word_sz);
			if (msb_b)
				msb_a_b = _tt_int_add_buf(a_b, msb_a_b,
						int1, msb_b);

			/* C+D */
			int msb_c_d = msb_c;
			memcpy(c_d, int2+div, msb_c*_tt_word_sz);
			if (msb_d)
				msb_c_d = _tt_int_add_buf(c_d, msb_c_d,
						int2, msb_d);

			/* A*D+B*C = (A+B)*(C+D)-A*C-B*D */
			msb_ad_bc = mul_buf_kara(ad_bc, a_b, msb_a_b,
					c_d, msb_c_d, nextbuf);
			msb_ad_bc = _tt_int_sub_buf(ad_bc, msb_ad_bc,
					intr+div*2, msb_ac);
			if (msb_bd)
				msb_ad_bc = _tt_int_sub_buf(ad_bc, msb_ad_bc,
						intr, msb_bd);
		}

		/* Sum all */
		int msb2 = msb - div;
		msb = _tt_int_add_buf(intr+div, msb2, ad_bc, msb_ad_bc) + div;
	}

	tt_assert_fa(msb == (msb1+msb2) || msb == (msb1+msb2-1));
	return msb;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %r8d, %ebp
movq %rdi, %r14
movl %r8d, %r12d
movq %rcx, %r13
movl %edx, %ebx
movq %rsi, %rax
cmpl %r8d, %edx
jle 0x50af
movl %edx, %r12d
movq %rsi, %r13
movl %ebp, %ebx
movq %rcx, %rax
cmpl $0xf, %ebx
jg 0x50d8
movq %r14, %rdi
movq %rax, %rsi
movl %ebx, %edx
movq %r13, %rcx
movl %r12d, %r8d
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4eea
movq %rax, 0x20(%rsp)
leal (%rbx,%rbx), %edi
cmpl %edi, %r12d
movq %r9, 0x48(%rsp)
jge 0x5325
cmpq %rsi, %rcx
movq %rbx, %rsi
sete 0x8(%rsp)
movq %rdx, 0x50(%rsp)
cmpl %edx, %ebp
sete 0x18(%rsp)
pushq $0x2
popq %rcx
movl %r12d, %eax
cltd
idivl %ecx
movl %eax, %ebx
subl %eax, %esi
movq %rsi, (%rsp)
movq 0x20(%rsp), %rdi
movl %eax, %esi
callq 0x66c8
movl %eax, %r15d
subl %ebx, %r12d
movq %r12, 0x40(%rsp)
movq %r13, %rdi
movq %rbx, 0x10(%rsp)
movl %ebx, %esi
callq 0x66c8
movl %eax, %r12d
testl %r15d, %r15d
setne %al
testl %r12d, %r12d
setne %cl
andb %al, %cl
xorl %eax, %eax
cmpb $0x1, %cl
jne 0x516f
movq %r14, %rdi
movq 0x20(%rsp), %rsi
movl %r15d, %edx
movq %r13, %rcx
movl %r12d, %r8d
movq 0x48(%rsp), %r9
callq 0x507d
movl %eax, 0x64(%rsp)
movq 0x10(%rsp), %rbx
leal (%rbx,%rbx), %eax
cltq
movq %r14, 0x28(%rsp)
leaq (%r14,%rax,8), %rdi
movslq %ebx, %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
movq %r13, 0x30(%rsp)
leaq (%r13,%rax,8), %rcx
movq %rax, %r13
movq %rdi, 0x90(%rsp)
movq %rsi, 0x70(%rsp)
movq (%rsp), %rdx
movq %rcx, 0x88(%rsp)
movq 0x40(%rsp), %r8
movq 0x48(%rsp), %r14
movq %r14, %r9
callq 0x507d
movl %eax, %edx
leal (%rdx,%rbx,2), %eax
movl %r15d, 0x60(%rsp)
orl %r12d, %r15d
je 0x5486
movq %rdx, 0x80(%rsp)
movl %r12d, 0x3c(%rsp)
movl %eax, 0x5c(%rsp)
movb 0x8(%rsp), %r12b
andb 0x18(%rsp), %r12b
leal 0x2(%rbx), %eax
leaq (%r14,%r13,8), %rcx
addq $0x10, %rcx
movq %r13, 0x18(%rsp)
movq %rcx, 0x68(%rsp)
leaq 0x10(%rcx,%r13,8), %rdx
leal 0x4(%rbx,%rbx), %ecx
movslq %ecx, %rcx
movq %rdx, 0x8(%rsp)
leaq (%rdx,%rcx,8), %rbx
shll $0x5, %eax
movslq %eax, %rdx
movq %r14, %r15
xorl %r14d, %r14d
movq %r15, %rdi
xorl %esi, %esi
callq 0x10e0
testb %r12b, %r12b
jne 0x54fd
movq %rbx, 0x78(%rsp)
movq (%rsp), %r13
leal (,%r13,8), %eax
movslq %eax, %rdx
movq %r15, %rdi
movq 0x70(%rsp), %rsi
callq 0x1120
movl 0x60(%rsp), %ecx
testl %ecx, %ecx
movq %r15, %r12
je 0x5281
movq %r12, %rdi
movl %r13d, %esi
movq 0x20(%rsp), %rdx
callq 0x4d04
movq %rax, (%rsp)
movq 0x30(%rsp), %rbx
movq 0x68(%rsp), %r14
movq 0x40(%rsp), %r15
leal (,%r15,8), %eax
movslq %eax, %rdx
movq %r14, %rdi
movq 0x88(%rsp), %rsi
callq 0x1120
movl 0x3c(%rsp), %ecx
testl %ecx, %ecx
movq 0x10(%rsp), %r13
je 0x52c9
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x4d04
movl %eax, %r15d
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq (%rsp), %rdx
movq %r14, %rcx
movl %r15d, %r8d
movq %rdi, %r15
movq 0x78(%rsp), %r9
callq 0x507d
movq %r15, %rdi
movl %eax, %esi
movq 0x90(%rsp), %rdx
movq 0x80(%rsp), %rcx
callq 0x4d64
movl 0x64(%rsp), %ecx
testl %ecx, %ecx
je 0x5464
movq %r15, %rdi
movl %eax, %esi
movq 0x28(%rsp), %rbx
movq %rbx, %rdx
callq 0x4d64
jmp 0x5469
movq %r12, 0x40(%rsp)
leal (%rdx,%rbp), %eax
decl %eax
xorl %ebp, %ebp
xorl %edx, %edx
divl %ebx
decl %eax
movl %eax, 0x50(%rsp)
movl %ebx, %eax
shll $0x4, %eax
movq %rax, 0x18(%rsp)
movl %edi, %eax
leaq (%r9,%rax,8), %rax
movq %rax, 0x8(%rsp)
movl %ebx, %eax
shlq $0x3, %rax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
xorl %ecx, %ecx
cmpl 0x50(%rsp), %ecx
jge 0x5407
movl %ecx, (%rsp)
movq %r14, %r15
movq %r13, %rdi
movl %ebx, %esi
callq 0x66c8
testl %eax, %eax
je 0x53ea
movl %eax, %r14d
movl %ebp, 0x10(%rsp)
movq %rbx, %rbp
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x10e0
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movl %ebp, %edx
movq %r13, 0x30(%rsp)
movq %r13, %rcx
movl %r14d, %r8d
movq 0x8(%rsp), %r9
callq 0x507d
movq %r15, %r14
movq %r15, %rdi
movl %r12d, %esi
movq %rbx, %rdx
movq %rbp, %rbx
movl %eax, %ecx
callq 0x4d04
movl %eax, %r12d
subl %ebx, %r12d
testl %r12d, %r12d
jg 0x53df
xorl %r12d, %r12d
movq 0x30(%rsp), %r13
movl 0x10(%rsp), %ebp
jmp 0x53f0
xorl %r12d, %r12d
movq %r15, %r14
movl (%rsp), %ecx
addl %ebx, %ebp
incl %ecx
movq 0x28(%rsp), %rax
addq %rax, %r13
addq %rax, %r14
jmp 0x5360
movq 0x40(%rsp), %r15
subl %ebp, %r15d
je 0x54b5
movl %ebp, 0x10(%rsp)
movq %r13, %rbp
movq %rbx, %r13
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
xorl %esi, %esi
movq 0x18(%rsp), %rdx
callq 0x10e0
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movl %r13d, %edx
movq %rbp, %rcx
movl %r15d, %r8d
movq 0x8(%rsp), %r9
callq 0x507d
movq %r14, %rdi
movl %r12d, %esi
movq %rbx, %rdx
movl %eax, %ecx
callq 0x4d04
addl 0x10(%rsp), %eax
jmp 0x54a3
movq 0x28(%rsp), %rbx
movl 0x5c(%rsp), %esi
subl %r13d, %esi
movq 0x18(%rsp), %rcx
leaq (%rbx,%rcx,8), %rdi
movq %r15, %rdx
movl %eax, %ecx
callq 0x4d04
addl %r13d, %eax
movq 0x50(%rsp), %rcx
leal (%rcx,%rbp), %edx
cmpl %edx, %eax
setne %dl
addl %ebp, %ecx
decl %ecx
cmpl %ecx, %eax
setne %cl
andb %dl, %cl
cmpb $0x1, %cl
je 0x54d4
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x114d5(%rip), %rsi     # 0x16991
leaq 0x4bbf(%rip), %rdx      # 0xa082
leaq 0x114a2(%rip), %rcx     # 0x1696c
xorl %edi, %edi
movl $0x17c, %r8d            # imm = 0x17C
jmp 0x54f1
leaq 0x114a9(%rip), %rsi     # 0x16984
leaq 0x4ba0(%rip), %rdx      # 0xa082
leaq 0x11483(%rip), %rcx     # 0x1696c
xorl %edi, %edi
movl $0x1f1, %r8d            # imm = 0x1F1
xorl %eax, %eax
callq 0x7de8
callq 0x1050
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq 0x70(%rsp), %rsi
movq (%rsp), %rdx
movq 0x30(%rsp), %rcx
movl 0x3c(%rsp), %r8d
movq %rbx, %r9
callq 0x507d
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movabsq $0x7ffffffffffffffe, %rdx # imm = 0x7FFFFFFFFFFFFFFE
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x555e
movl %r14d, %edi
movq (%r15,%rsi,8), %r9
addq %r9, %r9
movq %r9, %r8
andq %rdx, %r8
orq %rdi, %r8
shrq $0x3f, %r9
movq %r8, (%r15,%rsi,8)
incq %rsi
movl %r9d, %r14d
jmp 0x5536
testl %r14d, %r14d
movq 0x28(%rsp), %rbx
movq 0x10(%rsp), %r13
je 0x5469
movslq %eax, %rcx
incl %eax
movq $0x1, (%r15,%rcx,8)
jmp 0x5469