// File: /workspace/github_c_makefile_star2_O1/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 0x1050
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 0xf33(%rip), %r11       # 0x3430
leaq 0x132c(%rip), %rbx      # 0x3830
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), %esi
xorl (%r11,%rdi,4), %esi
xorq %r9, %rsi
xorq %rdx, %rsi
movl %eax, %eax
movq %rax, 0x8(%rsp)
xorl %edi, %edi
movl $0xf0, %r8d
leaq 0x1ec8(%rip), %r9       # 0x4430
leaq 0x22c1(%rip), %r10      # 0x4830
movq %rsi, %r11
shrq $0x38, %r11
movl %r11d, %ecx
andl $-0x10, %ecx
movq %rsi, %rbp
shrq $0x8, %rbp
movl %ebp, %r12d
andl $0xf, %r12d
orl %ecx, %r12d
movq %rsi, %r15
shrq $0x10, %r15
movl %r15d, %ebx
andl %r8d, %ebx
movq %rsi, %rcx
shrq $0x20, %rcx
movl %ecx, %edx
andl $0xf, %edx
orl %ebx, %edx
movq %rsi, %r14
shrq $0x28, %r14
movl %r14d, %ebx
andl %r8d, %ebx
andl $0xf, %r11d
orl %ebx, %r11d
movl %esi, %ebx
andl %r8d, %ebx
andl $0xf, %r15d
orl %ebx, %r15d
movq %rsi, %r13
shrq $0x18, %r13
movl %r13d, %ebx
andl %r8d, %ebx
andl $0xf, %r14d
orl %ebx, %r14d
movq %rsi, %rbx
shrq $0x30, %rbx
movl %ebx, %eax
andl %r8d, %eax
andl $0xf, %esi
orl %eax, %esi
andl %r8d, %ebp
andl $0xf, %r13d
orl %ebp, %r13d
andl %r8d, %ecx
andl $0xf, %ebx
orl %ecx, %ebx
movl (%r10,%rdx,4), %eax
xorl (%r9,%r12,4), %eax
movl (%r10,%r15,4), %ecx
xorl (%r9,%r11,4), %ecx
shlq $0x30, %rax
shlq $0x20, %rcx
xorq %rax, %rcx
movl (%r10,%rsi,4), %r11d
xorl (%r9,%r14,4), %r11d
movl (%r10,%rbx,4), %esi
xorl (%r9,%r13,4), %esi
shlq $0x10, %r11
xorq %rcx, %r11
xorq 0x18(%rsp,%rdi,8), %r11
xorq %r11, %rsi
incq %rdi
cmpq %rdi, 0x8(%rsp)
jne 0x256f
movq %r11, %rcx
shrq $0x38, %rcx
movq %r11, %rdi
shrq $0x30, %rdi
movl $0xff, %eax
andl %eax, %edi
movq %r11, %r8
shrq $0x28, %r8
andl %eax, %r8d
shrq $0x20, %r11
andl %eax, %r11d
movl %esi, %edx
andl %eax, %edx
leaq 0x11b8(%rip), %r10      # 0x3830
movl (%r10,%rdi,4), %edi
leaq 0xdad(%rip), %r9        # 0x3430
xorl (%r9,%rcx,4), %edi
shlq $0x30, %rdi
movl (%r10,%r11,4), %ecx
xorl (%r9,%r8,4), %ecx
shlq $0x20, %rcx
xorq %rdi, %rcx
movl %esi, %edi
shrl $0x18, %edi
movl %esi, %r8d
shrl $0xe, %r8d
andl $0x3fc, %r8d            # imm = 0x3FC
movl (%r8,%r10), %r8d
xorl (%r9,%rdi,4), %r8d
shlq $0x10, %r8
shrl $0x8, %esi
andl %eax, %esi
movl (%r10,%rdx,4), %eax
xorl (%r9,%rsi,4), %eax
movq %rax, %rdx
xorq %r8, %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