// File: /workspace/github_c_makefile_star2_O2/983[P]bigint/bigint.c
// Function: bigint_raw_mul_karatsuba
int bigint_raw_mul_karatsuba(
    bigint_word *dst,
    const bigint_word *a, int na,
    const bigint_word *b, int nb,
    bigint_word *tmp
){
    /* so many */
    int n, k, m, m2;
    const bigint_word *lo1, *hi1, *lo2, *hi2;
    int nlo1, nhi1, nlo2, nhi2;
    bigint_word *lo1hi1, *lo2hi2, *z0, *z1, *z2;
    int nlo1hi1, nlo2hi2, nz0, nz1, nz2;

    if (
        na < BIGINT_KARATSUBA_WORD_THRESHOLD &&
        nb < BIGINT_KARATSUBA_WORD_THRESHOLD
    ){
        bigint_raw_zero(dst, 0, na + nb);
        return bigint_raw_mul_add(dst, a, na, b, nb);
    }

    m = BIGINT_MAX(na, nb);
    m2 = m / 2;
    k = m2 + 2;

    lo1 = a;
    lo2 = b;
    hi1 = a + m2;
    hi2 = b + m2;

    nlo1 = bigint_raw_truncate(lo1, BIGINT_MIN(m2, na));
    nlo2 = bigint_raw_truncate(lo2, BIGINT_MIN(m2, nb));
    nhi1 = bigint_raw_truncate(hi1, BIGINT_MAX(na - m2, 0));
    nhi2 = bigint_raw_truncate(hi2, BIGINT_MAX(nb - m2, 0));

    lo1hi1 = tmp; tmp += k;
    lo2hi2 = tmp; tmp += k;
    z0 = tmp; tmp += k*2;
    z1 = tmp; tmp += k*2;
    z2 = tmp; tmp += k*2;

    nlo1hi1 = bigint_raw_add(lo1hi1, lo1, nlo1, hi1, nhi1);
    nlo2hi2 = bigint_raw_add(lo2hi2, lo2, nlo2, hi2, nhi2);

    nz0 = bigint_raw_mul_karatsuba(z0, lo1   , nlo1   , lo2   , nlo2   , tmp);
    nz1 = bigint_raw_mul_karatsuba(z1, lo1hi1, nlo1hi1, lo2hi2, nlo2hi2, tmp);
    nz2 = bigint_raw_mul_karatsuba(z2,    hi1, nhi1   ,    hi2,    nhi2, tmp);

    nz1 = bigint_raw_sub(z1, z1, nz1, z0, nz0);
    nz1 = bigint_raw_sub(z1, z1, nz1, z2, nz2);

    n = nz0;

    bigint_raw_cpy(dst, z0, n);
    bigint_raw_zero(dst, n, na + nb);

    n = bigint_raw_add(dst + m2*1, dst + m2*1, BIGINT_MAX(n - m2, 0), z1, nz1);
    n = bigint_raw_add(dst + m2*2, dst + m2*2, BIGINT_MAX(n - m2, 0), z2, nz2);

    return bigint_raw_truncate(dst, n + m2*2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r8d, %ebp
movq %rcx, %r15
movl %edx, %r14d
movq %rsi, %r12
movq %rdi, %rbx
cmpl $0x14, %edx
setge %al
cmpl $0x14, %r8d
setge %cl
orb %al, %cl
jne 0x2169
movl %ebp, %eax
addl %r14d, %eax
jle 0x2147
movl %eax, %edx
shlq $0x2, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1070
movq %rbx, %rdi
movq %r12, %rsi
movl %r14d, %edx
movq %r15, %rcx
movl %ebp, %r8d
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1ddc
cmpl %ebp, %r14d
movl %ebp, %eax
cmovgl %r14d, %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %r14d, %ecx
movslq %eax, %r14
leaq (%r12,%r14,4), %r13
movq %r13, 0x18(%rsp)
leaq (%r15,%r14,4), %rax
movq %rax, 0x40(%rsp)
movq %rbx, 0x70(%rsp)
movl %r14d, %ebx
movl %ecx, %esi
movl %ecx, 0x34(%rsp)
subl %ecx, %ebx
cmovll %r14d, %esi
negl %ebx
movq %r12, %rdi
movq %r9, 0x38(%rsp)
callq 0x1c0c
movl %eax, 0xc(%rsp)
movq %r15, %rdi
movq %r15, 0x68(%rsp)
movl %r14d, %r15d
subl %ebp, %r15d
movl %ebp, %esi
cmovll %r14d, %esi
negl %r15d
callq 0x1c0c
movl %eax, 0x30(%rsp)
movq %r12, 0x50(%rsp)
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
movq %r13, %rdi
movl %ebx, %esi
callq 0x1c0c
movl %eax, 0x10(%rsp)
testl %r15d, %r15d
movl $0x0, %eax
cmovlel %eax, %r15d
movq 0x40(%rsp), %r13
movq %r13, %rdi
movl %r15d, %esi
callq 0x1c0c
movl %eax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
leaq (%rdi,%r14,4), %r15
addq $0x8, %r15
leaq 0x8(%r15,%r14,4), %rcx
movq %r15, 0x58(%rsp)
movq %rcx, 0x48(%rsp)
leal 0x4(%r14,%r14), %eax
cltq
leaq (%rcx,%rax,4), %rbx
leaq (%rbx,%rax,4), %rcx
movq %rcx, 0x20(%rsp)
leaq (%rcx,%rax,4), %rax
movq %rax, 0x60(%rsp)
movq %r12, %rsi
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rcx
movl 0x10(%rsp), %r8d
callq 0x1f76
movl %eax, 0x2c(%rsp)
movq %r15, %rdi
movq 0x68(%rsp), %r12
movq %r12, %rsi
movl 0x30(%rsp), %r15d
movl %r15d, %edx
movq %r13, %rcx
movl 0x8(%rsp), %r8d
callq 0x1f76
movl %eax, 0x28(%rsp)
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rsi
movl 0xc(%rsp), %edx
movq %r12, %rcx
movl %r15d, %r8d
movq 0x60(%rsp), %r15
movq %r15, %r9
callq 0x2102
movl %eax, %r13d
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movl 0x2c(%rsp), %edx
movq 0x58(%rsp), %rcx
movl 0x28(%rsp), %r8d
movq %r15, %r9
callq 0x2102
movl %eax, %r12d
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x10(%rsp), %edx
movq 0x40(%rsp), %rcx
movl 0x8(%rsp), %r8d
movq %r15, %r9
callq 0x2102
movl %eax, %r15d
movq %rbx, %rdi
movq %rbx, %rsi
movl %r12d, %edx
movq 0x48(%rsp), %r12
movq %r12, %rcx
movl %r13d, %r8d
callq 0x2009
movq %rbx, %rdi
movq %rbx, 0x10(%rsp)
movq %rbx, %rsi
movl %eax, %edx
movq 0x20(%rsp), %rcx
movl %r15d, 0x18(%rsp)
movl %r15d, %r8d
callq 0x2009
movl %eax, 0x8(%rsp)
movslq %r13d, %rbx
leaq (,%rbx,4), %rdx
movq 0x70(%rsp), %rdi
movq %rdi, %r15
movq %r12, %rsi
callq 0x10a0
addl 0x34(%rsp), %ebp
cmpl %ebp, %ebx
jge 0x2364
leaq (%r15,%rbx,4), %rdi
subl %r13d, %ebp
movslq %ebp, %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x1070
leaq (%r15,%r14,4), %rdi
subl %r14d, %r13d
testl %r13d, %r13d
movl $0x0, %ebp
cmovlel %ebp, %r13d
movq %rdi, %rsi
movl %r13d, %edx
movq 0x10(%rsp), %rcx
movl 0x8(%rsp), %r8d
callq 0x1f76
leal (%r14,%r14), %ecx
movslq %ecx, %rcx
leaq (%r15,%rcx,4), %rdi
subl %r14d, %eax
testl %eax, %eax
cmovgl %eax, %ebp
movq %rdi, %rsi
movl %ebp, %edx
movq 0x20(%rsp), %rcx
movl 0x18(%rsp), %r8d
callq 0x1f76
leal (%rax,%r14,2), %esi
movq %r15, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1c0c