// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/shellaes128v2d5n64/ref/shellaes.c
// Function: PXDEC
void PXDEC(const u32 mk[], const u32 isk[], const u8 L[], u8 V[], const u8 Z[], const u32 rk[], u8 I[], unsigned long long int ctlen){

    int i=0;

    u8 ct[16];
    u8 final_block_mask[16];

    /*process Z[] except the last block*/
    while(ctlen>16){
        xor_byte_string(Z, V, 16);
        aesReducedDec(mk+4*i, isk+12*i, V, ct);

        memcpy(I, ct, 16);
        memcpy(V, Z, 16);

        Z+=16;
        I+=16;
        ctlen-=16;
        ++i;

        if(i==d){
            i=0;
            aesEncrypt(rk, V, ct);
            memcpy(V, ct, 16);
        }
    }

    /*process the last block of Z[]*/
    memcpy(final_block_mask, L, 16);
    double_mask(final_block_mask);
    double_mask(final_block_mask);
    double_mask(final_block_mask);


    xor_byte_string(Z, V, 16);
    xor_byte_string(final_block_mask, V, 16);

    aesReducedDec(mk+4*i, isk+12*i, V, I);

    /*apply the final AES call*/
    memcpy(V, Z, 16);
    aesEncrypt(rk, V, ct);
    memcpy(V, ct, 16);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x18(%rsp)
movq %r8, %r15
movq %rcx, %rbx
movq %rdx, 0x40(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movq 0x88(%rsp), %rbp
movq 0x80(%rsp), %r12
xorl %r13d, %r13d
cmpq $0x11, %rbp
jb 0x3049
xorl %r13d, %r13d
leaq 0x30(%rsp), %r14
xorl %eax, %eax
movb (%r15,%rax), %cl
xorb %cl, (%rbx,%rax)
incq %rax
cmpq $0x10, %rax
jne 0x2fbc
leal (,%r13,4), %eax
cltq
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
leal (%rax,%rax,2), %eax
cltq
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x11a0
vmovaps 0x30(%rsp), %xmm0
vmovups %xmm0, (%r12)
vmovups (%r15), %xmm0
vmovups %xmm0, (%rbx)
incl %r13d
cmpl $0x5, %r13d
jne 0x3033
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1180
vmovaps 0x30(%rsp), %xmm0
vmovups %xmm0, (%rbx)
xorl %r13d, %r13d
addq $0x10, %r15
addq $0x10, %r12
addq $-0x10, %rbp
cmpq $0x10, %rbp
ja 0x2fba
movq 0x40(%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 0x3061
testb %cl, %cl
jns 0x3084
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 0x308e
testb %al, %al
jns 0x30b1
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 0x30bb
testb %al, %al
jns 0x30de
xorb $-0x79, 0xf(%rsp)
xorl %eax, %eax
movb (%r15,%rax), %cl
xorb %cl, (%rbx,%rax)
incq %rax
cmpq $0x10, %rax
jne 0x30e0
vmovups (%rbx), %xmm0
vxorps (%rsp), %xmm0, %xmm0
vmovups %xmm0, (%rbx)
shll $0x2, %r13d
movslq %r13d, %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
leal (%rax,%rax,2), %eax
cltq
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
movq %rbx, %rdx
movq %r12, %rcx
callq 0x11a0
vmovups (%r15), %xmm0
vmovups %xmm0, (%rbx)
leaq 0x30(%rsp), %r14
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x1180
vmovaps (%r14), %xmm0
vmovups %xmm0, (%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq