// File: /workspace/github_c_makefile_star2_O3/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, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %r13
movq %r9, %rdi
callq 0x20e0
movq %rax, (%rsp)
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r12
movq %rbx, %rdi
callq 0x20e0
vxorps %xmm0, %xmm0, %xmm0
leaq 0x80(%rsp), %rcx
vmovaps %xmm0, (%rcx)
movq %rax, %rbp
leaq 0x60(%rsp), %rax
vmovaps %xmm0, (%rax)
vmovaps %xmm0, 0x20(%rsp)
leaq 0x90(%rsp), %r14
vmovaps %xmm0, (%r14)
leaq 0x10(%rsp), %rax
vmovaps %xmm0, (%rax)
leaq 0xa0(%rsp), %rdi
movq %r13, %rsi
callq 0x2170
leaq 0x250(%rsp), %rdi
movq %r13, %rsi
callq 0x2220
leaq 0x200(%rsp), %r15
leaq 0x3f0(%rsp), %rsi
leaq 0x300(%rsp), %rdx
movq %r15, %rdi
movq %r14, %rcx
leaq 0x10(%rsp), %r8
leaq 0x60(%rsp), %r9
pushq %r13
leaq 0xa8(%rsp), %rax
pushq %rax
callq 0x2060
addq $0x10, %rsp
leaq 0x150(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x2170
subq $0x8, %rsp
movq %r15, %rdi
leaq 0x3f8(%rsp), %rsi
movq %r14, %rdx
movq %r14, %r13
leaq 0x88(%rsp), %r14
movq %r14, %rcx
leaq 0xa8(%rsp), %r8
movq 0x50(%rsp), %r9
pushq 0x58(%rsp)
callq 0x21a0
addq $0x10, %rsp
leaq 0x250(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x2140
movq %r15, %rdi
leaq 0x300(%rsp), %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r13
movq %rbp, %r8
leaq 0xa0(%rsp), %r9
pushq %rbx
pushq %r12
callq 0x20a0
addq $0x10, %rsp
vmovdqa (%r14), %xmm0
vmovdqa %xmm0, 0x70(%rsp)
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %xmm0, 0x30(%rsp)
testq %rbx, %rbx
je 0x545e
movq 0x8(%rsp), %rcx
movq (%rsp), %r14
movq 0x520(%rsp), %r15
vmovaps 0x30(%rsp), %xmm0
xorl %eax, %eax
vxorps (%r12,%rax), %xmm0, %xmm0
addq $0x10, %rax
cmpq %rax, %rbx
jne 0x5309
vmovaps %xmm0, 0x30(%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r14, %rsi
movq %rbx, %r8
callq 0x2180
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2240
leaq 0x1f(%rbx), %rax
andq $-0x20, %rax
leaq -0x1(%rbx), %rcx
vpbroadcastq %rcx, %ymm0
xorl %ecx, %ecx
vpmovsxbq 0x6e43(%rip), %ymm1 # 0xc1a4
vpmovsxbq 0x6e3e(%rip), %ymm2 # 0xc1a8
vpmovsxbq 0x6e39(%rip), %ymm3 # 0xc1ac
vpmovsxbq 0x6e34(%rip), %ymm4 # 0xc1b0
vpmovsxbq 0x6e2f(%rip), %ymm5 # 0xc1b4
vpmovsxbq 0x6e2a(%rip), %ymm6 # 0xc1b8
vpmovsxbq 0x6e25(%rip), %ymm7 # 0xc1bc
vpmovsxbq 0x6e20(%rip), %ymm8 # 0xc1c0
vpbroadcastq %rcx, %ymm9
vpor %ymm1, %ymm9, %ymm10
vpor %ymm2, %ymm9, %ymm11
vpor %ymm3, %ymm9, %ymm12
vpor %ymm4, %ymm9, %ymm13
vpor %ymm5, %ymm9, %ymm14
vpor %ymm6, %ymm9, %ymm15
vporq %ymm7, %ymm9, %ymm16
vpor %ymm8, %ymm9, %ymm9
vpcmpleuq %ymm0, %ymm9, %k0
vpcmpleuq %ymm0, %ymm16, %k1
kshiftlb $0x4, %k1, %k1
korb %k1, %k0, %k0
vpcmpleuq %ymm0, %ymm15, %k1
vpcmpleuq %ymm0, %ymm14, %k2
kshiftlb $0x4, %k2, %k2
korb %k2, %k1, %k1
kunpckbw %k0, %k1, %k0
vpcmpleuq %ymm0, %ymm13, %k1
vpcmpleuq %ymm0, %ymm12, %k2
kshiftlb $0x4, %k2, %k2
korb %k2, %k1, %k1
vpcmpleuq %ymm0, %ymm11, %k2
vpcmpleuq %ymm0, %ymm10, %k3
kshiftlb $0x4, %k3, %k3
korb %k3, %k2, %k2
kunpckbw %k1, %k2, %k1
kunpckwd %k0, %k1, %k1
vmovdqu8 (%r12,%rcx), %ymm9 {%k1} {z}
vmovdqu8 (%r15,%rcx), %ymm10 {%k1} {z}
vpxor %ymm9, %ymm10, %ymm9
vmovdqu8 %ymm9, (%r15,%rcx) {%k1}
addq $0x20, %rcx
cmpq %rcx, %rax
jne 0x53a0
jmp 0x547f
leaq 0x150(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq (%rsp), %r14
movq %r14, %rsi
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
callq 0x2180
subq $0x8, %rsp
leaq 0xa8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x18(%rsp), %rdx
leaq 0x78(%rsp), %rcx
leaq 0x28(%rsp), %r8
movq 0x530(%rsp), %r9
pushq %rbx
vzeroupper
callq 0x2080
addq $0x10, %rsp
movq %r12, %rdi
callq 0x2150
movq %r14, %rdi
callq 0x2150
movq %r13, %rdi
callq 0x2150
addq $0x4e8, %rsp            # imm = 0x4E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq