// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/shellaes128v1d5n64/ref/shellaes.c
// Function: PXENC
void PXENC(const u32 mk[], const u32 sk[], const u8 L[], u8 V[], u8 Z[], const u32 rk[], const u8 I[], unsigned long long int ptlen){

    int i=0;
    u8 ct[16];

    u8 final_block_mask[16];

    /*process I[] except the last block*/
    while(ptlen>16){
        aesReducedEnc(mk+4*i, sk+12*i, I, ct);
        xor_byte_string(ct, V, 16);

        memcpy(Z, V, 16);

        Z+=16;
        I+=16;
        ptlen-=16;
        ++i;

        if(i==d){
                aesEncrypt(rk, V, ct);
                memcpy(V, ct, 16);
                i=0;
        }

    }

    /*process the last block of I[]*/
    aesReducedEnc(mk+4*i, sk+12*i, I, ct);
    xor_byte_string(ct, V, 16);

    memcpy(final_block_mask, L, 16);
    double_mask(final_block_mask);
    double_mask(final_block_mask);
    double_mask(final_block_mask);

    xor_byte_string(final_block_mask, V, 16);

    memcpy(Z, V, 16);

    /*the finalization AES*/
    aesEncrypt(rk, V, ct);
    memcpy(V, ct, 16);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x20(%rsp)
movq %r8, %r15
movq %rcx, %rbx
movq %rdx, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, %r12
movq 0x78(%rsp), %r14
movq 0x70(%rsp), %r13
xorl %ebp, %ebp
cmpq $0x11, %r14
jb 0x4314
xorl %ebp, %ebp
leal (,%rbp,4), %eax
cltq
leaq (%r12,%rax,4), %rdi
leal (%rax,%rax,2), %eax
cltq
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
movq %r13, %rdx
leaq 0x10(%rsp), %rcx
callq 0x2030
vmovups (%rbx), %xmm0
vxorps 0x10(%rsp), %xmm0, %xmm0
vmovups %xmm0, (%rbx)
vmovups %xmm0, (%r15)
incl %ebp
cmpl $0x5, %ebp
jne 0x4302
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
leaq 0x10(%rsp), %rdx
callq 0x21e0
vmovaps 0x10(%rsp), %xmm0
vmovups %xmm0, (%rbx)
xorl %ebp, %ebp
addq $0x10, %r15
addq $0x10, %r13
addq $-0x10, %r14
cmpq $0x10, %r14
ja 0x42a2
shll $0x2, %ebp
movslq %ebp, %rax
leaq (%r12,%rax,4), %rdi
leal (%rax,%rax,2), %eax
cltq
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
leaq 0x10(%rsp), %r14
movq %r13, %rdx
movq %r14, %rcx
callq 0x2030
vmovups (%rbx), %xmm0
vxorps (%r14), %xmm0, %xmm0
vmovups %xmm0, (%rbx)
movq 0x30(%rsp), %rax
vmovups (%rax), %xmm0
vmovaps %xmm0, (%rsp)
movl $0xf, %eax
xorl %edx, %edx
movb (%rsp), %cl
movb (%rsp,%rax), %sil
leal (%rsi,%rsi), %edi
orb %dl, %dil
movb %dil, (%rsp,%rax)
shrb $0x7, %sil
movl %esi, %edx
addq $-0x1, %rax
jb 0x4361
testb %cl, %cl
jns 0x4384
xorb $-0x79, 0xf(%rsp)
movl $0xf, %ecx
movb (%rsp), %al
xorl %edx, %edx
movb (%rsp,%rcx), %sil
leal (%rsi,%rsi), %edi
orb %dl, %dil
movb %dil, (%rsp,%rcx)
shrb $0x7, %sil
movl %esi, %edx
addq $-0x1, %rcx
jb 0x438e
testb %al, %al
jns 0x43b1
xorb $-0x79, 0xf(%rsp)
movl $0xf, %ecx
movb (%rsp), %al
xorl %edx, %edx
movb (%rsp,%rcx), %sil
leal (%rsi,%rsi), %edi
orb %dl, %dil
movb %dil, (%rsp,%rcx)
shrb $0x7, %sil
movl %esi, %edx
addq $-0x1, %rcx
jb 0x43bb
testb %al, %al
jns 0x43de
xorb $-0x79, 0xf(%rsp)
vmovups (%rbx), %xmm0
vxorps (%rsp), %xmm0, %xmm0
vmovups %xmm0, (%rbx)
vmovups %xmm0, (%r15)
leaq 0x10(%rsp), %r14
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x21e0
vmovaps (%r14), %xmm0
vmovups %xmm0, (%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq