// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/shellaes128v1d5n64/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 the output Z[] of XEXLayerDec 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*/
    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 finalization AES*/
    memcpy(V, Z, 16);
    aesEncrypt(rk, V, ct);
    memcpy(V, ct, 16);
}

// Assembly:
subq $0x58, %rsp
movq 0x68(%rsp), %rax
movq 0x60(%rsp), %rax
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movq %r9, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
cmpq $0x10, 0x68(%rsp)
jbe 0x614c
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x50(%rsp), %rdi
movl 0x24(%rsp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
movq 0x48(%rsp), %rsi
imull $0xc, 0x24(%rsp), %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
movq 0x38(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x2220
movq 0x60(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq 0x30(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x30(%rsp)
movq 0x60(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rax
subq $0x10, %rax
movq %rax, 0x68(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
cmpl $0x5, 0x24(%rsp)
jne 0x6147
movl $0x0, 0x24(%rsp)
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x2200
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
jmp 0x6054
movq 0x40(%rsp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movq %rsp, %rdi
callq 0x21e0
movq %rsp, %rdi
callq 0x21e0
movq %rsp, %rdi
callq 0x21e0
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq %rsp, %rdi
movq 0x38(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x50(%rsp), %rdi
movl 0x24(%rsp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
movq 0x48(%rsp), %rsi
imull $0xc, 0x24(%rsp), %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
movq 0x38(%rsp), %rdx
movq 0x60(%rsp), %rcx
callq 0x2220
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq 0x28(%rsp), %rdi
movq 0x38(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x2200
movq 0x38(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
addq $0x58, %rsp
retq
nopl (%rax)