// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x378, %rsp            # imm = 0x378
movq 0x388(%rsp), %rax
movq 0x380(%rsp), %rax
movq %rdi, 0x370(%rsp)
movq %rsi, 0x368(%rsp)
movq %rdx, 0x360(%rsp)
movq %rcx, 0x358(%rsp)
movq %r8, 0x350(%rsp)
movq %r9, 0x348(%rsp)
movq 0x348(%rsp), %rdi
callq 0x20d0
movq %rax, 0x2c8(%rsp)
movq 0x348(%rsp), %rdi
callq 0x20d0
movq %rax, 0x2c0(%rsp)
movq 0x348(%rsp), %rdi
callq 0x20d0
movq %rax, 0x2b8(%rsp)
leaq 0x330(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0x320(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0x310(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0x2f0(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0x300(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0x2e0(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0x2d0(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0xc0(%rsp), %rdi
movq 0x370(%rsp), %rsi
callq 0x2170
leaq 0x260(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x2e0(%rsp), %rdx
leaq 0x2d0(%rsp), %rcx
leaq 0x2f0(%rsp), %r8
leaq 0xc0(%rsp), %r9
movq 0x370(%rsp), %rax
movq %rax, (%rsp)
callq 0x2230
leaq 0x10(%rsp), %rdi
leaq 0x2f0(%rsp), %rsi
callq 0x2170
leaq 0x260(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x2e0(%rsp), %rdx
leaq 0x330(%rsp), %rcx
leaq 0xc0(%rsp), %r8
movq 0x360(%rsp), %r9
movq 0x358(%rsp), %rax
movq %rax, (%rsp)
callq 0x21a0
leaq 0x10(%rsp), %rdi
movq 0x2c8(%rsp), %rsi
leaq 0x300(%rsp), %rdx
movq 0x368(%rsp), %rcx
movq 0x348(%rsp), %r8
callq 0x2180
movq 0x2c0(%rsp), %rdi
movq 0x2c8(%rsp), %rsi
movq 0x348(%rsp), %rdx
callq 0x2270
movq 0x350(%rsp), %rdi
movq 0x2c0(%rsp), %rsi
movq 0x348(%rsp), %rdx
callq 0x2240
leaq 0x260(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x2e0(%rsp), %rdx
leaq 0x330(%rsp), %rcx
movq 0x2b8(%rsp), %r8
leaq 0xc0(%rsp), %r9
movq 0x2c0(%rsp), %r10
movq 0x348(%rsp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x2210
movq 0x330(%rsp), %rax
movq %rax, 0x320(%rsp)
movq 0x338(%rsp), %rax
movq %rax, 0x328(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x2d0(%rsp), %rsi
movq 0x2b8(%rsp), %rdx
movq 0x380(%rsp), %rcx
movq 0x348(%rsp), %r8
callq 0x2120
movq 0x2c0(%rsp), %rdi
leaq 0x310(%rsp), %rsi
movq 0x348(%rsp), %rdx
callq 0x21b0
leaq 0xc0(%rsp), %rdi
leaq 0x310(%rsp), %rsi
leaq 0x2d0(%rsp), %rdx
leaq 0x320(%rsp), %rcx
leaq 0x300(%rsp), %r8
movq 0x388(%rsp), %r9
movq 0x348(%rsp), %rax
movq %rax, (%rsp)
callq 0x2080
movq 0x2c0(%rsp), %rdi
callq 0x2150
movq 0x2b8(%rsp), %rdi
callq 0x2150
movq 0x2c8(%rsp), %rdi
callq 0x2150
addq $0x378, %rsp            # imm = 0x378
retq
nopw (%rax,%rax)