// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/joltikeq6464v13/ref/tweakableBC.c
// Function: aesTweakEncrypt
void aesTweakEncrypt(uint32_t tweakey_size,
                     const uint8_t pt[8],
                     uint8_t key[],
                     uint8_t ct[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=joltikKeySetupEnc128 (rk, key, tweakey_size/64);

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


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

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

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

    }

    /* Put the state into the ciphertext */
    PUTU64(ct, 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 0x10e0
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), %esi
shll $0x8, %esi
orq %rdx, %rsi
movzbl 0x7(%r14), %ecx
xorq %rsi, %rcx
xorq (%r15), %rcx
movl %eax, %eax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
movl $0xf0, %esi
leaq 0x1c1a(%rip), %rdi      # 0x3a00
leaq 0x2013(%rip), %r8       # 0x3e00
movq %rcx, %r9
shrq $0x38, %r9
cmpq %rdx, 0x8(%rsp)
je 0x1ecb
movl %r9d, %r10d
andl $-0x10, %r10d
movq %rcx, %r12
shrq $0x28, %r12
movl %r12d, %r11d
andl $0xf, %r11d
orl %r10d, %r11d
movq %rcx, %r10
shrq $0x10, %r10
movl %r10d, %ebp
andl %esi, %ebp
movl %ecx, %r15d
andl $0xf, %r15d
orl %ebp, %r15d
andl %esi, %r12d
movq %rcx, %rbp
shrq $0x18, %rbp
movl %ebp, %r14d
andl $0xf, %r14d
orl %r12d, %r14d
movl %ecx, %r12d
andl %esi, %r12d
movq %rcx, %r13
shrq $0x30, %r13
movl %r13d, %ebx
andl $0xf, %ebx
orl %r12d, %ebx
andl %esi, %ebp
movq %rcx, %r12
shrq $0x8, %r12
movl %r12d, %eax
andl $0xf, %eax
orl %ebp, %eax
andl %esi, %r13d
shrq $0x20, %rcx
movl %ecx, %ebp
andl $0xf, %ebp
orl %r13d, %ebp
andl %esi, %r12d
andl $0xf, %r9d
orl %r12d, %r9d
andl %esi, %ecx
andl $0xf, %r10d
orl %ecx, %r10d
movl (%r8,%r15,4), %ecx
xorl (%rdi,%r11,4), %ecx
shlq $0x30, %rcx
movl (%r8,%rbx,4), %r11d
xorl (%rdi,%r14,4), %r11d
shlq $0x20, %r11
xorq %rcx, %r11
movl (%r8,%rbp,4), %ecx
xorl (%rdi,%rax,4), %ecx
shlq $0x10, %rcx
xorq %r11, %rcx
movl (%r8,%r10,4), %eax
xorl (%rdi,%r9,4), %eax
xorq 0x18(%rsp,%rdx,8), %rcx
xorq %rax, %rcx
incq %rdx
jmp 0x1ded
movq (%rsp), %rdx
movb %r9b, (%rdx)
vpbroadcastq %rcx, %ymm0
vpsrlvq 0x111f(%rip), %ymm0, %ymm0 # 0x3000
vpmovqb %ymm0, 0x1(%rdx)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x5(%rdx)
movb %ch, 0x6(%rdx)
movb %cl, 0x7(%rdx)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq