// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movq 0x70(%rsp), %rax
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
movq 0x48(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
cmpq $0x10, 0x70(%rsp)
jbe 0x5a3e
movq 0x60(%rsp), %rdi
movl 0x34(%rsp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
movq 0x58(%rsp), %rsi
imull $0xc, 0x34(%rsp), %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
movq 0x38(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x2030
leaq 0x10(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
movq 0x38(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x38(%rsp)
movq 0x70(%rsp), %rax
subq $0x10, %rax
movq %rax, 0x70(%rsp)
cmpl $0x5, 0x34(%rsp)
jne 0x5a39
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x2200
movq 0x48(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, 0x34(%rsp)
jmp 0x5982
movq 0x50(%rsp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movq %rsp, %rdi
callq 0x21e0
leaq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x70(%rsp), %rdx
callq 0x2270
cmpq $0x10, 0x70(%rsp)
je 0x5aa8
movq %rsp, %rdi
callq 0x21e0
movq 0x70(%rsp), %rax
movb $-0x80, 0x20(%rsp,%rax)
leaq 0x20(%rsp), %rdi
addq 0x70(%rsp), %rdi
addq $0x1, %rdi
movl $0xf, %edx
subq 0x70(%rsp), %rdx
xorl %esi, %esi
callq 0x2070
movq 0x60(%rsp), %rdi
movl 0x34(%rsp), %eax
shll $0x2, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
movq 0x58(%rsp), %rsi
imull $0xc, 0x34(%rsp), %eax
cltq
shlq $0x2, %rax
addq %rax, %rsi
leaq 0x20(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x2030
leaq 0x10(%rsp), %rdi
movq 0x48(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq %rsp, %rdi
movq 0x48(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x2200
movq 0x48(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)