// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/aezv3/ref/aez_ref.c
// Function: Decrypt
int Decrypt(byte *K, unsigned kbytes,
            byte *N, unsigned nbytes,
            byte *AD[], unsigned adbytes[],
            unsigned veclen, unsigned abytes,
            byte *C, unsigned cbytes, byte *M) {
    byte delta[16], *X, sum=0;
    unsigned i;
    if (cbytes < abytes) return -1;
    AEZhash(K, kbytes, N, nbytes, AD, adbytes, veclen, abytes*8, delta);
    X = (byte *)malloc(cbytes);
    if (cbytes==abytes) {
        AEZprf(K, kbytes, delta, abytes, X);
        for (i=0; i<abytes; i++) sum |= (X[i] ^ C[i]);
    } else {
        Decipher(K, kbytes, delta, C, cbytes, X);
        for (i=0; i<abytes; i++) sum |= X[cbytes-abytes+i];
        if (sum==0) memcpy(M,X,cbytes-abytes);
    }
    free(X);
    return (sum == 0 ? 0 : -1);  /* return 0 if valid, -1 if invalid */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r12
movl 0x88(%rsp), %r15d
movl 0x78(%rsp), %edi
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl %edi, %r15d
jb 0x1428
movl 0x70(%rsp), %eax
leal (,%rdi,8), %r10d
leaq 0x20(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, (%rsp)
movq %r12, %rdi
movl %esi, %ebp
callq 0x143a
movl %r15d, %r13d
movq %r13, %rdi
callq 0x1050
movq %rax, %rbx
movl %r15d, %r14d
movl 0x78(%rsp), %ecx
subl %ecx, %r14d
jne 0x138a
leaq 0x20(%rsp), %rdx
movq %r12, %rdi
movl %ebp, %esi
movl %r15d, %ecx
movq %rbx, %r8
callq 0x1705
testl %r15d, %r15d
je 0x141a
leaq 0x1f(%r13), %rax
andq $-0x20, %rax
decq %r13
vpbroadcastq %r13, %ymm1
vpxor %xmm0, %xmm0, %xmm0
xorl %ecx, %ecx
vpmovsxbq 0x3e94(%rip), %ymm2 # 0x5100
vpmovsxbq 0x3e8f(%rip), %ymm3 # 0x5104
vpmovsxbq 0x3e8a(%rip), %ymm4 # 0x5108
vpmovsxbq 0x3e85(%rip), %ymm5 # 0x510c
vpmovsxbq 0x3e80(%rip), %ymm6 # 0x5110
vpmovsxbq 0x3e7b(%rip), %ymm7 # 0x5114
vpmovsxbq 0x3e76(%rip), %ymm8 # 0x5118
vpmovsxbq 0x3e71(%rip), %ymm9 # 0x511c
movq 0x80(%rsp), %rdx
vpbroadcastq %rcx, %ymm10
vpor %ymm2, %ymm10, %ymm11
vpor %ymm3, %ymm10, %ymm12
vpor %ymm4, %ymm10, %ymm13
vpor %ymm5, %ymm10, %ymm14
vpor %ymm6, %ymm10, %ymm15
vporq %ymm7, %ymm10, %ymm16
vporq %ymm8, %ymm10, %ymm17
vpor %ymm9, %ymm10, %ymm10
vpcmpleuq %ymm1, %ymm10, %k0
vpcmpleuq %ymm1, %ymm17, %k1
kshiftlb $0x4, %k1, %k1
korb %k1, %k0, %k0
vpcmpleuq %ymm1, %ymm16, %k1
vpcmpleuq %ymm1, %ymm15, %k2
kshiftlb $0x4, %k2, %k2
korb %k2, %k1, %k1
kunpckbw %k0, %k1, %k0
vpcmpleuq %ymm1, %ymm14, %k1
vpcmpleuq %ymm1, %ymm13, %k2
kshiftlb $0x4, %k2, %k2
korb %k2, %k1, %k1
vpcmpleuq %ymm1, %ymm12, %k2
vpcmpleuq %ymm1, %ymm11, %k3
kshiftlb $0x4, %k3, %k3
korb %k3, %k2, %k2
kunpckbw %k1, %k2, %k1
kunpckwd %k0, %k1, %k1
vmovdqu8 (%rbx,%rcx), %ymm11 {%k1} {z}
vmovdqa %ymm0, %ymm10
vmovdqu8 (%rdx,%rcx), %ymm0 {%k1} {z}
vpternlogq $0xde, %ymm11, %ymm10, %ymm0
addq $0x20, %rcx
cmpq %rcx, %rax
jne 0x12b3
vmovdqu8 %ymm0, %ymm10 {%k1}
xorl %r14d, %r14d
vptest %ymm10, %ymm10
setne %r14b
negl %r14d
jmp 0x141d
testl %r15d, %r15d
movq %rcx, %r13
je 0x13e2
cmpl $0x1f, %r15d
ja 0x13be
movq %rbx, (%rsp)
leaq 0x20(%rsp), %rdx
movq %r12, %rdi
movl %ebp, %esi
movq 0x80(%rsp), %rcx
movl %r15d, %r8d
movl $0x1, %r9d
callq 0x1fc8
jmp 0x13e2
movq %rbx, (%rsp)
leaq 0x20(%rsp), %rdx
movq %r12, %rdi
movl %ebp, %esi
movq 0x80(%rsp), %rcx
movl %r15d, %r8d
movl $0x1, %r9d
callq 0x2544
testl %r13d, %r13d
je 0x1404
movl %r13d, %ecx
xorl %eax, %eax
movl %r14d, %edx
orb (%rbx,%rdx), %al
incl %r14d
decq %rcx
jne 0x13ec
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testb %al, %al
jne 0x141d
movq 0x90(%rsp), %rdi
subl %r13d, %r15d
movq %rbx, %rsi
movq %r15, %rdx
callq 0x10d0
xorl %r14d, %r14d
movq %rbx, %rdi
vzeroupper
callq 0x1070
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq