// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/joltikeq6464v13/ref/tweakableBC.c
// Function: aesTweakDecrypt
void aesTweakDecrypt(uint32_t tweakey_size,
                     const uint8_t ct[8],
                     const uint8_t key[],
                     uint8_t pt[8])
{

    int i;
    int Nr;    
    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;

    uint64_t rk[33];

    /* Produce the round tweakeys */
    Nr=joltikKeySetupDec128 (rk, key, tweakey_size/64);

    /* Get the ciphertext + key/tweak prewhitening */
    s=GETU64(ct) ^ rk[0];

    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);

    for(i=1; i<=Nr; ++i) {

        /* round i: */
        s0 = (((s>>56ULL)&0xf0))^((s>> 8ULL)&0xf); 
        s1 = (((s>>16ULL)&0xf0))^((s>>32ULL)&0xf);
        s2 = (((s>>40ULL)&0xf0))^((s>>56ULL)&0xf); 
        s3 = (((s>> 0ULL)&0xf0))^((s>>16ULL)&0xf);
        s4 = (((s>>24ULL)&0xf0))^((s>>40ULL)&0xf); 
        s5 = (((s>>48ULL)&0xf0))^((s>> 0ULL)&0xf);
        s6 = (((s>> 8ULL)&0xf0))^((s>>24ULL)&0xf); 
        s7 = (((s>>32ULL)&0xf0))^((s>>48ULL)&0xf);

        s  = (((uint64_t)(TdH[s0]^TdL[s1]))<<48ULL) ^ 
             (((uint64_t)(TdH[s2]^TdL[s3]))<<32ULL) ^ 
             (((uint64_t)(TdH[s4]^TdL[s5]))<<16ULL) ^ 
             (((uint64_t)(TdH[s6]^TdL[s7]))<< 0ULL) ^ rk[i];
    }

    /* Apply the MixColum to invert the last one performed in the Td table */
    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);

    /* Put the state into the plaintext */
    PUTU64(pt, s);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rcx, (%rsp)
movq %rsi, %r14
movl %edi, %eax
shrl $0x6, %eax
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rdx, %rsi
movl %eax, %edx
callq 0x1060
movzbl (%r14), %ecx
shlq $0x38, %rcx
movzbl 0x1(%r14), %edx
shlq $0x30, %rdx
orq %rcx, %rdx
movzbl 0x2(%r14), %ecx
shlq $0x28, %rcx
orq %rdx, %rcx
movzbl 0x3(%r14), %edx
shlq $0x20, %rdx
orq %rcx, %rdx
movzbl 0x4(%r14), %ecx
shll $0x18, %ecx
orq %rdx, %rcx
movzbl 0x5(%r14), %edx
shll $0x10, %edx
orq %rcx, %rdx
movzbl 0x6(%r14), %ecx
shll $0x8, %ecx
orq %rdx, %rcx
movzbl 0x7(%r14), %edi
xorq %rcx, %rdi
xorq (%r15), %rdi
movq %rdi, %rdx
shrq $0x38, %rdx
movq %rdi, %r8
shrq $0x30, %r8
movl $0xff, %esi
andl %esi, %r8d
movq %rdi, %r9
shrq $0x28, %r9
andl %esi, %r9d
movq %rdi, %r10
shrq $0x20, %r10
andl %esi, %r10d
movl %edi, %ecx
andl %esi, %ecx
leaq 0x1236(%rip), %r11      # 0x3200
leaq 0x162f(%rip), %rbx      # 0x3600
movl (%rbx,%r8,4), %r8d
xorl (%r11,%rdx,4), %r8d
shlq $0x30, %r8
movl (%rbx,%r10,4), %edx
xorl (%r11,%r9,4), %edx
shlq $0x20, %rdx
xorq %r8, %rdx
movl %edi, %r8d
shrl $0x18, %r8d
movl %edi, %r9d
shrl $0xe, %r9d
andl $0x3fc, %r9d            # imm = 0x3FC
movl (%r9,%rbx), %r9d
xorl (%r11,%r8,4), %r9d
shlq $0x10, %r9
shrl $0x8, %edi
andl %esi, %edi
movl (%rbx,%rcx,4), %ebp
xorl (%r11,%rdi,4), %ebp
xorq %r9, %rbp
xorq %rdx, %rbp
movl %eax, %eax
movq %rax, 0x8(%rsp)
xorl %edi, %edi
movl $0xf0, %r8d
leaq 0x21cb(%rip), %r9       # 0x4200
leaq 0x25c4(%rip), %r10      # 0x4600
movq %rbp, %r11
shrq $0x38, %r11
cmpq %rdi, 0x8(%rsp)
je 0x2117
movl %r11d, %ecx
andl $-0x10, %ecx
movq %rbp, %r12
shrq $0x8, %r12
movl %r12d, %ebx
andl $0xf, %ebx
orl %ecx, %ebx
movq %rbp, %r14
shrq $0x10, %r14
movl %r14d, %esi
andl %r8d, %esi
movq %rbp, %rcx
shrq $0x20, %rcx
movl %ecx, %edx
andl $0xf, %edx
orl %esi, %edx
movq %rbp, %r15
shrq $0x28, %r15
movl %r15d, %esi
andl %r8d, %esi
andl $0xf, %r11d
orl %esi, %r11d
movl %ebp, %esi
andl %r8d, %esi
andl $0xf, %r14d
orl %esi, %r14d
movq %rbp, %r13
shrq $0x18, %r13
movl %r13d, %esi
andl %r8d, %esi
andl $0xf, %r15d
orl %esi, %r15d
movq %rbp, %rsi
shrq $0x30, %rsi
movl %esi, %eax
andl %r8d, %eax
andl $0xf, %ebp
orl %eax, %ebp
andl %r8d, %r12d
andl $0xf, %r13d
orl %r12d, %r13d
andl %r8d, %ecx
andl $0xf, %esi
orl %ecx, %esi
movl (%r10,%rdx,4), %eax
xorl (%r9,%rbx,4), %eax
shlq $0x30, %rax
movl (%r10,%r14,4), %ecx
xorl (%r9,%r11,4), %ecx
shlq $0x20, %rcx
xorq %rax, %rcx
movl (%r10,%rbp,4), %ebp
xorl (%r9,%r15,4), %ebp
shlq $0x10, %rbp
xorq %rcx, %rbp
movl (%r10,%rsi,4), %eax
xorl (%r9,%r13,4), %eax
xorq 0x18(%rsp,%rdi,8), %rbp
xorq %rax, %rbp
incq %rdi
jmp 0x203c
movq %rbp, %rcx
shrq $0x30, %rcx
movl $0xff, %eax
andl %eax, %ecx
movq %rbp, %rsi
shrq $0x28, %rsi
andl %eax, %esi
movq %rbp, %rdi
shrq $0x20, %rdi
andl %eax, %edi
movl %ebp, %edx
andl %eax, %edx
leaq 0x14be(%rip), %r10      # 0x3600
movl (%r10,%rcx,4), %r8d
leaq 0x10b3(%rip), %r9       # 0x3200
xorl (%r9,%r11,4), %r8d
shlq $0x30, %r8
movl (%r10,%rdi,4), %ecx
xorl (%r9,%rsi,4), %ecx
shlq $0x20, %rcx
xorq %r8, %rcx
movl %ebp, %esi
shrl $0x18, %esi
movl %ebp, %edi
shrl $0xe, %edi
andl $0x3fc, %edi            # imm = 0x3FC
movl (%rdi,%r10), %edi
xorl (%r9,%rsi,4), %edi
shlq $0x10, %rdi
shrl $0x8, %ebp
andl %eax, %ebp
movl (%r10,%rdx,4), %eax
xorl (%r9,%rbp,4), %eax
movq %rax, %rdx
xorq %rdi, %rdx
movq %rdx, %rsi
xorq %rcx, %rsi
movq %rcx, %rdi
shrq $0x38, %rdi
movq (%rsp), %rbx
movb %dil, (%rbx)
shrq $0x30, %rcx
movb %cl, 0x1(%rbx)
movq %rsi, %rcx
shrq $0x28, %rcx
movb %cl, 0x2(%rbx)
shrq $0x20, %rsi
movb %sil, 0x3(%rbx)
movl %edx, %ecx
shrl $0x18, %ecx
movb %cl, 0x4(%rbx)
shrl $0x10, %edx
movb %dl, 0x5(%rbx)
movb %ah, 0x6(%rbx)
movb %al, 0x7(%rbx)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop