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

    u8 V[16], U[16], checksum[16], keyprime[16], F[16], L[16], Lprime[16];

    u8* S;
    u8* I;
    u8* Z;

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

    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], isk[12*d], rk[44], irk[44], rkprime[44];

    aesKeySetupEnc(rk, key);
    aesKeySetupDec(irk, key);
    KeySetupDec(mk, sk, isk, L, Lprime, keyprime, rk, key);
    aesKeySetupEnc(rkprime, keyprime);

    PXMAC(mk, sk, L, V, rk, ad, adlen);

    XEXLayerDec(irk, Lprime, c, Z, ctlen);
    PXDEC(mk, isk, L, V, Z, rk, I, ctlen);
    memcpy(U, V, 16);

    checksum_state_string(I, checksum, ctlen);

    CENC(rkprime, S, F, nonce, ctlen);

    memcpy(p, S, ctlen);
    xor_byte_string(I, p, ctlen);

    tagGen(rk, checksum, Lprime, U, F, tag, ctlen);

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


}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4e8, %rsp            # imm = 0x4E8
movq %r9, %rbx
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, %r14
movq %r9, %rdi
callq 0x20e0
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r13
movq %rbx, %rdi
callq 0x20e0
movq %rax, (%rsp)
vxorps %xmm0, %xmm0, %xmm0
leaq 0x90(%rsp), %rax
vmovaps %xmm0, (%rax)
leaq 0x70(%rsp), %rax
vmovaps %xmm0, (%rax)
leaq 0x30(%rsp), %rax
vmovaps %xmm0, (%rax)
leaq 0x60(%rsp), %rax
vmovaps %xmm0, (%rax)
leaq 0x50(%rsp), %r12
vmovaps %xmm0, (%r12)
leaq 0x40(%rsp), %r15
vmovaps %xmm0, (%r15)
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x2180
leaq 0x250(%rsp), %rdi
movq %r14, %rsi
callq 0x2260
leaq 0x150(%rsp), %rbp
leaq 0x3f0(%rsp), %rsi
leaq 0x300(%rsp), %rdx
movq %rbp, %rdi
movq %r12, %rcx
movq %r15, %r8
leaq 0x30(%rsp), %r9
pushq %r14
leaq 0xa8(%rsp), %rax
pushq %rax
callq 0x2060
popq %rax
popq %rcx
leaq 0x1a0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2180
subq $0x8, %rsp
movq %rbp, %rdi
movq %rbp, %r14
leaq 0x3f8(%rsp), %rsi
movq %r12, %rdx
leaq 0x98(%rsp), %rbp
movq %rbp, %rcx
leaq 0xa8(%rsp), %r8
movq %r8, %r12
movq 0x10(%rsp), %r9
pushq 0x18(%rsp)
callq 0x21b0
popq %rax
popq %rcx
leaq 0x250(%rsp), %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rdx
movq (%rsp), %r15
movq %r15, %rcx
movq %rbx, %r8
callq 0x2150
movq %r14, %rdi
leaq 0x300(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %rbp, %rcx
movq %r15, %r8
movq %r12, %r9
pushq %rbx
pushq %r13
callq 0x20a0
popq %rax
popq %rcx
vmovaps (%rbp), %xmm0
leaq 0x80(%rsp), %rax
vmovaps %xmm0, (%rax)
movq %r13, %rdi
leaq 0x70(%rsp), %r12
movq %r12, %rsi
movq %rbx, %rdx
callq 0x21c0
leaq 0x1a0(%rsp), %rdi
movq 0x20(%rsp), %r14
movq %r14, %rsi
leaq 0x60(%rsp), %r15
movq %r15, %rdx
movq 0x28(%rsp), %rcx
movq %rbx, %r8
callq 0x2190
movq 0x520(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2280
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x2250
subq $0x8, %rsp
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
leaq 0x48(%rsp), %rdx
leaq 0x88(%rsp), %rcx
movq %r15, %r8
movq 0x530(%rsp), %r9
pushq %rbx
callq 0x2080
popq %rax
popq %rcx
movq %r13, %rdi
callq 0x2160
movq %r14, %rdi
callq 0x2160
movq (%rsp), %rdi
callq 0x2160
addq $0x4e8, %rsp            # imm = 0x4E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq