// File: /workspace/github_c_makefile_star2_O3/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, %r15d
movl %edx, %r12d
movq %rdi, %r8
movl %r15d, %ebp
movq %rcx, %r13
movl %edx, %r10d
movq %rsi, %rdx
cmpl %r15d, %r12d
jle 0x5c85
movl %r12d, %ebp
movq %rsi, %r13
movl %r15d, %r10d
movq %rcx, %rdx
cmpl $0xf, %r10d
jg 0x5cb0
movq %r8, %rdi
movq %rdx, %rsi
movl %r10d, %edx
movq %r13, %rcx
movl %ebp, %r8d
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5aa0
leal (%r10,%r10), %edi
cmpl %edi, %ebp
movq %r9, 0x38(%rsp)
movq %rdx, 0x60(%rsp)
jge 0x5d06
cmpq %rsi, %rcx
sete 0x8(%rsp)
cmpl %r12d, %r15d
sete 0x28(%rsp)
movl %ebp, %ecx
shrl $0x1f, %ecx
addl %ebp, %ecx
sarl %ecx
subl %ecx, %r10d
leal 0x1(%rbp), %eax
movslq %ecx, %r9
cmpl $0x2, %eax
movq %r8, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
ja 0x5e13
subl %ecx, %ebp
movq %rbp, 0x48(%rsp)
xorl %r14d, %r14d
jmp 0x5e48
leal (%r15,%r12), %eax
decl %eax
xorl %r12d, %r12d
xorl %edx, %edx
divl %r10d
movl %eax, %ecx
movl %edi, %eax
cmpl $0x2, %ecx
movq %rax, 0x58(%rsp)
jb 0x6008
decl %ecx
movl %r10d, %edx
movl %r10d, %esi
shll $0x4, %esi
movq %rsi, 0x40(%rsp)
leaq (%r9,%rax,8), %rax
movq %rax, 0x8(%rsp)
leaq (,%rdx,8), %rsi
xorl %r15d, %r15d
xorl %eax, %eax
xorl %r12d, %r12d
movl %ecx, 0x4(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, %r14
cmpq $0x0, -0x8(%r13,%r14,8)
jne 0x5d72
decq %r14
jne 0x5d60
jmp 0x5df3
testq %r14, %r14
je 0x5df3
movq %rbp, 0x48(%rsp)
movq 0x38(%rsp), %rbp
movq %rbp, %rdi
movl %eax, 0x18(%rsp)
xorl %esi, %esi
movq 0x40(%rsp), %rdx
movq %r8, 0x10(%rsp)
movq %r10, %rbx
callq 0x10e0
movq %rbp, %rdi
movq 0x60(%rsp), %rsi
movl %ebx, %edx
movq %r13, %rcx
movl %r14d, %r8d
movq 0x8(%rsp), %r9
callq 0x5c4e
movq 0x10(%rsp), %rdi
movl 0x18(%rsp), %esi
movq %rbp, %rdx
movq 0x48(%rsp), %rbp
movl %eax, %ecx
callq 0x5888
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
movl 0x4(%rsp), %ecx
movq %rbx, %r10
movq 0x10(%rsp), %r8
subl %r10d, %eax
testl %eax, %eax
movl $0x0, %edi
cmovlel %edi, %eax
jmp 0x5df5
xorl %eax, %eax
leaq (%r8,%rdx,8), %r8
addq %rsi, %r13
addl %r10d, %r12d
subl %r10d, %ebp
incl %r15d
cmpl %ecx, %r15d
jl 0x5d5d
jmp 0x600a
leaq -0x1(%r9), %rax
movl %ecx, %r14d
cmpq $0x0, (%rdx,%rax,8)
jne 0x5e2d
decl %r14d
addq $-0x1, %rax
jb 0x5e1a
xorl %r14d, %r14d
subl %ecx, %ebp
movq %rbp, 0x48(%rsp)
movq %r9, %rbp
cmpq $0x0, -0x8(%r13,%rbp,8)
jne 0x6069
decq %rbp
jne 0x5e37
testl %r14d, %r14d
setne 0x4(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
movl $0x0, 0x24(%rsp)
leal (%rcx,%rcx), %eax
cltq
leaq (%r8,%rax,8), %rdi
leaq (%rdx,%r9,8), %rsi
movq %r9, 0x40(%rsp)
leaq (%r13,%r9,8), %rcx
movq %rdi, 0x90(%rsp)
movq %rsi, 0x58(%rsp)
movq %r10, 0x30(%rsp)
movl %r10d, %edx
movq %rcx, 0x78(%rsp)
movq 0x48(%rsp), %r8
movq 0x38(%rsp), %r9
callq 0x5c4e
movq 0x18(%rsp), %rdx
movl %eax, %ecx
leal (%rcx,%rdx,2), %eax
testb %bl, %bl
jne 0x5eb5
cmpb $0x0, 0x4(%rsp)
je 0x60f2
movq %rcx, 0x88(%rsp)
movl %ebx, 0x70(%rsp)
movl %eax, 0x74(%rsp)
movq %r12, 0x68(%rsp)
movq %r15, 0x50(%rsp)
movb 0x8(%rsp), %r12b
andb 0x28(%rsp), %r12b
leal 0x2(%rdx), %eax
movslq %edx, %rcx
movq 0x38(%rsp), %r15
leaq (%r15,%rcx,8), %rsi
addq $0x10, %rsi
movq %rsi, 0x28(%rsp)
leaq 0x10(%rsi,%rcx,8), %rsi
leal 0x4(%rdx,%rdx), %ecx
movslq %ecx, %rcx
movq %rsi, 0x8(%rsp)
leaq (%rsi,%rcx,8), %rbx
shll $0x5, %eax
movslq %eax, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x10e0
testb %r12b, %r12b
jne 0x6129
movq 0x30(%rsp), %r12
leal (,%r12,8), %eax
movslq %eax, %rdx
movq %r15, %rdi
movq 0x58(%rsp), %rsi
callq 0x1120
cmpb $0x0, 0x4(%rsp)
movq %rbx, 0x80(%rsp)
je 0x5f63
movq %r15, %rdi
movl %r12d, %esi
movq 0x60(%rsp), %rdx
movl %r14d, %ecx
callq 0x5888
movq %rax, 0x30(%rsp)
movq 0x50(%rsp), %r15
movq 0x78(%rsp), %rsi
movq 0x28(%rsp), %r14
movq 0x48(%rsp), %rbx
leal (,%rbx,8), %eax
movslq %eax, %rdx
movq %r14, %rdi
callq 0x1120
cmpb $0x0, 0x70(%rsp)
movq 0x68(%rsp), %r12
je 0x5fa6
movq %r14, %rdi
movl %ebx, %esi
movq %r13, %rdx
movl %ebp, %ecx
callq 0x5888
movl %eax, %ebx
movq 0x8(%rsp), %r13
movq %r13, %rdi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r14, %rcx
movl %ebx, %r8d
movq 0x80(%rsp), %r9
callq 0x5c4e
movq %r13, %rdi
movl %eax, %esi
movq 0x90(%rsp), %rdx
movq 0x88(%rsp), %rcx
callq 0x58f2
movl 0x24(%rsp), %ecx
testl %ecx, %ecx
je 0x60cb
movq %r13, %rdi
movl %eax, %esi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
callq 0x58f2
jmp 0x60d0
xorl %eax, %eax
testl %ebp, %ebp
je 0x611f
movl %r10d, %edx
shll $0x4, %edx
movq 0x38(%rsp), %r14
movq %r14, %rdi
movl %eax, 0x18(%rsp)
xorl %esi, %esi
movq %r8, %rbx
movq %r10, %r15
callq 0x10e0
movq 0x58(%rsp), %rax
leaq (%r14,%rax,8), %r9
movq %r14, %rdi
movq 0x60(%rsp), %rsi
movl %r15d, %edx
movq %r13, %rcx
movl %ebp, %r8d
callq 0x5c4e
movq %rbx, %rdi
movl 0x18(%rsp), %esi
movq %r14, %rdx
movl %eax, %ecx
callq 0x5888
addl %r12d, %eax
jmp 0x610d
testl %r14d, %r14d
setne %al
testq %rbp, %rbp
setne %bl
movb %al, 0x4(%rsp)
andb %bl, %al
cmpb $0x1, %al
jne 0x5e54
movq %r8, %rdi
movq %r9, 0x40(%rsp)
movq %rdx, %rsi
movl %r14d, %edx
movq %r13, %rcx
movl %ebp, %r8d
movq 0x38(%rsp), %r9
movq %r10, %rbx
callq 0x5c4e
movq 0x40(%rsp), %r9
movq 0x18(%rsp), %rcx
movq 0x60(%rsp), %rdx
movq %rbx, %r10
movq 0x10(%rsp), %r8
movl %eax, 0x24(%rsp)
movb $0x1, %bl
movb $0x1, 0x4(%rsp)
jmp 0x5e5c
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
movl 0x74(%rsp), %esi
subl %r14d, %esi
movq 0x40(%rsp), %rcx
leaq (%rbx,%rcx,8), %rdi
movq %r13, %rdx
movl %eax, %ecx
callq 0x5888
addl %r14d, %eax
leal (%r15,%r12), %ecx
cmpl %ecx, %eax
setne %dl
leal (%r15,%r12), %ecx
decl %ecx
cmpl %ecx, %eax
setne %cl
andb %dl, %cl
cmpb $0x1, %cl
je 0x6124
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x17d2
callq 0x17fc
movq 0x8(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r13, %rcx
movl %ebp, %r8d
movq %rbx, %r9
callq 0x5c4e
testl %eax, %eax
jle 0x61ac
movl %eax, %ecx
xorl %edx, %edx
movabsq $0x7ffffffffffffffe, %rsi # imm = 0x7FFFFFFFFFFFFFFE
xorl %edi, %edi
movq 0x8(%rsp), %r13
movq (%r13,%rdx,8), %r8
addq %r8, %r8
movq %r8, %r9
andq %rsi, %r9
orq %rdi, %r9
movq %r8, %rdi
shrq $0x3f, %rdi
movq %r9, (%r13,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x615f
testq %r8, %r8
movq 0x10(%rsp), %rbx
movq 0x50(%rsp), %r15
movq 0x68(%rsp), %r12
jns 0x60d0
incl %eax
movq $0x1, (%r13,%rcx,8)
jmp 0x60d0
movq 0x10(%rsp), %rbx
movq 0x50(%rsp), %r15
movq 0x68(%rsp), %r12
movq 0x8(%rsp), %r13
jmp 0x60d0