// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/shellaes128v1d5n64/ref/shellaes.c
// Function: shellaesEnc_nfb
void shellaesEnc_nfb(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;

    unsigned long long int pt_fblen;
    unsigned int pt_nfblen;

    pt_nfblen=ptlen%16;
    pt_fblen=ptlen-pt_nfblen;

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

    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);

    /*process the plaintext except the last non-full block*/
    PXMAC(mk, sk, L, V, rk, ad, adlen);
    CENC(rkprime, S, F, nonce, ptlen);
    memcpy(I, p, ptlen);
    xor_byte_string(S, I, ptlen);
    checksum_state_string(I, checksum, pt_fblen);
    PXENC(mk, sk, L, V, Z, rk, I, pt_fblen);
    memcpy(U, V, 16);
    XEXLayerEnc(rk, Lprime, Z, c, pt_fblen);
    tagGen(rk, checksum, Lprime, U, F, tag, pt_fblen);

    /*XLS: process the last non-full block*/
    XLS(rk, Lprime, p+pt_fblen, pt_fblen, pt_nfblen, c+pt_fblen, tag);

    /*
    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 $0x388, %rsp            # imm = 0x388
movq 0x398(%rsp), %rax
movq 0x390(%rsp), %rax
movq %rdi, 0x380(%rsp)
movq %rsi, 0x378(%rsp)
movq %rdx, 0x370(%rsp)
movq %rcx, 0x368(%rsp)
movq %r8, 0x360(%rsp)
movq %r9, 0x358(%rsp)
movq 0x358(%rsp), %rax
andq $0xf, %rax
movl %eax, 0x2bc(%rsp)
movq 0x358(%rsp), %rax
movl 0x2bc(%rsp), %ecx
subq %rcx, %rax
movq %rax, 0x2c0(%rsp)
movq 0x358(%rsp), %rdi
callq 0x20d0
movq %rax, 0x2d8(%rsp)
movq 0x358(%rsp), %rdi
callq 0x20d0
movq %rax, 0x2d0(%rsp)
movq 0x2c0(%rsp), %rdi
callq 0x20d0
movq %rax, 0x2c8(%rsp)
leaq 0x340(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
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 0x300(%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 0x2e0(%rsp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2070
leaq 0xc0(%rsp), %rdi
movq 0x380(%rsp), %rsi
callq 0x2170
leaq 0x260(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x2f0(%rsp), %rdx
leaq 0x2e0(%rsp), %rcx
leaq 0x300(%rsp), %r8
leaq 0xc0(%rsp), %r9
movq 0x380(%rsp), %rax
movq %rax, (%rsp)
callq 0x2230
leaq 0x10(%rsp), %rdi
leaq 0x300(%rsp), %rsi
callq 0x2170
leaq 0x260(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x2f0(%rsp), %rdx
leaq 0x340(%rsp), %rcx
leaq 0xc0(%rsp), %r8
movq 0x370(%rsp), %r9
movq 0x368(%rsp), %rax
movq %rax, (%rsp)
callq 0x21a0
leaq 0x10(%rsp), %rdi
movq 0x2d8(%rsp), %rsi
leaq 0x310(%rsp), %rdx
movq 0x378(%rsp), %rcx
movq 0x358(%rsp), %r8
callq 0x2180
movq 0x2d0(%rsp), %rdi
movq 0x360(%rsp), %rsi
movq 0x358(%rsp), %rdx
callq 0x2270
movq 0x2d8(%rsp), %rdi
movq 0x2d0(%rsp), %rsi
movq 0x358(%rsp), %rdx
callq 0x2240
movq 0x2d0(%rsp), %rdi
leaq 0x320(%rsp), %rsi
movq 0x2c0(%rsp), %rdx
callq 0x21b0
leaq 0x260(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x2f0(%rsp), %rdx
leaq 0x340(%rsp), %rcx
movq 0x2c8(%rsp), %r8
leaq 0xc0(%rsp), %r9
movq 0x2d0(%rsp), %r10
movq 0x2c0(%rsp), %rax
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x2210
movq 0x340(%rsp), %rax
movq %rax, 0x330(%rsp)
movq 0x348(%rsp), %rax
movq %rax, 0x338(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
movq 0x2c8(%rsp), %rdx
movq 0x390(%rsp), %rcx
movq 0x2c0(%rsp), %r8
callq 0x2120
leaq 0xc0(%rsp), %rdi
leaq 0x320(%rsp), %rsi
leaq 0x2e0(%rsp), %rdx
leaq 0x330(%rsp), %rcx
leaq 0x310(%rsp), %r8
movq 0x398(%rsp), %r9
movq 0x2c0(%rsp), %rax
movq %rax, (%rsp)
callq 0x2080
leaq 0xc0(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
movq 0x360(%rsp), %rdx
addq 0x2c0(%rsp), %rdx
movq 0x2c0(%rsp), %rcx
movl 0x2bc(%rsp), %r8d
movq 0x390(%rsp), %r9
addq 0x2c0(%rsp), %r9
movq 0x398(%rsp), %rax
movq %rax, (%rsp)
callq 0x21f0
movq 0x2d0(%rsp), %rdi
callq 0x2150
movq 0x2c8(%rsp), %rdi
callq 0x2150
movq 0x2d8(%rsp), %rdi
callq 0x2150
addq $0x388, %rsp            # imm = 0x388
retq
nopw %cs:(%rax,%rax)