// File: ushitora-anqou[P]aqtfhe2/./aqtfhe2.hpp
// Function: aqtfhe2::trlwe_lvl1<aqtfhe2::params::CGGI16>::trgswfft_external_product(aqtfhe2::trlwe_lvl1<aqtfhe2::params::CGGI16>&, aqtfhe2::trgswfft_lvl1<aqtfhe2::params::CGGI16> const&) const
void trlwe_lvl1<P>::trgswfft_external_product(
    trlwe_lvl1<P> &out, const trgswfft_lvl1<P> &trgswfft) const
{
    constexpr uint32_t Bgbit = P::Bgbit(), N = P::N(), l = P::l(), Bg = P::Bg();
    thread_local detail::fft_processor<N> fftproc;

    ///// offset gen/////
    uint32_t offset = 0;
    for (size_t i = 1; i <= l; i++)
        offset += Bg / 2 * (1U << (32 - i * Bgbit));

    ///// decomposition /////
    constexpr uint32_t mask = static_cast<uint32_t>((1UL << Bgbit) - 1);
    constexpr uint32_t halfBg = (1UL << (Bgbit - 1));
    detail::nd_array<uint32_t, 2 * l, N> decvec;
    for (size_t i = 0; i < N; i++) {
        decvec(0, i) = poly0_[i] + offset;
        decvec(l, i) = poly1_[i] + offset;
    }
    for (int i = l - 1; i >= 0; i--) {
        for (size_t j = 0; j < N; j++) {
            decvec(i, j) =
                ((decvec(0, j) >> (32 - (i + 1) * Bgbit)) & mask) - halfBg;
            decvec(i + l, j) =
                ((decvec(l, j) >> (32 - (i + 1) * Bgbit)) & mask) - halfBg;
        }
    }

    ///// ifft /////
    detail::nd_array<double, 2 * P::l(), P::N()> decvecfft;
    for (size_t i = 0; i < 2 * l; i++)
        fftproc.twist_ifft_lvl1(decvecfft.slice(i), decvec.slice(i));

    ///// mul and fma in fd /////
    detail::nd_array<double, P::N()> poly0 =
        detail::mul_in_fd<P::N()>(decvecfft.slice(0), trgswfft.slice(0, 0));
    detail::nd_array<double, P::N()> poly1 =
        detail::mul_in_fd<P::N()>(decvecfft.slice(0), trgswfft.slice(0, 1));
    for (size_t i = 1; i < 2 * P::l(); i++) {
        detail::fma_in_fd(poly0.slice(), decvecfft.cslice(i),
                          trgswfft.slice(i, 0));
        detail::fma_in_fd(poly1.slice(), decvecfft.cslice(i),
                          trgswfft.slice(i, 1));
    }

    ///// twsit fft /////
    fftproc.twist_fft_lvl1(/* out */ out.poly0_.slice(), poly0.slice());
    fftproc.twist_fft_lvl1(/* out */ out.poly1_.slice(), poly1.slice());
}

// Assembly:
subq $0x10148, %rsp          # imm = 0x10148
movq %rdi, 0x10140(%rsp)
movq %rsi, 0x10138(%rsp)
movq %rdx, 0x10130(%rsp)
movq 0x10140(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0xa, 0x1012c(%rsp)
movl $0x400, 0x10128(%rsp) # imm = 0x400
movl $0x2, 0x10124(%rsp)
movl $0x400, 0x10120(%rsp) # imm = 0x400
movb %fs:-0x18020, %al
cmpb $0x0, %al
jne 0xd5c2
movq %fs:0x0, %rax
leaq -0x20020(%rax), %rdi
callq 0x76a0
movb $0x1, %fs:-0x18020
movl $0x0, 0x1011c(%rsp)
movq $0x1, 0x10110(%rsp)
cmpq $0x2, 0x10110(%rsp)
ja 0xd625
imulq $0xa, 0x10110(%rsp), %rcx
movl $0x20, %eax
subq %rcx, %rax
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
shll $0x9, %eax
addl 0x1011c(%rsp), %eax
movl %eax, 0x1011c(%rsp)
movq 0x10110(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x10110(%rsp)
jmp 0xd5d9
movl $0x3ff, 0x1010c(%rsp) # imm = 0x3FF
movl $0x200, 0x10108(%rsp) # imm = 0x200
movq $0x0, 0xc100(%rsp)
cmpq $0x400, 0xc100(%rsp) # imm = 0x400
jae 0xd6f4
movq 0x30(%rsp), %rdi
movq 0xc100(%rsp), %rsi
callq 0x5de0
movl (%rax), %eax
addl 0x1011c(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0xc100(%rsp), %rdx
leaq 0xc108(%rsp), %rdi
xorl %esi, %esi
callq 0xe040
movl 0x28(%rsp), %ecx
movq 0x30(%rsp), %rdi
movl %ecx, (%rax)
addq $0x1000, %rdi           # imm = 0x1000
movq 0xc100(%rsp), %rsi
callq 0x5de0
movl (%rax), %eax
addl 0x1011c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0xc100(%rsp), %rdx
leaq 0xc108(%rsp), %rdi
movl $0x2, %esi
callq 0xe080
movl 0x2c(%rsp), %ecx
movl %ecx, (%rax)
movq 0xc100(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc100(%rsp)
jmp 0xd647
movl $0x1, 0xc0fc(%rsp)
cmpl $0x0, 0xc0fc(%rsp)
jl 0xd820
movq $0x0, 0xc0f0(%rsp)
cmpq $0x400, 0xc0f0(%rsp) # imm = 0x400
jae 0xd808
movq 0xc0f0(%rsp), %rdx
leaq 0xc108(%rsp), %rdi
xorl %esi, %esi
callq 0xe040
movl (%rax), %eax
movl 0xc0fc(%rsp), %ecx
addl $0x1, %ecx
imull $0xa, %ecx, %edx
movl $0x20, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0x3ff, %eax            # imm = 0x3FF
subl $0x200, %eax            # imm = 0x200
movl %eax, 0x20(%rsp)
movl 0xc0fc(%rsp), %esi
movq 0xc0f0(%rsp), %rdx
leaq 0xc108(%rsp), %rdi
callq 0xe040
movl 0x20(%rsp), %ecx
movl %ecx, (%rax)
movq 0xc0f0(%rsp), %rdx
leaq 0xc108(%rsp), %rdi
movl $0x2, %esi
callq 0xe080
movl (%rax), %eax
movl 0xc0fc(%rsp), %ecx
addl $0x1, %ecx
imull $0xa, %ecx, %edx
movl $0x20, %ecx
subl %edx, %ecx
shrl %cl, %eax
andl $0x3ff, %eax            # imm = 0x3FF
subl $0x200, %eax            # imm = 0x200
movl %eax, 0x24(%rsp)
movl 0xc0fc(%rsp), %esi
addl $0x2, %esi
movq 0xc0f0(%rsp), %rdx
leaq 0xc108(%rsp), %rdi
callq 0xe080
movl 0x24(%rsp), %ecx
movl %ecx, (%rax)
movq 0xc0f0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xc0f0(%rsp)
jmp 0xd719
jmp 0xd80a
movl 0xc0fc(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0xc0fc(%rsp)
jmp 0xd6ff
movq $0x0, 0x40e8(%rsp)
cmpq $0x4, 0x40e8(%rsp)
jae 0xd8d2
movq %fs:0x0, %rax
leaq -0x20020(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x40e8(%rsp), %rsi
leaq 0x40f0(%rsp), %rdi
callq 0xe0c0
movq %rax, 0x40e0(%rsp)
movq 0x40e8(%rsp), %rsi
leaq 0xc108(%rsp), %rdi
callq 0xe120
movq %rax, 0x40d0(%rsp)
movq 0x40d0(%rsp), %rsi
leaq 0x40d8(%rsp), %rdi
callq 0x7d50
movq 0x18(%rsp), %rdi
movq 0x40e0(%rsp), %rsi
movq 0x40d8(%rsp), %rdx
callq 0x7b70
movq 0x40e8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x40e8(%rsp)
jmp 0xd82c
leaq 0x40f0(%rsp), %rdi
xorl %esi, %esi
callq 0xe180
movq %rax, 0x20c0(%rsp)
movq 0x20c0(%rsp), %rsi
leaq 0x20c8(%rsp), %rdi
callq 0xe1e0
movq 0x10130(%rsp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0xe210
movq %rax, 0x20b8(%rsp)
movq 0x20c8(%rsp), %rsi
movq 0x20b8(%rsp), %rdx
leaq 0x20d0(%rsp), %rdi
callq 0x8a10
leaq 0x40f0(%rsp), %rdi
xorl %esi, %esi
callq 0xe180
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0xe1e0
movq 0x10130(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0xe210
movq %rax, 0xa0(%rsp)
movq 0xb0(%rsp), %rsi
movq 0xa0(%rsp), %rdx
leaq 0xb8(%rsp), %rdi
callq 0x8a10
movq $0x1, 0x98(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
callq 0x73c0
movl %eax, %ecx
movq 0x10(%rsp), %rax
shll %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0xdab8
leaq 0x20d0(%rsp), %rdi
callq 0x8c00
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rsi
leaq 0x40f0(%rsp), %rdi
callq 0xe450
movq %rax, 0x88(%rsp)
movq 0x10130(%rsp), %rdi
movq 0x98(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xe210
movq %rax, 0x80(%rsp)
movq 0x90(%rsp), %rdi
movq 0x88(%rsp), %rsi
movq 0x80(%rsp), %rdx
callq 0xe250
leaq 0xb8(%rsp), %rdi
callq 0x8c00
movq %rax, 0x78(%rsp)
movq 0x98(%rsp), %rsi
leaq 0x40f0(%rsp), %rdi
callq 0xe450
movq %rax, 0x70(%rsp)
movq 0x10130(%rsp), %rdi
movq 0x98(%rsp), %rsi
movl $0x1, %edx
callq 0xe210
movq %rax, 0x68(%rsp)
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
callq 0xe250
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
jmp 0xd9aa
movq %fs:0x0, %rax
leaq -0x20020(%rax), %rax
movq %rax, (%rsp)
movq 0x10138(%rsp), %rdi
callq 0x7cf0
movq %rax, 0x60(%rsp)
leaq 0x20d0(%rsp), %rdi
callq 0x8c00
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rsi
leaq 0x58(%rsp), %rdi
callq 0xe1e0
movq (%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdx
callq 0x8f40
movq %fs:0x0, %rax
leaq -0x20020(%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x10138(%rsp), %rdi
addq $0x1000, %rdi           # imm = 0x1000
callq 0x7cf0
movq %rax, 0x48(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x8c00
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0xe1e0
movq 0x8(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x8f40
addq $0x10148, %rsp          # imm = 0x10148
retq
nopl (%rax)