// File: /workspace/github_c_makefile_star2_O1/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
movl %esi, %ebp
movl 0x88(%rsp), %r12d
movl 0x78(%rsp), %esi
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl %esi, %r12d
jb 0x141c
movq %rdi, %r13
movq 0x80(%rsp), %r14
movl 0x70(%rsp), %eax
leal (,%rsi,8), %esi
leaq 0x20(%rsp), %rdi
movq %rdi, 0x10(%rsp)
movl %esi, 0x8(%rsp)
movl %eax, (%rsp)
movq %r13, %rdi
movl %ebp, %esi
callq 0x142e
movl %r12d, %edi
callq 0x1050
movl 0x78(%rsp), %ecx
movq %rax, %rbx
movl %r12d, %r15d
subl %ecx, %r15d
jne 0x1389
leaq 0x20(%rsp), %rdx
movq %r13, %rdi
movl %ebp, %esi
movq %rbx, %r8
callq 0x16f9
movl 0x78(%rsp), %eax
testl %eax, %eax
je 0x140e
movl %eax, %ecx
leaq 0x1f(%rcx), %rax
andq $-0x20, %rax
decq %rcx
vpbroadcastq %rcx, %ymm1
vpxor %xmm0, %xmm0, %xmm0
xorl %ecx, %ecx
vpmovsxbq 0x3e8d(%rip), %ymm2 # 0x5100
vpmovsxbq 0x3e88(%rip), %ymm3 # 0x5104
vpmovsxbq 0x3e83(%rip), %ymm4 # 0x5108
vpmovsxbq 0x3e7e(%rip), %ymm5 # 0x510c
vpmovsxbq 0x3e79(%rip), %ymm6 # 0x5110
vpmovsxbq 0x3e74(%rip), %ymm7 # 0x5114
vpmovsxbq 0x3e6f(%rip), %ymm8 # 0x5118
vpmovsxbq 0x3e6a(%rip), %ymm9 # 0x511c
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 (%r14,%rcx), %ymm0 {%k1} {z}
vpternlogq $0xde, %ymm11, %ymm10, %ymm0
addq $0x20, %rcx
cmpq %rcx, %rax
jne 0x12b2
vmovdqu8 %ymm0, %ymm10 {%k1}
xorl %r14d, %r14d
vptest %ymm10, %ymm10
setne %r14b
negl %r14d
jmp 0x1411
testl %r12d, %r12d
je 0x13d8
cmpl $0x1f, %r12d
ja 0x13b5
movq %rbx, (%rsp)
leaq 0x20(%rsp), %rdx
movq %r13, %rdi
movl %ebp, %esi
movq %r14, %rcx
movl %r12d, %r8d
movl $0x1, %r9d
callq 0x1fbc
jmp 0x13d4
movq %rbx, (%rsp)
leaq 0x20(%rsp), %rdx
movq %r13, %rdi
movl %ebp, %esi
movq %r14, %rcx
movl %r12d, %r8d
movl $0x1, %r9d
callq 0x250a
movl 0x78(%rsp), %ecx
testl %ecx, %ecx
je 0x13f8
movl %ecx, %esi
xorl %eax, %eax
movl %r15d, %edx
orb (%rbx,%rdx), %al
incl %r15d
decq %rsi
jne 0x13e0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testb %al, %al
jne 0x1411
movq 0x90(%rsp), %rdi
subl %ecx, %r12d
movq %rbx, %rsi
movq %r12, %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