// File: /workspace/github_c_makefile_star2_O0/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:
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 0x5f46
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 0x60(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x2030
leaq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x30(%rsp), %rax
movq 0x38(%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 0x5f41
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)
movl $0x0, 0x24(%rsp)
jmp 0x5e64
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 0x60(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x2030
leaq 0x10(%rsp), %rdi
movq 0x38(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
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 %rsp, %rdi
movq 0x38(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x30(%rsp), %rax
movq 0x38(%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
nopw (%rax,%rax)