// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/joltikeq6464v13/ref/tweakableBC.c
// Function: joltikKeySetupDec128
int joltikKeySetupDec128(uint64_t* rtweakey, 
                        const uint8_t* Tweakey,
                        int no_tweakeys)
{

    int i;
    int j;
    int Nr;
    uint64_t temp;

    uint64_t s;

    uint32_t s0;
    uint32_t s1;
    uint32_t s2;
    uint32_t s3;
    uint32_t s4;
    uint32_t s5;
    uint32_t s6;
    uint32_t s7;    

    /* Produce the round tweakeys used for the encryption */
    Nr=joltikKeySetupEnc128 (rtweakey, Tweakey, no_tweakeys);

    /* invert their order */
    for (i = 0, j = Nr; i < j; ++i, --j) {
        temp = rtweakey[i];
        rtweakey[i] = rtweakey[j];
        rtweakey[j] = temp;
    }


    /* apply the inverse MixColumn transform to all round keys but the first and the last */
    for (i = 1; i <= Nr; i++) {

        s=rtweakey[i];
        s0 = (s>>56ULL)&0xff;
        s1 = (s>>48ULL)&0xff;
        s2 = (s>>40ULL)&0xff;
        s3 = (s>>32ULL)&0xff;
        s4 = (s>>24ULL)&0xff;
        s5 = (s>>16ULL)&0xff;
        s6 = (s>> 8ULL)&0xff;
        s7 = (s>> 0ULL)&0xff;

        s  = (((uint64_t)(TmcH[s0]^TmcL[s1]))<<48ULL) ^ 
             (((uint64_t)(TmcH[s2]^TmcL[s3]))<<32ULL) ^ 
             (((uint64_t)(TmcH[s4]^TmcL[s5]))<<16ULL) ^ 
             (((uint64_t)(TmcH[s6]^TmcL[s7]))<< 0ULL);

        rtweakey[i]=s;
    }
    return Nr;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x10c0
movl %eax, %ecx
movl %eax, %eax
addl $-0x3, %ecx
shrl %ecx
addl $0x2, %ecx
leaq (%rbx,%rax,8), %rdx
xorl %esi, %esi
movq (%rbx,%rsi,8), %rdi
movq (%rdx), %r8
movq %r8, (%rbx,%rsi,8)
movq %rdi, (%rdx)
incq %rsi
addq $-0x8, %rdx
cmpq %rsi, %rcx
jne 0x20bb
leal 0x3(%rax), %ecx
andl $0x7c, %ecx
leaq -0x1(%rax), %rdx
vpbroadcastq %rdx, %ymm0
addq $0x8, %rbx
vpmovsxbq 0x106a(%rip), %ymm1 # 0x315c
vmovdqa 0x1066(%rip), %ymm2     # 0x3160
vmovdqa 0x107e(%rip), %ymm3     # 0x3180
vmovdqa 0x1096(%rip), %ymm4     # 0x31a0
vmovdqa 0x10ae(%rip), %ymm5     # 0x31c0
xorl %edx, %edx
vmovdqa 0x10c4(%rip), %ymm6     # 0x31e0
vpbroadcastq 0x1153(%rip), %ymm7 # 0x3278
leaq 0x1344(%rip), %rsi      # 0x3470
leaq 0x173d(%rip), %rdi      # 0x3870
vpxor %xmm8, %xmm8, %xmm8
vpmovsxbd 0x113f(%rip), %ymm9 # 0x3280
vmovdqa 0x10d7(%rip), %ymm10    # 0x3220
vpbroadcastq %rdx, %ymm11
vpor %ymm1, %ymm11, %ymm11
vpcmpleuq %ymm0, %ymm11, %k1
vmovdqu64 (%rbx,%rdx,8), %ymm11 {%k1} {z}
vpsrlq $0x38, %ymm11, %ymm12
vpshufb %ymm2, %ymm11, %ymm13
vpshufb %ymm3, %ymm11, %ymm14
vpshufb %ymm4, %ymm11, %ymm15
vpshufb %ymm5, %ymm11, %ymm16
vpshufb %ymm6, %ymm11, %ymm17
kmovq %k1, %k2
vpxord %xmm18, %xmm18, %xmm18
vpgatherqd (%rsi,%ymm12,4), %xmm18 {%k2}
kmovq %k1, %k2
vpxor %xmm12, %xmm12, %xmm12
vpgatherqd (%rdi,%ymm13,4), %xmm12 {%k2}
kmovq %k1, %k2
vpxor %xmm13, %xmm13, %xmm13
vpgatherqd (%rsi,%ymm14,4), %xmm13 {%k2}
kmovq %k1, %k2
vpxor %xmm14, %xmm14, %xmm14
vpgatherqd (%rdi,%ymm15,4), %xmm14 {%k2}
vpand %ymm7, %ymm11, %ymm15
vpxord %xmm18, %xmm12, %xmm12
vpmovzxdq %xmm12, %ymm12  # ymm12 = xmm12[0],zero,xmm12[1],zero,xmm12[2],zero,xmm12[3],zero
vpsllq $0x30, %ymm12, %ymm12
vpxor %xmm13, %xmm14, %xmm13
vpshufb %ymm10, %ymm11, %ymm11
kmovq %k1, %k2
vpxor %xmm14, %xmm14, %xmm14
vpgatherqd (%rsi,%ymm11,4), %xmm14 {%k2}
kmovq %k1, %k2
vpxor %xmm11, %xmm11, %xmm11
vpgatherqd (%rdi,%ymm16,4), %xmm11 {%k2}
vpermt2d %ymm8, %ymm9, %ymm13
vpxor %ymm12, %ymm13, %ymm12
vpxor %xmm14, %xmm11, %xmm11
vpmovzxdq %xmm11, %ymm11  # ymm11 = xmm11[0],zero,xmm11[1],zero,xmm11[2],zero,xmm11[3],zero
vpsllq $0x10, %ymm11, %ymm11
kmovq %k1, %k2
vpxor %xmm13, %xmm13, %xmm13
vpgatherqd (%rsi,%ymm17,4), %xmm13 {%k2}
kmovq %k1, %k2
vpxor %xmm14, %xmm14, %xmm14
vpgatherqd (%rdi,%ymm15,4), %xmm14 {%k2}
vpxor %xmm13, %xmm14, %xmm13
vpmovzxdq %xmm13, %ymm13  # ymm13 = xmm13[0],zero,xmm13[1],zero,xmm13[2],zero,xmm13[3],zero
vpternlogq $0x96, %ymm11, %ymm12, %ymm13
vmovdqu64 %ymm13, (%rbx,%rdx,8) {%k1}
addq $0x4, %rdx
cmpq %rdx, %rcx
jne 0x2149
popq %rbx
vzeroupper
retq