// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/shellaes128v1d5n64/ref/shellaes.c
// Function: shellaesEnc_short
void shellaesEnc_short(const u8 key[], const u8 nonce[], const u8 ad[], unsigned long long int adlen, const u8 p[], unsigned long long int ptlen, u8 c[], u8 tag[]){

         u8 V[16], F[16], keyprime[16], L[16], Lprime[16], S[16], I[16];

         u32 mk[4*d], sk[12*d], rk[44], rkprime[44];

         u8 pt[16], pt1[16], pt2[16], ct1[16], ct2[16];
         u8 mask[16];
         u8 temp[16];
         int i;

         /*key setup*/
         aesKeySetupEnc(rk, key);
         KeySetupEnc(mk, sk, L, Lprime, keyprime, rk, key);
         aesKeySetupEnc(rkprime, keyprime);

         /*PXMAC: process the associated data and save output to V[]*/
         memset(V, 0, 16);
         PXMAC(mk, sk, L, V, rk, ad, adlen);

         /*CENC: process nonce and save the output to S[] and F[]*/
         CENC(rkprime, S, F, nonce, 16);


         /*pad p[] to a full block and save it to pt[]*/
         memset(pt, 0, 16);
         memcpy(pt, p, ptlen);
         pt[ptlen]=0x80;

         /*mask pt[] by xoring the output S[] of CENC, and save it to I[] */
         memcpy(I, S, 16);
         xor_byte_string(pt, I, 16);

         /*compute 3^3*Lprime and save it to mask[]*/
         memcpy(mask, Lprime, 16);
         for(i=0; i<3; ++i){
            memcpy(temp, mask, 16);
            double_mask(mask);
            xor_byte_string(temp, mask, 16);
         }

         /*compute XEX cipher with tweak of 3^3*Lprime and input I[], and save the output to ct1[]*/

         memcpy(pt1, I, 16);
         xor_byte_string(mask, pt1, 16);
         aesEncrypt(rk, pt1, ct1);
         xor_byte_string(mask, ct1, 16);

         /*compute XEX cipher with tweak of 2*3^3*Lprime and input I[], and save the output to ct2[]*/
         double_mask(mask);
         memcpy(pt2, I, 16);
         xor_byte_string(mask, pt2, 16);
         aesEncrypt(rk, pt2, ct2);
         xor_byte_string(mask, ct2, 16);

         /*compute XEX cipher with tweak of 2^2*3^3*Lprime and input of xoring ct1 and the output V of PX-MAC,
           and save the output to ct1[]*/
         xor_byte_string(ct1, V, 16);
         memcpy(pt1, V, 16);
         double_mask(mask);
         xor_byte_string(mask, pt1, 16);
         aesEncrypt(rk, pt1, ct1);
         xor_byte_string(mask, ct1, 16);

        /*compute XEX cipher with tweak of 2^3*3^3*Lprime and input of xoring ct2 and the updated V,
          and save the output to ct2[]*/
         xor_byte_string(ct2, V, 16);
         memcpy(pt2, V, 16);
         double_mask(mask);
         xor_byte_string(mask, pt2, 16);
         aesEncrypt(rk, pt2, ct2);
         xor_byte_string(mask, ct2, 16);

         /*xor ct2 with the output F of CENC*/
         xor_byte_string(F, ct2, 16);

         /*tag splitting:
         produce the ciphertext and tag from ct1 and ct2*/
         memcpy(c, ct1, ptlen);
         for(i=ptlen; i<16; ++i){
            tag[i-ptlen]=ct1[i];
         }
         for(i=0; i<ptlen; ++i){
            tag[16-ptlen+i]=ct2[i];
         }

        /*
        printf("ciphertext is: \n");
        printf_byte_string(c, ptlen);

        printf("tag value is: \n");
        printf_byte_string(tag, 16);
        */

}

// Assembly:
subq $0x3c8, %rsp            # imm = 0x3C8
movq 0x3d8(%rsp), %rax
movq 0x3d0(%rsp), %rax
movq %rdi, 0x3c0(%rsp)
movq %rsi, 0x3b8(%rsp)
movq %rdx, 0x3b0(%rsp)
movq %rcx, 0x3a8(%rsp)
movq %r8, 0x3a0(%rsp)
movq %r9, 0x398(%rsp)
leaq 0x130(%rsp), %rdi
movq 0x3c0(%rsp), %rsi
callq 0x2170
leaq 0x2d0(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
leaq 0x350(%rsp), %rdx
leaq 0x340(%rsp), %rcx
leaq 0x360(%rsp), %r8
leaq 0x130(%rsp), %r9
movq 0x3c0(%rsp), %rax
movq %rax, (%rsp)
callq 0x2230
leaq 0x80(%rsp), %rdi
leaq 0x360(%rsp), %rsi
callq 0x2170
leaq 0x380(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0x2d0(%rsp), %rdi
leaq 0x1e0(%rsp), %rsi
leaq 0x350(%rsp), %rdx
leaq 0x380(%rsp), %rcx
leaq 0x130(%rsp), %r8
movq 0x3b0(%rsp), %r9
movq 0x3a8(%rsp), %rax
movq %rax, (%rsp)
callq 0x21a0
leaq 0x80(%rsp), %rdi
leaq 0x330(%rsp), %rsi
leaq 0x370(%rsp), %rdx
movq 0x3b8(%rsp), %rcx
movl $0x10, %r8d
callq 0x2180
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0x70(%rsp), %rdi
movq 0x3a0(%rsp), %rsi
movq 0x398(%rsp), %rdx
callq 0x2270
movq 0x398(%rsp), %rax
movb $-0x80, 0x70(%rsp,%rax)
movq 0x330(%rsp), %rax
movq %rax, 0x320(%rsp)
movq 0x338(%rsp), %rax
movq %rax, 0x328(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0x320(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x340(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x348(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x3, 0xc(%rsp)
jge 0x7239
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x21e0
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x71f3
movq 0x320(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x328(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
leaq 0x130(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x2200
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
leaq 0x20(%rsp), %rdi
callq 0x21e0
movq 0x320(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x328(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
leaq 0x130(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x2200
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
leaq 0x40(%rsp), %rdi
leaq 0x380(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x380(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x388(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x21e0
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
leaq 0x130(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x2200
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
leaq 0x30(%rsp), %rdi
leaq 0x380(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x380(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x388(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x21e0
leaq 0x20(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
leaq 0x130(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x2200
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
leaq 0x370(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl $0x10, %edx
callq 0x2240
movq 0x3d0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movq 0x398(%rsp), %rdx
callq 0x2270
movq 0x398(%rsp), %rax
movl %eax, 0xc(%rsp)
cmpl $0x10, 0xc(%rsp)
jge 0x745b
movslq 0xc(%rsp), %rax
movb 0x40(%rsp,%rax), %dl
movq 0x3d8(%rsp), %rax
movslq 0xc(%rsp), %rcx
subq 0x398(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x7426
movl $0x0, 0xc(%rsp)
movslq 0xc(%rsp), %rax
cmpq 0x398(%rsp), %rax
jae 0x74a8
movslq 0xc(%rsp), %rax
movb 0x30(%rsp,%rax), %dl
movq 0x3d8(%rsp), %rax
movl $0x10, %ecx
subq 0x398(%rsp), %rcx
movslq 0xc(%rsp), %rsi
addq %rsi, %rcx
movb %dl, (%rax,%rcx)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x7463
addq $0x3c8, %rsp            # imm = 0x3C8
retq