// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x44(%rsp)
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl 0x44(%rsp), %edx
callq 0x10e0
movl %eax, 0x38(%rsp)
movl $0x0, 0x40(%rsp)
movl 0x38(%rsp), %eax
movl %eax, 0x3c(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0x287d
movq 0x50(%rsp), %rax
movslq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
movq 0x50(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x50(%rsp), %rax
movslq 0x40(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x30(%rsp), %rdx
movq 0x50(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
movl 0x3c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x2819
movl $0x1, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x38(%rsp), %eax
jg 0x2a07
movq 0x50(%rsp), %rax
movslq 0x40(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
shrq $0x38, %rax
andq $0xff, %rax
movl %eax, 0x24(%rsp)
movq 0x28(%rsp), %rax
shrq $0x30, %rax
andq $0xff, %rax
movl %eax, 0x20(%rsp)
movq 0x28(%rsp), %rax
shrq $0x28, %rax
andq $0xff, %rax
movl %eax, 0x1c(%rsp)
movq 0x28(%rsp), %rax
shrq $0x20, %rax
andq $0xff, %rax
movl %eax, 0x18(%rsp)
movq 0x28(%rsp), %rax
shrq $0x18, %rax
andq $0xff, %rax
movl %eax, 0x14(%rsp)
movq 0x28(%rsp), %rax
shrq $0x10, %rax
andq $0xff, %rax
movl %eax, 0x10(%rsp)
movq 0x28(%rsp), %rax
shrq $0x8, %rax
andq $0xff, %rax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rax
shrq $0x0, %rax
andq $0xff, %rax
movl %eax, 0x8(%rsp)
movl 0x24(%rsp), %eax
movl %eax, %ecx
leaq 0x17f5(%rip), %rax      # 0x4140
movl (%rax,%rcx,4), %eax
movl 0x20(%rsp), %ecx
movl %ecx, %edx
leaq 0x1be5(%rip), %rcx      # 0x4540
xorl (%rcx,%rdx,4), %eax
movl %eax, %eax
shlq $0x30, %rax
movl 0x1c(%rsp), %ecx
movl %ecx, %edx
leaq 0x17cf(%rip), %rcx      # 0x4140
movl (%rcx,%rdx,4), %ecx
movl 0x18(%rsp), %edx
movl %edx, %esi
leaq 0x1bbf(%rip), %rdx      # 0x4540
xorl (%rdx,%rsi,4), %ecx
movl %ecx, %ecx
shlq $0x20, %rcx
xorq %rcx, %rax
movl 0x14(%rsp), %ecx
movl %ecx, %edx
leaq 0x17a6(%rip), %rcx      # 0x4140
movl (%rcx,%rdx,4), %ecx
movl 0x10(%rsp), %edx
movl %edx, %esi
leaq 0x1b96(%rip), %rdx      # 0x4540
xorl (%rdx,%rsi,4), %ecx
movl %ecx, %ecx
shlq $0x10, %rcx
xorq %rcx, %rax
movl 0xc(%rsp), %ecx
movl %ecx, %edx
leaq 0x177d(%rip), %rcx      # 0x4140
movl (%rcx,%rdx,4), %ecx
movl 0x8(%rsp), %edx
movl %edx, %esi
leaq 0x1b6d(%rip), %rdx      # 0x4540
xorl (%rdx,%rsi,4), %ecx
movl %ecx, %ecx
shlq $0x0, %rcx
xorq %rcx, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdx
movq 0x50(%rsp), %rax
movslq 0x40(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x2885
movl 0x38(%rsp), %eax
addq $0x58, %rsp
retq