// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10008, %rsp          # imm = 0x10008
cmpb $0x0, %fs:-0x18020
movq %rdx, %r14
movq %rdi, %r15
movq %rsi, (%rsp)
je 0x6407
vpbroadcastd 0x20a6(%rip), %zmm0 # 0x8164
xorl %eax, %eax
vpaddd (%r15,%rax,4), %zmm0, %zmm1
vmovdqu64 %zmm1, 0x4008(%rsp,%rax,4)
vpaddd 0x1000(%r15,%rax,4), %zmm0, %zmm1
vmovdqu64 %zmm1, 0x6008(%rsp,%rax,4)
addq $0x10, %rax
cmpq $0x400, %rax            # imm = 0x400
jne 0x60c0
movl $0x1, %eax
leaq 0x7008(%rsp), %rcx
movl $0x3ff, %edx            # imm = 0x3FF
movl $0xfffffe00, %esi       # imm = 0xFFFFFE00
leal (%rax,%rax), %edi
leal (%rdi,%rdi,4), %r8d
movl $0x16, %edi
subl %r8d, %edi
xorl %r8d, %r8d
shrxl %edi, 0x4008(%rsp,%r8,4), %r9d
andl %edx, %r9d
addl %esi, %r9d
movl %r9d, -0x2000(%rcx,%r8,4)
shrxl %edi, 0x6008(%rsp,%r8,4), %r9d
andl %edx, %r9d
addl %esi, %r9d
movl %r9d, (%rcx,%r8,4)
incq %r8
cmpq $0x400, %r8             # imm = 0x400
jne 0x611a
addq $-0x1000, %rcx          # imm = 0xF000
subq $0x1, %rax
jae 0x6108
movq %fs:0x0, %rax
leaq 0x4008(%rsp), %rbp
leaq 0x8(%rsp), %r12
xorl %ebx, %ebx
leaq -0x20020(%rax), %r15
movq %rbx, %rax
shlq $0xd, %rax
xorl %ecx, %ecx
vcvtdq2pd (%rbp,%rcx,4), %zmm0
vmovdqu64 %zmm0, 0x8(%rsp,%rcx,8)
addq $0x8, %rcx
cmpq $0x400, %rcx            # imm = 0x400
jne 0x6187
leaq 0x8008(%rsp,%rax), %r13
movq %r15, %rdi
movq %r12, %rsi
vzeroupper
callq 0x4f1a
movl $0x2000, %edx           # imm = 0x2000
movq %r13, %rdi
movq %r12, %rsi
callq 0x2130
incq %rbx
addq $0x1000, %rbp           # imm = 0x1000
cmpq $0x4, %rbx
jne 0x617e
movl $0x200, %eax            # imm = 0x200
vmovupd 0x8008(%rsp,%rax,8), %zmm0
vmovupd (%r14,%rax,8), %zmm1
vmovupd 0x7008(%rsp,%rax,8), %zmm3
vmovupd -0x1000(%r14,%rax,8), %zmm4
vmulpd %zmm0, %zmm1, %zmm2
vmulpd %zmm1, %zmm3, %zmm1
vfmsub231pd %zmm3, %zmm4, %zmm2 # zmm2 = (zmm4 * zmm3) - zmm2
vfmadd231pd %zmm0, %zmm4, %zmm1 # zmm1 = (zmm4 * zmm0) + zmm1
vmovupd %zmm2, -0xff8(%rsp,%rax,8)
vmovupd %zmm1, 0x8(%rsp,%rax,8)
addq $0x8, %rax
cmpq $0x400, %rax            # imm = 0x400
jne 0x61e2
movl $0x200, %eax            # imm = 0x200
vmovupd 0x8008(%rsp,%rax,8), %zmm0
vmovupd 0x2000(%r14,%rax,8), %zmm1
vmovupd 0x7008(%rsp,%rax,8), %zmm3
vmovupd 0x1000(%r14,%rax,8), %zmm4
vmulpd %zmm0, %zmm1, %zmm2
vmulpd %zmm1, %zmm3, %zmm1
vfmsub231pd %zmm3, %zmm4, %zmm2 # zmm2 = (zmm4 * zmm3) - zmm2
vfmadd231pd %zmm0, %zmm4, %zmm1 # zmm1 = (zmm4 * zmm0) + zmm1
vmovupd %zmm2, 0x1008(%rsp,%rax,8)
vmovupd %zmm1, 0x2008(%rsp,%rax,8)
addq $0x8, %rax
cmpq $0x400, %rax            # imm = 0x400
jne 0x6246
leaq 0x4000(%r14), %rax
addq $0x6000, %r14           # imm = 0x6000
movl $0x1, %ecx
leaq 0x8008(%rsp), %rdx
movl $0x4000, %esi           # imm = 0x4000
movl $0x400, %edi            # imm = 0x400
vmovupd 0x1000(%rdx,%rdi,8), %zmm0
vmovupd -0x1000(%rax,%rdi,8), %zmm1
vmovupd -0x1ff8(%rsp,%rdi,8), %zmm4
vmovupd (%rdx,%rdi,8), %zmm2
vmovupd -0x2000(%rax,%rdi,8), %zmm3
vfmsub231pd %zmm0, %zmm1, %zmm4 # zmm4 = (zmm1 * zmm0) - zmm4
vfmsub231pd %zmm2, %zmm3, %zmm4 # zmm4 = (zmm3 * zmm2) - zmm4
vmovupd %zmm4, -0x1ff8(%rsp,%rdi,8)
vfmadd213pd -0xff8(%rsp,%rdi,8), %zmm2, %zmm1 # zmm1 = (zmm2 * zmm1) + mem
vfmadd231pd %zmm0, %zmm3, %zmm1 # zmm1 = (zmm3 * zmm0) + zmm1
vmovupd %zmm1, -0xff8(%rsp,%rdi,8)
addq $0x8, %rdi
cmpq $0x600, %rdi            # imm = 0x600
jne 0x62ce
movl $0x600, %edi            # imm = 0x600
vmovupd (%rdx,%rdi,8), %zmm0
vmovupd -0x2000(%r14,%rdi,8), %zmm1
vmovupd -0xff8(%rsp,%rdi,8), %zmm4
vmovupd -0x1000(%rdx,%rdi,8), %zmm2
vmovupd -0x3000(%r14,%rdi,8), %zmm3
vfmsub231pd %zmm0, %zmm1, %zmm4 # zmm4 = (zmm1 * zmm0) - zmm4
vfmsub231pd %zmm2, %zmm3, %zmm4 # zmm4 = (zmm3 * zmm2) - zmm4
vmovupd %zmm4, -0xff8(%rsp,%rdi,8)
vfmadd213pd 0x8(%rsp,%rdi,8), %zmm2, %zmm1 # zmm1 = (zmm2 * zmm1) + mem
vfmadd231pd %zmm0, %zmm3, %zmm1 # zmm1 = (zmm3 * zmm0) + zmm1
vmovupd %zmm1, 0x8(%rsp,%rdi,8)
addq $0x8, %rdi
cmpq $0x800, %rdi            # imm = 0x800
jne 0x633d
incq %rcx
addq %rsi, %rax
addq $0x2000, %rdx           # imm = 0x2000
addq %rsi, %r14
cmpq $0x4, %rcx
jne 0x62c9
movq (%rsp), %rbx
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
vzeroupper
callq 0x4c90
addq $0x1000, %rbx           # imm = 0x1000
leaq 0x2008(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4c90
addq $0x10008, %rsp          # imm = 0x10008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2280
jmp 0x60b4
nop