// File: /workspace/github_cpp_makefile_star2_O1/ushitora-anqou[P]aqtfhe2/./aqtfhe2.hpp
// Function: aqtfhe2::trgswfft_lvl1<aqtfhe2::params::CGGI16> aqtfhe2::trgswfft_lvl1<aqtfhe2::params::CGGI16>::sym_encrypt<std::random_device>(std::random_device&, aqtfhe2::detail::nd_array<unsigned int, 1024ul> const&, double, unsigned int)
trgswfft_lvl1<P> trgswfft_lvl1<P>::sym_encrypt(
    RandomEngine &rand,
    const typename secret_key<P>::container_key_lvl1 &key_lvl1, double alpha,
    uint32_t plain)
{
    // trgsw sym encrypt
    // FIXME: more efficient implementation?
    std::vector<trlwe_lvl1<P>> trgsw;
    trgsw.reserve(2 * P::l());
    for (size_t i = 0; i < 2 * P::l(); i++)
        trgsw.push_back(trlwe_lvl1<P>::sym_encrypt_zero(rand, key_lvl1, alpha));
    for (uint32_t i = 0; i < P::l(); i++) {
        uint32_t h = 1U << (32 - (i + 1) * P::Bgbit());
        trgsw[i].poly0_[0] += plain * h;
        trgsw[i + P::l()].poly1_[0] += plain * h;
    }

    // trgswfft sym encrypt
    thread_local detail::fft_processor<P::N()> fftproc;
    container trgswfft;
    for (uint32_t i = 0; i < 2 * P::l(); i++) {
        fftproc.twist_ifft_lvl1(trgswfft.slice(i, 0), trgsw[i].poly0_.slice());
        fftproc.twist_ifft_lvl1(trgswfft.slice(i, 1), trgsw[i].poly1_.slice());
    }

    return trgswfft_lvl1{std::move(trgswfft)};
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x12038, %rsp          # imm = 0x12038
movl %ecx, %ebp
vmovsd %xmm0, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x30(%rsp)
vxorps %xmm0, %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
vmovaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl $0x4, %r13d
movl $0x4, %esi
callq 0x4216
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
vmovsd 0x8(%rsp), %xmm0
callq 0x42f0
movq 0x18(%rsp), %rbx
cmpq 0x20(%rsp), %rbx
je 0x3cf0
movl $0x2000, %edx           # imm = 0x2000
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2140
addq $0x2000, %rbx           # imm = 0x2000
movq %rbx, 0x18(%rsp)
jmp 0x3d00
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x4908
decq %r13
jne 0x3cb2
movl $0x16, %eax
movq 0x10(%rsp), %rcx
xorl %edx, %edx
movl $0x2000, %esi           # imm = 0x2000
shlxl %eax, %ebp, %edi
addl %edi, (%rcx,%rdx)
addl %edi, 0x5000(%rcx,%rdx)
addq %rsi, %rdx
addl $-0xa, %eax
cmpq %rsi, %rdx
je 0x3d16
cmpb $0x0, %fs:-0x28030
je 0x3e6e
movq %fs:0x0, %rax
leaq -0x30030(%rax), %rax
movq %rax, 0x8(%rsp)
movl $0x1000, %r13d          # imm = 0x1000
xorl %ebp, %ebp
leaq 0x38(%rsp), %r15
xorl %r14d, %r14d
movq %r14, %r12
shlq $0xe, %r12
movq 0x10(%rsp), %rax
addq %rbp, %rax
xorl %ecx, %ecx
vcvtdq2pd (%rax,%rcx,4), %zmm0
vmovups %zmm0, 0x38(%rsp,%rcx,8)
addq $0x8, %rcx
cmpq $0x400, %rcx            # imm = 0x400
jne 0x3d75
leaq 0x2038(%rsp,%r12), %rbx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
vzeroupper
callq 0x4e6e
movl $0x2000, %edx           # imm = 0x2000
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2140
movq 0x10(%rsp), %rax
addq %r13, %rax
xorl %ecx, %ecx
vcvtdq2pd (%rax,%rcx,4), %zmm0
vmovups %zmm0, 0x38(%rsp,%rcx,8)
addq $0x8, %rcx
cmpq $0x400, %rcx            # imm = 0x400
jne 0x3dc6
leaq 0x4038(%rsp), %rax
addq %rax, %r12
movq 0x8(%rsp), %rdi
movq %r15, %rsi
vzeroupper
callq 0x4e6e
movl $0x2000, %edx           # imm = 0x2000
movq %r12, %rdi
movq %r15, %rsi
callq 0x2140
incq %r14
movl $0x2000, %eax           # imm = 0x2000
addq %rax, %rbp
addq %rax, %r13
cmpq $0x4, %r14
jne 0x3d64
leaq 0x2038(%rsp), %rsi
movl $0x10000, %edx          # imm = 0x10000
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x2140
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3e59
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rax
addq $0x12038, %rsp          # imm = 0x12038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %fs:0x0, %rax
leaq -0x30030(%rax), %rdi
callq 0x43ee
movb $0x1, %fs:-0x28030
jmp 0x3d3f
jmp 0x3e93
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3ead
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x21e0
nop