// File: /workspace/github_c_makefile_star2_O1/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
movq %rdi, %r14
movl %r8d, %r15d
movq %rcx, %r13
movl %edx, %r10d
movq %rsi, %r11
cmpl %r8d, %edx
jle 0x5ccb
movl %edx, %r15d
movq %rsi, %r13
movl %r8d, %r10d
movq %rcx, %r11
cmpl $0xf, %r10d
jg 0x5cf6
movq %r14, %rdi
movq %r11, %rsi
movl %r10d, %edx
movq %r13, %rcx
movl %r15d, %r8d
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5ae5
movq %r9, 0x28(%rsp)
leal (%r10,%r10), %edi
cmpl %edi, %r15d
movq %r11, 0x38(%rsp)
jge 0x5d6f
movq %r14, 0x8(%rsp)
cmpq %rsi, %rcx
sete 0x10(%rsp)
cmpl %edx, %r8d
sete 0x20(%rsp)
movl %r15d, %r14d
shrl $0x1f, %r14d
addl %r15d, %r14d
sarl %r14d
leal 0x1(%r15), %eax
xorl %ebx, %ebx
movl $0x0, %ebp
cmpl $0x3, %eax
jb 0x5d4d
movslq %r14d, %rbp
cmpq $0x0, -0x8(%r11,%rbp,8)
jne 0x5d4d
decq %rbp
jne 0x5d3e
xorl %ebp, %ebp
cmpl $0x3, %eax
jb 0x5eeb
movslq %r14d, %rax
cmpq $0x0, -0x8(%r13,%rax,8)
jne 0x5ee9
decq %rax
jne 0x5d59
jmp 0x5eeb
leal (%r8,%rdx), %eax
decl %eax
xorl %r12d, %r12d
xorl %edx, %edx
divl %r10d
movl %edi, %ecx
cmpl $0x2, %eax
movq %rcx, 0x48(%rsp)
jl 0x5e8b
movl %eax, %edx
decl %edx
movl %r10d, %eax
shll $0x4, %eax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
leaq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
movl %r10d, %eax
leaq -0x1(%rax), %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x58(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x40(%rsp)
xorl %ebx, %ebx
xorl %eax, %eax
xorl %r12d, %r12d
movl %edx, 0x10(%rsp)
movq %r14, 0x8(%rsp)
movq 0x50(%rsp), %rcx
movl %r10d, %r14d
cmpq $0x0, (%r13,%rcx,8)
jne 0x5df4
decl %r14d
addq $-0x1, %rcx
jb 0x5de0
xorl %r14d, %r14d
testl %r14d, %r14d
je 0x5e64
movq %r15, 0x60(%rsp)
movq 0x28(%rsp), %r15
movq %r15, %rdi
movl %eax, 0x18(%rsp)
xorl %esi, %esi
movq 0x20(%rsp), %rdx
movq %r10, %rbp
callq 0x10e0
movq %r15, %rdi
movq 0x38(%rsp), %rsi
movl %ebp, %edx
movq %r13, %rcx
movl %r14d, %r8d
movq 0x30(%rsp), %r9
callq 0x5c9a
movq 0x8(%rsp), %r14
movq %r14, %rdi
movl 0x18(%rsp), %esi
movq %r15, %rdx
movq 0x60(%rsp), %r15
movl %eax, %ecx
callq 0x58d8
movl 0x10(%rsp), %edx
movq %rbp, %r10
subl %r10d, %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
jmp 0x5e6b
xorl %eax, %eax
movq 0x8(%rsp), %r14
movq 0x58(%rsp), %rcx
leaq (%r14,%rcx,8), %r14
addq 0x40(%rsp), %r13
addl %r10d, %r12d
subl %r10d, %r15d
incl %ebx
cmpl %edx, %ebx
jl 0x5dd3
jmp 0x5e8d
xorl %eax, %eax
testl %r15d, %r15d
je 0x6122
movl %r10d, %edx
shll $0x4, %edx
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movl %eax, 0x18(%rsp)
xorl %esi, %esi
movq %r10, %rbp
callq 0x10e0
movq 0x48(%rsp), %rax
leaq (%rbx,%rax,8), %r9
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movl %ebp, %edx
movq %r13, %rcx
movl %r15d, %r8d
callq 0x5c9a
movq %r14, %rdi
movl 0x18(%rsp), %esi
movq %rbx, %rdx
movl %eax, %ecx
callq 0x58d8
addl %r12d, %eax
jmp 0x6110
movl %eax, %ebx
movq %rdx, 0x50(%rsp)
movq %r8, 0x58(%rsp)
subl %r14d, %r10d
subl %r14d, %r15d
testl %ebp, %ebp
setne %al
testl %ebx, %ebx
setne %cl
andb %al, %cl
xorl %eax, %eax
cmpb $0x1, %cl
jne 0x5f33
movq 0x8(%rsp), %rdi
movq %r11, %rsi
movl %ebp, %edx
movq %r13, %rcx
movq %r10, %r12
movl %ebx, %r8d
movq 0x28(%rsp), %r9
callq 0x5c9a
movq %r12, %r10
movq 0x38(%rsp), %r11
movl %eax, 0x48(%rsp)
leal (%r14,%r14), %eax
cltq
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movl %ebx, %r12d
movslq %r14d, %rbx
leaq (%r11,%rbx,8), %rsi
leaq (%r13,%rbx,8), %rcx
movq %rdi, 0x90(%rsp)
movq %rsi, 0x30(%rsp)
movq %r10, 0x18(%rsp)
movl %r10d, %edx
movq %rcx, 0x88(%rsp)
movq %r15, 0x60(%rsp)
movl %r15d, %r8d
movq 0x28(%rsp), %r15
movq %r15, %r9
callq 0x5c9a
movl %eax, %edx
leal (%rdx,%r14,2), %eax
movl %ebp, %ecx
movl %r12d, 0x40(%rsp)
orl %r12d, %ecx
je 0x60ec
movq %rdx, 0x80(%rsp)
movl %eax, 0x6c(%rsp)
movb 0x10(%rsp), %r12b
andb 0x20(%rsp), %r12b
leal 0x2(%r14), %eax
leaq (%r15,%rbx,8), %rcx
addq $0x10, %rcx
movq %rbx, 0x10(%rsp)
movq %rcx, 0x78(%rsp)
leaq 0x10(%rcx,%rbx,8), %rdx
leal 0x4(%r14,%r14), %ecx
movslq %ecx, %rcx
movq %rdx, 0x20(%rsp)
leaq (%rdx,%rcx,8), %rbx
shll $0x5, %eax
movslq %eax, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x10e0
testb %r12b, %r12b
jne 0x612c
movq %rbx, 0x70(%rsp)
movq 0x18(%rsp), %rbx
leal (,%rbx,8), %eax
movslq %eax, %rdx
movq %r15, %rdi
movq 0x30(%rsp), %rsi
callq 0x1120
testl %ebp, %ebp
je 0x6033
movq %r15, %rdi
movl %ebx, %esi
movq 0x38(%rsp), %rdx
movl %ebp, %ecx
callq 0x58d8
movq %rax, 0x18(%rsp)
movq 0x60(%rsp), %r12
leal (,%r12,8), %eax
movslq %eax, %rdx
movq 0x78(%rsp), %rbp
movq %rbp, %rdi
movq 0x88(%rsp), %rsi
callq 0x1120
movl 0x40(%rsp), %ecx
testl %ecx, %ecx
movq 0x70(%rsp), %rbx
je 0x6076
movq %rbp, %rdi
movl %r12d, %esi
movq %r13, %rdx
callq 0x58d8
movl %eax, %r12d
movq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
movq %rbp, %rcx
movl %r12d, %r8d
movq %rbx, %r9
callq 0x5c9a
movq %r13, %rdi
movl %eax, %esi
movq 0x90(%rsp), %rdx
movq 0x80(%rsp), %rcx
callq 0x593d
movl 0x48(%rsp), %ecx
testl %ecx, %ecx
je 0x60ca
movq %r13, %rdi
movl %eax, %esi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
callq 0x593d
jmp 0x60cf
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %rdx
movl 0x6c(%rsp), %esi
subl %r14d, %esi
leaq (%rbx,%rdx,8), %rdi
movq %r13, %rdx
movl %eax, %ecx
callq 0x58d8
addl %r14d, %eax
movq 0x58(%rsp), %rcx
movq 0x50(%rsp), %rdx
leal (%rcx,%rdx), %esi
cmpl %esi, %eax
setne %sil
addl %edx, %ecx
decl %ecx
cmpl %ecx, %eax
setne %cl
andb %sil, %cl
cmpb $0x1, %cl
je 0x6127
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1826
callq 0x1850
movq 0x20(%rsp), %rdi
movq %rdi, %r15
movq 0x30(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r13, %rcx
movl 0x40(%rsp), %r8d
movq %rbx, %r9
callq 0x5c9a
testl %eax, %eax
jle 0x61ad
movl %eax, %ecx
xorl %edx, %edx
movabsq $0x7ffffffffffffffe, %rsi # imm = 0x7FFFFFFFFFFFFFFE
xorl %edi, %edi
movq %r15, %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 0x6165
testq %r8, %r8
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %rdx
jns 0x60d4
incl %eax
movq $0x1, (%r13,%rcx,8)
jmp 0x60d4
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %rdx
movq %r15, %r13
jmp 0x60d4