// File: ushitora-anqou[P]aqtfhe2/./aqtfhe2.hpp
// Function: aqtfhe2::tlwe_lvl1<aqtfhe2::params::CGGI16>::identity_key_switch(aqtfhe2::key_switching_key<aqtfhe2::params::CGGI16> const&) const
tlwe_lvl0<P> tlwe_lvl1<P>::identity_key_switch(
    const key_switching_key<P> &ksk) const
{
    const uint32_t prec_offset = 1U << (32 - (1 + P::basebit() * P::t()));
    const uint32_t mask = (1U << P::basebit()) - 1;

    typename tlwe_lvl0<P>::container ret = {};
    ret[P::n()] = data_[P::N()];
    for (size_t i = 0; i < P::N(); i++) {
        uint32_t aibar = data_[i] + prec_offset;
        for (size_t j = 0; j < P::t(); j++) {
            uint32_t aij = (aibar >> (32 - (j + 1) * P::basebit())) & mask;
            if (aij == 0)
                continue;
            for (size_t k = 0; k <= P::n(); k++)
                ret[k] -= ksk(i, j, aij - 1, k);
        }
    }

    return tlwe_lvl0<P>{std::move(ret)};
}

// Assembly:
subq $0x1818, %rsp           # imm = 0x1818
movq %rdi, 0x808(%rsp)
movq %rdi, 0x810(%rsp)
movq %rsi, 0x1810(%rsp)
movq %rdx, 0x1808(%rsp)
movq 0x1810(%rsp), %rax
movq %rax, 0x818(%rsp)
movl $0x8000, 0x1804(%rsp) # imm = 0x8000
movl $0x3, 0x1800(%rsp)
leaq 0x102c(%rsp), %rdi
xorl %esi, %esi
movl $0x7d4, %edx            # imm = 0x7D4
callq 0x20d0
callq 0x5da0
movq 0x818(%rsp), %rdi
movl %eax, %esi
callq 0xebd0
movl (%rax), %eax
movl %eax, 0x824(%rsp)
callq 0x55c0
movl %eax, %esi
leaq 0x102c(%rsp), %rdi
callq 0xcc50
movl 0x824(%rsp), %ecx
movl %ecx, (%rax)
movq $0x0, 0x1020(%rsp)
movq 0x1020(%rsp), %rax
movq %rax, 0x800(%rsp)
callq 0x5da0
movl %eax, %ecx
movq 0x800(%rsp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0xd1c8
movq 0x818(%rsp), %rdi
movq 0x1020(%rsp), %rsi
callq 0xec00
movl (%rax), %eax
addl $0x8000, %eax           # imm = 0x8000
movl %eax, 0x101c(%rsp)
movq $0x0, 0x1010(%rsp)
movq 0x1010(%rsp), %rax
movq %rax, 0x7f8(%rsp)
callq 0x5dc0
movl %eax, %ecx
movq 0x7f8(%rsp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0xd1ad
movl 0x101c(%rsp), %eax
movl %eax, 0x7f4(%rsp)
movq 0x1010(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x7e8(%rsp)
callq 0x5dd0
movq 0x7e8(%rsp), %rdx
movl %eax, %ecx
movl 0x7f4(%rsp), %eax
movl %ecx, %ecx
imulq %rcx, %rdx
movl $0x20, %ecx
subq %rdx, %rcx
shrl %cl, %eax
andl $0x3, %eax
movl %eax, 0x100c(%rsp)
cmpl $0x0, 0x100c(%rsp)
jne 0xd0eb
jmp 0xd194
movq $0x0, 0x1000(%rsp)
movq 0x1000(%rsp), %rax
movq %rax, 0x7e0(%rsp)
callq 0x55c0
movl %eax, %ecx
movq 0x7e0(%rsp), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
ja 0xd192
movq 0x1808(%rsp), %rdi
movq 0x1020(%rsp), %rsi
movq 0x1010(%rsp), %rdx
movl 0x100c(%rsp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x1000(%rsp), %r8
callq 0xec30
movl %eax, 0x7dc(%rsp)
movq 0x1000(%rsp), %rsi
leaq 0x102c(%rsp), %rdi
callq 0xcc20
movl 0x7dc(%rsp), %edx
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
movq 0x1000(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1000(%rsp)
jmp 0xd0f7
jmp 0xd194
movq 0x1010(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1010(%rsp)
jmp 0xd060
jmp 0xd1af
movq 0x1020(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1020(%rsp)
jmp 0xd007
leaq 0x828(%rsp), %rdi
leaq 0x102c(%rsp), %rsi
movl $0x7d4, %edx            # imm = 0x7D4
callq 0x2160
movq %rsp, %rax
movl $0xfa, %ecx
leaq 0x828(%rsp), %rsi
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x808(%rsp), %rdi
movl 0xff8(%rsp), %ecx
movl %ecx, 0x7d0(%rax)
callq 0xc9b0
movq 0x810(%rsp), %rax
addq $0x1818, %rsp           # imm = 0x1818
retq
nopw %cs:(%rax,%rax)
nopl (%rax)