// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/shellaes128v1d5n64/ref/shellaes.c
// Function: PXMAC
void PXMAC(const u32 mk[], const u32 sk[], const u8 L[], u8 V[], const u32 rk[], const u8 ad[], unsigned long long int adlen){

      int i=0;
      u8 pt[16], ct[16];
      u8 final_block_mask[16];


      memset(pt, 0, 16);
      memset(ct, 0, 16);

      /*process associated data except the last block*/
      memset(V, 0x00, 16);

      while(adlen>16){
            aesReducedEnc(mk+4*i, sk+12*i, ad, ct);
            xor_byte_string(ct, V, 16);

            ++i;
            ad+=16;
            adlen-=16;

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

      /*process the last block*/
      memcpy(final_block_mask, L, 16);
      double_mask(final_block_mask);

      memcpy(pt, ad, adlen);

      if(adlen!=16){
            double_mask(final_block_mask);

            pt[adlen]=0x80;
            memset(pt+adlen+1, 0x00, 15-adlen);
      }

      aesReducedEnc(mk+4*i, sk+12*i, pt, ct);
      xor_byte_string(ct, V, 16);

      xor_byte_string(final_block_mask, 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 $0x48, %rsp
movq %r9, %rbp
movq %r8, 0x10(%rsp)
movq %rcx, %rbx
movq %rdx, 0x40(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r12
movq 0x80(%rsp), %r13
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0x30(%rsp)
vmovaps %xmm0, 0x20(%rsp)
vmovups %xmm0, (%rcx)
xorl %r15d, %r15d
cmpq $0x11, %r13
jb 0x405d
xorl %r15d, %r15d
leaq 0x20(%rsp), %r14
leal (,%r15,4), %eax
cltq
leaq (%r12,%rax,4), %rdi
leal (%rax,%rax,2), %eax
cltq
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x2030
vmovups (%rbx), %xmm0
vxorps 0x20(%rsp), %xmm0, %xmm0
vmovups %xmm0, (%rbx)
incl %r15d
cmpl $0x5, %r15d
jne 0x404f
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x21e0
vmovaps 0x20(%rsp), %xmm0
vmovups %xmm0, (%rbx)
xorl %r15d, %r15d
addq $0x10, %rbp
addq $-0x10, %r13
cmpq $0x10, %r13
ja 0x3ff4
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 0x4075
testb %cl, %cl
jns 0x4098
xorb $-0x79, 0xf(%rsp)
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x2240
cmpq $0x10, %r13
je 0x40f6
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 0x40b8
testb %al, %al
jns 0x40db
xorb $-0x79, 0xf(%rsp)
leaq (%rsp,%r13), %rdi
addq $0x31, %rdi
movb $-0x80, -0x1(%rdi)
movl $0xf, %edx
subq %r13, %rdx
xorl %esi, %esi
callq 0x2070
shll $0x2, %r15d
movslq %r15d, %rax
leaq (%r12,%rax,4), %rdi
leal (%rax,%rax,2), %eax
cltq
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,4), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x20(%rsp), %r14
movq %r14, %rcx
callq 0x2030
vmovups (%rbx), %xmm0
vxorps (%r14), %xmm0, %xmm0
vmovups %xmm0, (%rbx)
vxorps (%rsp), %xmm0, %xmm0
vmovups %xmm0, (%rbx)
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x21e0
vmovaps (%r14), %xmm0
vmovups %xmm0, (%rbx)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq