// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movl %edx, 0x9c(%rsp)
movq %rcx, 0x90(%rsp)
movl %r8d, 0x8c(%rsp)
movq %r9, 0x80(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0x8c(%rsp), %eax
jle 0x915a
jmp 0x9108
movl 0x9c(%rsp), %eax
movl %eax, 0x7c(%rsp)
movl 0x8c(%rsp), %eax
movl %eax, 0x9c(%rsp)
movl 0x7c(%rsp), %eax
movl %eax, 0x8c(%rsp)
jmp 0x912e
movq 0xa0(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x90(%rsp)
jmp 0x915a
cmpl $0x10, 0x9c(%rsp)
jge 0x919c
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movl 0x9c(%rsp), %edx
movq 0x90(%rsp), %rcx
movl 0x8c(%rsp), %r8d
callq 0x8d30
movl %eax, 0xb4(%rsp)
jmp 0x96d7
movl 0x8c(%rsp), %eax
movl 0x9c(%rsp), %ecx
shll %ecx
cmpl %ecx, %eax
jl 0x91f0
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movl 0x9c(%rsp), %edx
movq 0x90(%rsp), %rcx
movl 0x8c(%rsp), %r8d
movq 0x80(%rsp), %r9
callq 0xb0c0
movl %eax, 0xb4(%rsp)
jmp 0x96d7
movq 0xa0(%rsp), %rcx
xorl %eax, %eax
cmpq 0x90(%rsp), %rcx
movb %al, 0xf(%rsp)
jne 0x921d
movl 0x9c(%rsp), %eax
cmpl 0x8c(%rsp), %eax
sete %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x6c(%rsp)
movl 0x8c(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x68(%rsp)
movl 0x9c(%rsp), %eax
subl 0x68(%rsp), %eax
movl %eax, 0x64(%rsp)
movq 0xa0(%rsp), %rdi
movl 0x68(%rsp), %esi
callq 0xb2e0
movl %eax, 0x60(%rsp)
movl 0x8c(%rsp), %eax
subl 0x68(%rsp), %eax
movl %eax, 0x5c(%rsp)
movq 0x90(%rsp), %rdi
movl 0x68(%rsp), %esi
callq 0xb2e0
movl %eax, 0x58(%rsp)
movl $0x0, 0x4c(%rsp)
cmpl $0x0, 0x60(%rsp)
je 0x92cd
cmpl $0x0, 0x58(%rsp)
je 0x92cd
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movl 0x60(%rsp), %edx
movq 0x90(%rsp), %rcx
movl 0x58(%rsp), %r8d
movq 0x80(%rsp), %r9
callq 0x90c0
movl %eax, 0x4c(%rsp)
movq 0xa8(%rsp), %rdi
movl 0x68(%rsp), %eax
shll %eax
cltq
shlq $0x3, %rax
addq %rax, %rdi
movq 0xa0(%rsp), %rsi
movslq 0x68(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl 0x64(%rsp), %edx
movq 0x90(%rsp), %rcx
movslq 0x68(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movl 0x5c(%rsp), %r8d
movq 0x80(%rsp), %r9
callq 0x90c0
movl %eax, 0x50(%rsp)
movl 0x50(%rsp), %eax
movl 0x68(%rsp), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, 0x54(%rsp)
cmpl $0x0, 0x60(%rsp)
jne 0x9348
cmpl $0x0, 0x58(%rsp)
je 0x964e
movq 0x80(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
movl 0x68(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movl 0x68(%rsp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
movl 0x68(%rsp), %ecx
addl $0x2, %ecx
shll %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x80(%rsp), %rdi
movl 0x68(%rsp), %eax
addl $0x2, %eax
shll $0x2, %eax
shll $0x3, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x10e0
cmpl $0x0, 0x6c(%rsp)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x94f0
movq 0x30(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movslq 0x68(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl 0x64(%rsp), %edx
movq 0x90(%rsp), %rcx
movl 0x58(%rsp), %r8d
movq 0x28(%rsp), %r9
callq 0x90c0
movl %eax, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x24(%rsp), %eax
jge 0x94c7
movq 0x30(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
shlq %rdx
movq %rdx, (%rax,%rcx,8)
movslq 0x20(%rsp), %rdx
movq 0x30(%rsp), %rax
movslq 0x1c(%rsp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x30(%rsp), %rcx
movslq 0x1c(%rsp), %rdx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
je 0x94ad
movq 0x30(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
subq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
movl $0x1, 0x20(%rsp)
jmp 0x94b5
movl $0x0, 0x20(%rsp)
jmp 0x94b7
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x942c
cmpl $0x0, 0x20(%rsp)
je 0x94eb
movq 0x30(%rsp), %rax
movl 0x24(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x24(%rsp)
movslq %ecx, %rcx
movq $0x1, (%rax,%rcx,8)
jmp 0x9614
movl 0x64(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0x40(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movslq 0x68(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl 0x64(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
cmpl $0x0, 0x60(%rsp)
je 0x9545
movq 0x40(%rsp), %rdi
movl 0x18(%rsp), %esi
movq 0xa0(%rsp), %rdx
movl 0x60(%rsp), %ecx
callq 0x87d0
movl %eax, 0x18(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x38(%rsp), %rdi
movq 0x90(%rsp), %rsi
movslq 0x68(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movl 0x5c(%rsp), %eax
shll $0x3, %eax
movslq %eax, %rdx
callq 0x1140
cmpl $0x0, 0x58(%rsp)
je 0x959a
movq 0x38(%rsp), %rdi
movl 0x14(%rsp), %esi
movq 0x90(%rsp), %rdx
movl 0x58(%rsp), %ecx
callq 0x87d0
movl %eax, 0x14(%rsp)
movq 0x30(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x18(%rsp), %edx
movq 0x38(%rsp), %rcx
movl 0x14(%rsp), %r8d
movq 0x28(%rsp), %r9
callq 0x90c0
movl %eax, 0x24(%rsp)
movq 0x30(%rsp), %rdi
movl 0x24(%rsp), %esi
movq 0xa8(%rsp), %rdx
movl 0x68(%rsp), %eax
shll %eax
cltq
shlq $0x3, %rax
addq %rax, %rdx
movl 0x50(%rsp), %ecx
callq 0x8940
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x4c(%rsp)
je 0x9612
movq 0x30(%rsp), %rdi
movl 0x24(%rsp), %esi
movq 0xa8(%rsp), %rdx
movl 0x4c(%rsp), %ecx
callq 0x8940
movl %eax, 0x24(%rsp)
jmp 0x9614
movl 0x54(%rsp), %eax
subl 0x68(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0xa8(%rsp), %rdi
movslq 0x68(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x10(%rsp), %esi
movq 0x30(%rsp), %rdx
movl 0x24(%rsp), %ecx
callq 0x87d0
addl 0x68(%rsp), %eax
movl %eax, 0x54(%rsp)
jmp 0x9650
movl 0x54(%rsp), %ecx
movl 0x9c(%rsp), %edx
addl 0x8c(%rsp), %edx
movb $0x1, %al
cmpl %edx, %ecx
movb %al, 0xe(%rsp)
je 0x968a
movl 0x54(%rsp), %eax
movl 0x9c(%rsp), %ecx
addl 0x8c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
sete %al
movb %al, 0xe(%rsp)
movb 0xe(%rsp), %al
xorb $-0x1, %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x96ca
xorl %edi, %edi
leaq 0x15202(%rip), %rsi     # 0x1e8ac
leaq 0x8a2d(%rip), %rdx      # 0x120de
leaq 0x151dc(%rip), %rcx     # 0x1e894
movl $0x1f1, %r8d            # imm = 0x1F1
movb $0x0, %al
callq 0xe010
callq 0x1060
jmp 0x96cc
movl 0x54(%rsp), %eax
movl %eax, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)