// File: /workspace/github_c_makefile_star2_O1/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 0x10c0
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), %ebx
xorq %rcx, %rbx
xorq (%r15), %rbx
movl %eax, %eax
movq %rax, 0x8(%rsp)
xorl %ecx, %ecx
movl $0xf0, %edx
leaq 0x1919(%rip), %rsi      # 0x3c30
leaq 0x1d12(%rip), %rdi      # 0x4030
movq %rbx, %r8
shrq $0x38, %r8
movl %r8d, %r9d
andl $-0x10, %r9d
movq %rbx, %r15
shrq $0x28, %r15
movl %r15d, %r10d
andl $0xf, %r10d
orl %r9d, %r10d
movq %rbx, %r9
shrq $0x10, %r9
movl %r9d, %r11d
andl %edx, %r11d
movl %ebx, %r14d
andl $0xf, %r14d
orl %r11d, %r14d
andl %edx, %r15d
movq %rbx, %r13
shrq $0x18, %r13
movl %r13d, %r11d
andl $0xf, %r11d
orl %r15d, %r11d
movl %ebx, %r15d
andl %edx, %r15d
movq %rbx, %r12
shrq $0x30, %r12
movl %r12d, %ebp
andl $0xf, %ebp
orl %r15d, %ebp
andl %edx, %r13d
movq %rbx, %r15
shrq $0x8, %r15
movl %r15d, %eax
andl $0xf, %eax
orl %r13d, %eax
andl %edx, %r12d
shrq $0x20, %rbx
movl %ebx, %r13d
andl $0xf, %r13d
orl %r12d, %r13d
andl %edx, %r15d
andl $0xf, %r8d
orl %r15d, %r8d
andl %edx, %ebx
andl $0xf, %r9d
orl %ebx, %r9d
movl (%rdi,%r14,4), %ebx
xorl (%rsi,%r10,4), %ebx
movl (%rdi,%rbp,4), %r14d
xorl (%rsi,%r11,4), %r14d
shlq $0x30, %rbx
shlq $0x20, %r14
xorq %rbx, %r14
movl (%rdi,%r13,4), %r10d
xorl (%rsi,%rax,4), %r10d
movl (%rdi,%r9,4), %ebx
xorl (%rsi,%r8,4), %ebx
shlq $0x10, %r10
xorq %r14, %r10
xorq 0x18(%rsp,%rcx,8), %r10
xorq %r10, %rbx
incq %rcx
cmpq %rcx, 0x8(%rsp)
jne 0x231e
vpbroadcastq %r10, %ymm0
vpsrlvq 0xdf4(%rip), %ymm0, %ymm0 # 0x3200
movq (%rsp), %rcx
vpmovqb %ymm0, (%rcx)
movl %ebx, %eax
shrl $0x18, %eax
movb %al, 0x4(%rcx)
movl %ebx, %eax
shrl $0x10, %eax
movb %al, 0x5(%rcx)
movb %bh, 0x6(%rcx)
movb %bl, 0x7(%rcx)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq