// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/shellaes128v1d5n64/ref/shellaes.c
// Function: shellaesEnc_fb
void shellaesEnc_fb(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], U[16], checksum[16], F[16], keyprime[16], L[16], Lprime[16];
    u8* S;
    u8* I;
    u8* Z;

    S= (u8 *) malloc(ptlen);
    I= (u8 *) malloc(ptlen);
    Z= (u8 *) malloc(ptlen);

    memset(V, 0, 16);
    memset(U, 0, 16);
    memset(checksum, 0, 16);
    memset(keyprime, 0, 16);
    memset(F, 0, 16);
    memset(L, 0, 16);
    memset(Lprime, 0, 16);

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

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

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

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

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

    /*PXENC: save outputs to Z[] and U[] */
    PXENC(mk, sk, L, V, Z, rk, I, ptlen);
    memcpy(U, V, 16);

    /*XEX: produce the ciphertext*/
    XEXLayerEnc(rk, Lprime, Z, c, ptlen);

    /*generate tag*/
    checksum_state_string(I, checksum, ptlen);
    tagGen(rk, checksum, Lprime, U, F, tag, ptlen);

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

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

    free(I);
    free(Z);
    free(S);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movq %r9, %r14
movq %r8, 0x38(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, %rbx
movq %r9, %rdi
callq 0x20e0
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0x20e0
movq %rax, %r12
movq %r14, %rdi
callq 0x20e0
movq %rax, 0x30(%rsp)
vxorps %xmm0, %xmm0, %xmm0
leaq 0x80(%rsp), %rax
vmovaps %xmm0, (%rax)
leaq 0x70(%rsp), %rax
vmovaps %xmm0, (%rax)
leaq 0x40(%rsp), %rax
vmovaps %xmm0, (%rax)
leaq 0x50(%rsp), %rax
vmovaps %xmm0, (%rax)
leaq 0x90(%rsp), %r15
vmovaps %xmm0, (%r15)
leaq 0x60(%rsp), %r13
vmovaps %xmm0, (%r13)
leaq 0x1f0(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2180
movq %rbx, (%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x100(%rsp), %rsi
movq %r15, %rdx
movq %r13, %rcx
leaq 0x40(%rsp), %r8
movq %rbp, %r9
callq 0x2240
leaq 0x2a0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
callq 0x2180
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x100(%rsp), %rsi
movq %r15, %rdx
leaq 0x80(%rsp), %r13
movq %r13, %rcx
movq %rbp, %r8
movq 0x20(%rsp), %r9
callq 0x21b0
movq %rbx, %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
leaq 0x50(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq %r14, %r8
callq 0x2190
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2280
movq 0x38(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2250
movq %r14, 0x8(%rsp)
movq %r12, (%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x100(%rsp), %rsi
movq %r15, %rdx
movq %r13, %rcx
movq 0x30(%rsp), %r15
movq %r15, %r8
movq %rbp, %r9
callq 0x2220
vmovaps (%r13), %xmm0
leaq 0xa0(%rsp), %rbx
vmovaps %xmm0, (%rbx)
movq %rbp, %rdi
leaq 0x60(%rsp), %rbp
movq %rbp, %rsi
movq %r15, %rdx
movq %r15, %r13
movq 0x390(%rsp), %rcx
movq %r14, %r8
callq 0x2130
movq %r12, %rdi
leaq 0x70(%rsp), %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x21c0
movq %r14, (%rsp)
leaq 0x1f0(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
leaq 0x50(%rsp), %r8
movq 0x398(%rsp), %r9
callq 0x2080
movq %r12, %rdi
callq 0x2160
movq %r13, %rdi
callq 0x2160
movq 0x10(%rsp), %rdi
callq 0x2160
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq